* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --primary: #3d5a9e;
  --primary-light: #5674ba;
  --primary-dark: #2c4070;
  --accent: #e8a838;
  --accent-light: #f0c060;
  --bg: #f4f6fa;
  --card: #ffffff;
  --card-bg: #ffffff;
  --text: #1a202c;
  --text-light: #718096;
  --border: #dce2f0;
  --success: #48bb78;
  --warning: #ecc94b;
  --danger: #f56565;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
}
#sidebar {
  width: 240px;
  background: var(--primary);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform 0.3s;
}
.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo {
  width: 40px; height: 40px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 16px;
  color: var(--primary);
}
.logo-text { font-size: 18px; font-weight: 700; }
nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,0.1); color: white; }
.nav-item.active { background: rgba(255,255,255,0.15); color: white; border-left-color: var(--accent); }
.nav-icon {
  width: 28px; height: 28px;
  background: rgba(255,255,255,0.1);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
}
.search-box { position: relative; }
.search-box input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  background: rgba(255,255,255,0.1);
  color: white;
  font-size: 13px;
  outline: none;
}
.search-box input::placeholder { color: rgba(255,255,255,0.5); }
.search-results {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background: white;
  color: var(--text);
  border-radius: 6px;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.15);
  max-height: 300px;
  overflow-y: auto;
  z-index: 200;
}
.search-results.hidden { display: none; }
.search-result-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
}
.search-result-item:hover { background: var(--bg); }
.search-result-item .result-type {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-light);
  font-weight: 600;
}

#menuToggle {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 200;
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 18px;
  cursor: pointer;
}

#mainContent {
  margin-left: 240px;
  flex: 1;
  padding: 24px;
  min-height: 100vh;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header .header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}
