:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --border: #e4e2dd;
  --text-primary: #1a1a18;
  --text-secondary: #6b6963;
  --text-muted: #9a9791;
  --accent: #1d9e75;
  --accent-bg: #e1f5ee;
  --danger: #b03a2e;
  --danger-bg: #faece7;
  --warning: #8a5a12;
  --warning-bg: #faeeda;
  --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* iOS zoom-on-focus fix: inputs/selects/textareas must be >=16px */
input, select, textarea {
  font-size: 16px !important;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  font-size: 14px;
}

.hidden { display: none !important; }

/* Login screen */
#login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  width: 320px;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  padding: 2rem 1.75rem;
}
.login-card h1 { font-size: 18px; font-weight: 500; margin-bottom: 4px; }
.login-card p { font-size: 12px; color: var(--text-muted); margin-bottom: 1.5rem; }
.login-card input {
  width: 100%;
  height: 38px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0 12px;
  font-size: 16px;
  margin-bottom: 10px;
  background: var(--surface);
  color: var(--text-primary);
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card button {
  width: 100%;
  height: 38px;
  border-radius: var(--radius);
  border: none;
  background: var(--text-primary);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 6px;
}
.login-card button:hover { opacity: 0.9; }
.login-error { color: var(--danger); font-size: 12px; margin-top: 8px; min-height: 16px; }

/* App shell */
#app-shell { display: flex; height: 100vh; }

.sidebar {
  width: 200px;
  min-width: 200px;
  background: var(--surface);
  border-right: 0.5px solid var(--border);
  display: flex;
  overflow-y: auto;
  flex-direction: column;
  padding: 16px 0;
}
.sidebar-brand { padding: 0 16px 16px; border-bottom: 0.5px solid var(--border); margin-bottom: 8px; }
.sidebar-brand .name { font-size: 15px; font-weight: 500; }
.sidebar-brand .sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 16px; font-size: 13px; color: var(--text-secondary);
  cursor: pointer; border-left: 2px solid transparent;
}
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--bg); color: var(--text-primary); font-weight: 500; border-left-color: var(--accent); }
.nav-section-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; padding: 16px 16px 4px; }
.sidebar-bottom { margin-top: auto; border-top: 0.5px solid var(--border); padding-top: 4px; }
.sidebar-bottom .user-row { padding: 8px 16px 0; display: flex; align-items: center; gap: 8px; }
.sidebar-bottom .logout-link { padding: 0 16px 12px; }

/* Chat with R - highlighted nav item */
.nav-item-chat {
  position: relative;
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 500;
  border-left-color: var(--accent);
}
.nav-item-chat:hover { background: var(--accent-bg); filter: brightness(0.97); }
.nav-item-chat i { color: var(--accent); }
.chat-badge-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); margin-left: auto;
  animation: chat-pulse 2s ease-in-out infinite;
}
@keyframes chat-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

.filter-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-bg); color: var(--accent);
  font-size: 12px; font-weight: 500; padding: 5px 10px; border-radius: var(--radius);
}
.filter-chip i { font-size: 13px; }

/* WA Log - collapsible contact groups */
.toggle-icon { font-size: 16px; color: var(--text-muted); transition: transform 0.15s ease; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-bg); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 500;
}
.user-role { font-size: 10px; color: var(--text-muted); text-transform: capitalize; }
.logout-link { font-size: 11px; color: var(--text-muted); cursor: pointer; margin-top: 8px; display: block; }
.logout-link:hover { color: var(--danger); }

.main { flex: 1; padding: 20px 24px; overflow: auto; }
.page-title { font-size: 18px; font-weight: 500; margin-bottom: 2px; }
.page-sub { font-size: 12px; color: var(--text-muted); margin-bottom: 16px; }