.page-header-logo {
  width: 48px; height: 48px;
  border-radius: 8px;
  object-fit: contain;
}
.page-header h1 { font-size: 24px; font-weight: 700; }
.page-header p { color: var(--text-light); font-size: 14px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card h3 { font-size: 13px; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.card .number { font-size: 28px; font-weight: 700; }
.card .number.green { color: var(--success); }
.card .number.blue { color: var(--primary-light); }
.card .number.gold { color: var(--accent); }

.briefing-card {
  background: linear-gradient(135deg, var(--primary), #1a365d);
  color: white;
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 4px 16px rgba(44, 82, 130, 0.3);
}
.briefing-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.briefing-header h2 { font-size: 20px; margin: 0; color: white; }
.briefing-date { font-size: 13px; opacity: 0.8; }
.briefing-body { margin-bottom: 16px; }
.briefing-item { padding: 6px 0; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.briefing-dot { width: 8px; height: 8px; border-radius: 50%; background: #48bb78; flex-shrink: 0; }
.briefing-actions { display: flex; gap: 8px; }
.briefing-actions .btn { color: white; border-color: rgba(255,255,255,0.4); }

.modules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.module-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  text-decoration: none;
  color: inherit;
  display: block;
}
.module-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
.module-card .module-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 800;
  color: white;
  margin-bottom: 12px;
}
.module-card h3 { font-size: 16px; margin-bottom: 4px; }
.module-card p { font-size: 13px; color: var(--text-light); }

.section { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.section h2 { font-size: 16px; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 8px 12px; border-bottom: 2px solid var(--border); color: var(--text-light); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
tr:hover td { background: var(--bg); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.badge.paid, .badge.completed { background: #c6f6d5; color: #276749; }
.badge.pending, .badge.draft { background: #fefcbf; color: #975a16; }
.badge.overdue { background: #fed7d7; color: #9b2c2c; }
.badge.sent { background: #d4e2fc; color: #3d5a9e; }
.badge.deposit { background: #e9d8fd; color: #553c9a; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); }
.btn-accent { background: var(--accent); color: var(--primary); }
.btn-accent:hover { opacity: 0.9; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.form-group input, .form-group textarea, .form-group select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus { border-color: var(--primary-light); }
.form-group textarea { min-height: 80px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 300;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: white;
  border-radius: 12px;
  padding: 28px;
  width: 100%;
  max-width: 640px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal h2 { font-size: 20px; margin-bottom: 20px; }
.modal .btn-group { margin-top: 20px; }

.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-light);
}
.empty-state h3 { font-size: 16px; margin-bottom: 8px; }
.empty-state p { font-size: 13px; }

.invoice-preview {
  font-size: 12px;
  line-height: 1.6;
  font-family: 'Courier New', monospace;
  padding: 20px;
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  white-space: pre-wrap;
}

.tab-bar { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.tab {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  color: var(--text-light);
  transition: all 0.2s;
}
.tab.active { color: var(--primary); border-bottom-color: var(--accent); }
.tab:hover { color: var(--text); }

.tech-guide {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.tech-guide h4 { font-size: 14px; margin-bottom: 8px; }
.tech-guide p { font-size: 13px; color: var(--text-light); margin-bottom: 4px; }
.tech-guide .safety { color: var(--danger); font-weight: 700; }

.store-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.store-item:last-child { border-bottom: none; }
.store-item .item-info h4 { font-size: 14px; }
.store-item .item-info p { font-size: 12px; color: var(--text-light); }
.store-item .item-price { font-size: 16px; font-weight: 700; color: var(--primary); }

/* === AI CHAT === */
#chatButton {
  position: fixed;
  bottom: 24px; right: 24px;
  width: 56px; height: 56px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  z-index: 250;
  transition: transform 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
#chatButton:hover { transform: scale(1.1); }
#chatButton .badge-dot {
  position: absolute;
  top: 0; right: 0;
  width: 12px; height: 12px;
  background: var(--success);
  border-radius: 50%;
  border: 2px solid white;
}

#chatPanel {
  position: fixed;
  bottom: 90px; right: 24px;
  width: 380px;
  height: 520px;
  background: var(--bg);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  z-index: 260;
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
#chatPanel.open { display: flex; }

#chatHeader {
  background: var(--primary);
  color: white;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#chatHeader h3 { font-size: 15px; }
#chatHeader button {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 18px;
  opacity: 0.7;
}
#chatHeader button:hover { opacity: 1; }

#chatMessages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-msg {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  max-width: 85%;
  white-space: pre-wrap;
}
.chat-msg.user {
  background: var(--primary);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.chat-msg.bot {
  background: var(--bg);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.chat-msg.bot strong {
  color: var(--primary);
}
.chat-msg.typing {
  background: var(--bg);
  color: var(--text-light);
  align-self: flex-start;
  font-style: italic;
}
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0;
  align-self: flex-start;
}
.chat-chip {
  background: #e8edf8;
  border: 1px solid #d0daf0;
  border-radius: 16px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--primary);
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  white-space: nowrap;
}
.chat-chip:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

#chatInputArea {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: center;
}
#chatInput {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 22px;
  font-size: 15px;
  outline: none;
  font-family: inherit;
}
#chatInput:focus { border-color: var(--primary-light); }
#chatSend {
  width: 40px; height: 40px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
#chatSend:hover { background: var(--primary-light); }

/* === BOTTOM NAV (mobile) === */
#bottomNav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: white;
  border-top: 1px solid var(--border);
  z-index: 150;
  padding: 4px 0 env(safe-area-inset-bottom, 4px) 0;
  justify-content: space-around;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
}
.bnav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  text-decoration: none;
  color: var(--text-light);
  font-size: 10px;
  transition: color 0.2s;
  min-width: 56px;
  -webkit-tap-highlight-color: transparent;
}
.bnav-item.active { color: var(--primary); }
.bnav-icon {
  width: 28px; height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  border-radius: 6px;
}
.bnav-item.active .bnav-icon {
  background: var(--primary);
  color: white;
}
.bnav-label { font-size: 10px; font-weight: 500; }

/* === MORE MENU (mobile) === */
.more-menu {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: white;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
  z-index: 160;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  max-height: 70vh;
  overflow-y: auto;
}
.more-menu.hidden { display: none; }
.more-menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.more-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 12px;
  background: var(--bg);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}
.more-item:active { background: var(--border); }
.more-icon {
  width: 32px; height: 32px;
  background: var(--primary);
  color: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}
.more-close {
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

/* === MOBILE TABLES -> CARDS === */
@media (max-width: 768px) {
  body { padding-bottom: 64px; }
  #sidebar { transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); }
  #menuToggle { display: block; }
  #mainContent { margin-left: 0; padding: 12px; padding-top: 52px; }
  .form-row { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr 1fr; }
  .cards .card { padding: 14px; }
  .card .number { font-size: 22px; }
  
  /* Bottom nav */
  #bottomNav { display: flex; }
  
  /* Table -> stacked cards on mobile */
  .section { padding: 12px; overflow: hidden; }
  .section table, .section thead, .section tbody, .section th, .section td, .section tr { display: block; }
  .section thead { display: none; }
  .section table tr {
    display: flex;
    flex-direction: column;
    padding: 12px;
    margin-bottom: 8px;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
  }
  .section table tr:hover td { background: transparent; }
  .section table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    border: none;
    font-size: 13px;
    gap: 8px;
  }
  .section table td:empty { display: none; }
  .section table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-light);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    flex-shrink: 0;
  }
  .section table td:last-child {
    padding-top: 8px;
    border-top: 1px solid var(--border);
    margin-top: 4px;
    justify-content: flex-end;
    gap: 8px;
  }
  .section table td:last-child::before { display: none; }
  
  /* Page header mobile */
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header .btn-group { width: 100%; }
  .page-header .btn-group .btn { flex: 1; text-align: center; justify-content: center; padding: 12px; }
  
  /* Module grid mobile */
  .modules-grid { grid-template-columns: 1fr; }
  .module-card { padding: 16px; }
  
  /* Modal makes full-screen */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-overlay .modal {
    max-width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 85vh;
    overflow-y: auto;
    padding: 20px;
  }
  
  /* Bigger touch targets in forms */
  .form-group input, .form-group textarea, .form-group select { padding: 12px; font-size: 15px; }
  .form-group label { font-size: 14px; }
  .btn { padding: 12px 20px; font-size: 14px; }
  .btn-sm { padding: 8px 14px; font-size: 13px; }
  
  /* Tech guides on mobile */
  .tech-guide { padding: 12px; }
  
  /* Invoice preview scrollable */
  .invoice-preview { font-size: 11px; padding: 12px; }
  
  /* Chat full-screen on mobile */
  #chatButton { bottom: 72px; right: 16px; width: 52px; height: 52px; font-size: 22px; }
  #chatPanel {
    width: 100vw;
    height: 100vh;
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    border-radius: 0;
    animation: mobileSlideUp 0.3s ease;
  }
  @keyframes mobileSlideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
  #chatPanel .chat-msg { font-size: 15px; padding: 12px 16px; }
  #chatInput { font-size: 16px; /* prevent zoom on iOS */ }
  #chatMessages { padding: 16px; }
  #chatHeader { padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top)); }
  #chatInputArea { padding: 12px 16px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .chat-chip { padding: 8px 16px; font-size: 13px; }
}
@media (max-width: 480px) {
  .cards { grid-template-columns: 1fr; }
  .modules-grid { grid-template-columns: 1fr; }
  .more-menu-grid { grid-template-columns: 1fr 1fr; }
  .chat-msg { font-size: 14px; padding: 10px 14px; }
}
.autocomplete-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--text);
  outline: none;
}
.autocomplete-input:focus {
  border-color: var(--primary);
}
.autocomplete-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1000;
  max-height: 220px;
  overflow-y: auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 6px 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.autocomplete-item {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  border-bottom: 1px solid var(--bg);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--primary); color: #fff; }
.autocomplete-item.disabled { color: var(--text-light); cursor: default; }
.autocomplete-item.disabled:hover { background: transparent; color: var(--text-light); }

body.loading #sidebar, body.loading #chatButton, body.loading #bottomNav, body.loading #menuToggle { display: none !important; }

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a202c;
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; }
.toast.error { background: #9b2c2c; }
.toast.success { background: #276749; }

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  gap: 10px;
  color: var(--text-light);
  font-size: 14px;
}

.tools-preview {
  font-size: 13px;
  line-height: 1.6;
  font-family: Arial, Helvetica, sans-serif;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  white-space: pre-wrap;
}