.brief-card {
  background: var(--surface); border: 0.5px solid var(--border); border-radius: 12px;
  padding: 1rem 1.25rem; margin-bottom: 20px;
}
.brief-label { font-size: 13px; font-weight: 500; margin-bottom: 8px; }
.brief-text { font-size: 13px; color: var(--text-secondary); line-height: 1.7; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 0.5px solid var(--border); border-radius: 8px; padding: 1rem; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.stat-value { font-size: 24px; font-weight: 500; }
.stat-value.danger { color: var(--danger); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--text-muted); font-weight: 500; padding: 8px 6px; border-bottom: 0.5px solid var(--border); font-size: 12px; }
td { padding: 8px 6px; border-bottom: 0.5px solid var(--border); }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 4px; font-weight: 500; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.btn {
  border: 0.5px solid var(--border); background: var(--surface);
  border-radius: var(--radius); padding: 7px 14px; font-size: 13px;
  cursor: pointer; color: var(--text-primary);
}
.btn:hover { background: var(--border); border-color: var(--text-muted); }
.btn-primary { background: var(--text-primary); color: #fff; border: none; }
.btn-primary:hover { opacity: 0.9; }

select, .cell-input {
  border: 0.5px solid var(--border); border-radius: 6px; padding: 4px 8px;
  font-size: 12px; background: var(--surface); color: var(--text-primary);
}

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
.modal-card {
  width: 380px; background: var(--surface); border-radius: 12px; padding: 1.5rem;
}
.modal-card h3 { font-size: 15px; font-weight: 500; margin-bottom: 14px; }
.modal-card input, .modal-card select {
  width: 100%; height: 36px; border: 0.5px solid var(--border); border-radius: var(--radius);
  padding: 0 10px; font-size: 13px; margin-bottom: 10px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); font-size: 13px; }

/* Chat with R */
.chat-window {
  height: 440px; overflow-y: auto; background: var(--surface); border: 0.5px solid var(--border);
  border-radius: 12px; padding: 16px; margin-bottom: 12px; display: flex; flex-direction: column; gap: 10px;
}
.chat-bubble { max-width: 75%; padding: 8px 14px; border-radius: 12px; font-size: 13px; line-height: 1.5; white-space: pre-wrap; }
.chat-user { align-self: flex-end; background: var(--text-primary); color: #fff; }
.chat-assistant { align-self: flex-start; background: var(--bg); color: var(--text-primary); border: 0.5px solid var(--border); }
.chat-input-row { display: flex; gap: 8px; }
.chat-input-row input { flex: 1; height: 40px; border: 0.5px solid var(--border); border-radius: var(--radius); padding: 0 14px; font-size: 16px; }
.chat-input-row input:focus { outline: none; border-color: var(--accent); }

/* Marketing equipment grid */
.equip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.equip-card { background: var(--surface); border: 0.5px solid var(--border); border-radius: 12px; overflow: hidden; }
.equip-photo { width: 100%; height: 120px; background: var(--bg); display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 24px; overflow: hidden; }
.equip-photo img { width: 100%; height: 100%; object-fit: cover; }
.equip-body { padding: 10px 12px; }
.equip-name { font-size: 13px; font-weight: 500; margin-bottom: 2px; }
.equip-meta { font-size: 11px; color: var(--text-muted); }
.equip-qty-row { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.equip-qty-row input { width: 50px; height: 28px; font-size: 16px; border: 0.5px solid var(--border); border-radius: 6px; text-align: center; }

/* Mobile: off-canvas sidebar + hamburger */
.mobile-topbar { display: none; }
.sidebar-overlay { display: none; }

@media (max-width: 768px) {
  #app-shell { flex-direction: column; height: 100vh; }
  .mobile-topbar {
    display: flex; align-items: center; gap: 12px;
    height: 60px; min-height: 60px; padding: 0 12px;
    background: var(--surface); border-bottom: 0.5px solid var(--border);
  }
  .mobile-topbar button {
    display: flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; min-width: 44px;
    background: var(--bg); border: 0.5px solid var(--border);
    border-radius: 8px; font-size: 24px; line-height: 1;
    color: var(--text-primary); cursor: pointer;
  }
  .mobile-topbar button:active { background: var(--border); }
  .mobile-topbar-title { font-size: 15px; font-weight: 500; }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; z-index: 30;
    transform: translateX(-100%); transition: transform 0.2s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,0.15);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 20;
  }
  .sidebar-overlay.open { display: block; }
  .main { padding: 16px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }

  body { font-size: 15px; }
  .nav-item { font-size: 15px; padding: 11px 16px; }
  .nav-section-label { font-size: 11px; }
  .page-title { font-size: 20px; }
  .page-sub { font-size: 13px; }
  .brief-label { font-size: 14px; }
  .brief-text { font-size: 14px; }
  .stat-label { font-size: 13px; }
  .stat-value { font-size: 26px; }
  table, th, td { font-size: 14px; }
  th { font-size: 13px; }
  .btn { font-size: 15px; padding: 9px 16px; }
  .equip-name { font-size: 14px; }
  .equip-meta { font-size: 12px; }
  .chat-bubble { font-size: 14px; }
  .login-card h1 { font-size: 20px; }
  .login-card p { font-size: 13px; }
}
