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

:root {
  --bg:        #000000;
  --surface:   #1C1C1E;
  --surface2:  #2C2C2E;
  --border:    #38383A;
  --text:      #FFFFFF;
  --text2:     #8E8E93;
  --accent:    #007AFF;
  --green:     #30D158;
  --orange:    #FF9F0A;
  --red:       #FF453A;
  --radius:    12px;
  --font:      system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --sidebar-w: 220px;
  --tab-h:     60px;

  /* ── Backwards-compat aliases (old theme variable names) ───────── */
  --muted:        #8E8E93;   /* was text2 */
  --card:         #1C1C1E;   /* was surface */
  --border-light: rgba(255,255,255,0.18);
  --danger:       #FF453A;   /* was red */
  --success:      #30D158;   /* was green */
  --warning:      #FF9F0A;   /* was orange */
  --gradient:     linear-gradient(135deg, #007AFF 0%, #5AC8FA 100%);
  --gradient-subtle: rgba(0,122,255,0.12);
  --shadow:       0 4px 24px rgba(0,0,0,0.5);
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ── SIDEBAR (desktop) ──────────────────────────────────────────── */
#app-sidebar {
  display: none; /* hidden on mobile by default */
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  flex-direction: column;
  z-index: 100;
  padding: 0 0 24px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
}
.sidebar-brand-icon { font-size: 22px; }
.sidebar-brand-name { font-size: 15px; font-weight: 700; color: var(--text); }
.sidebar-brand-sub  { font-size: 11px; color: var(--text2); }

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text2);
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--font);
}
.sidebar-item:hover { background: var(--surface2); color: var(--text); }
.sidebar-item.active { background: rgba(0,122,255,0.15); color: var(--accent); }
.sidebar-item-icon { font-size: 18px; width: 24px; text-align: center; }
.sidebar-item-label { flex: 1; }

.sidebar-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 10px 4px;
}

.sidebar-logout {
  padding: 0 8px;
}

/* ── Hide old nav placeholder ───────────────────────────────────── */
nav#main-nav { display: none !important; }

/* ── BOTTOM TAB BAR (mobile by default) ────────────────────────── */
#app-tabs {
  display: flex; /* shown on mobile by default */
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.tab-bar {
  display: flex;
  width: 100%;
  height: var(--tab-h);
  align-items: center;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-decoration: none;
  color: var(--text2);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  font-family: var(--font);
  padding: 6px 4px;
  transition: color .15s;
  min-width: 0;
}
.tab-item.active { color: var(--accent); }
.tab-item-icon { font-size: 24px; line-height: 1; display: block; }

/* ── MAIN CONTENT (mobile-first) ────────────────────────────────── */
main {
  margin-left: 0;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 20px);
  min-height: 100vh;
}

/* Desktop: show sidebar, hide tab bar, add left margin */
@media (min-width: 769px) {
  #app-sidebar { display: flex; }
  #app-tabs    { display: none; }
  main {
    margin-left: var(--sidebar-w);
    padding: 24px;
  }
}

/* ── PAGE HEADER ────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}
.page-header h1 {
  font-size: 22px;
  font-weight: 700;
}
.page-subtitle {
  font-size: 13px;
  color: var(--text2);
  margin-top: 2px;
}

/* ── CARDS ──────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.card-section {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}
.card-section-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── GROUPED LIST (iOS Settings style) ─────────────────────────── */
.grouped-list {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}
.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  min-height: 52px;
}
.list-row:last-child { border-bottom: none; }

.list-avatar {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  font-weight: 700;
}
.list-avatar-text { font-size: 14px; font-weight: 700; }

.list-content { flex: 1; min-width: 0; }
.list-title   { font-size: 14px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-sub     { font-size: 12px; color: var(--text2); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.list-right   { text-align: right; flex-shrink: 0; }
.list-value   { font-size: 13px; font-weight: 600; color: var(--text); }
.list-meta    { font-size: 11px; color: var(--text2); margin-top: 1px; }

.list-chevron { color: var(--text2); font-size: 12px; }

/* ── BUTTONS ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  transition: opacity .15s, transform .1s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }

.btn-primary   { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-danger    { background: rgba(255,69,58,0.15); color: var(--red); }
.btn-ghost     { background: none; color: var(--text2); }
.btn-success { background: var(--green); color: #000; font-weight: 700; }
.btn-sm        { padding: 6px 12px; font-size: 12px; border-radius: 8px; }
.btn-xs        { padding: 3px 9px; font-size: 11px; border-radius: 6px; }

.btn:hover { opacity: 0.85; }

/* ── BADGES ─────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green  { background: rgba(48,209,88,0.15);  color: var(--green); }
.badge-orange { background: rgba(255,159,10,0.15); color: var(--orange); }
.badge-red    { background: rgba(255,69,58,0.15);  color: var(--red); }
.badge-blue   { background: rgba(0,122,255,0.15);  color: var(--accent); }
.badge-gray   { background: var(--surface2);        color: var(--text2); }

/* ── FORMS ──────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
input, select, textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  padding: 10px 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--text2); }
select option { background: var(--surface); }
textarea { resize: vertical; min-height: 80px; }

/* Alias for old class name */
.form-control { /* inherits input styles via element selector */ }

/* ── TABLE ──────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
table tr:last-child td { border-bottom: none; }
table tr:hover td { background: var(--surface2); }

/* ── STATS ROW ──────────────────────────────────────────────────── */
.stats-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.stat-box {
  flex: 1;
  min-width: 60px;
  background: var(--surface2);
  border-radius: 10px;
  padding: 10px 12px;
  text-align: center;
}
.stat-value { font-size: 18px; font-weight: 700; color: var(--text); }
.stat-label { font-size: 10px; color: var(--text2); margin-top: 2px; }

/* ── ALERTS ─────────────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: 10px; font-size: 13px; margin-bottom: 12px; }
.alert-success { background: rgba(48,209,88,0.12);  color: var(--green);  border: 1px solid rgba(48,209,88,0.2); }
.alert-danger  { background: rgba(255,69,58,0.12);  color: var(--red);    border: 1px solid rgba(255,69,58,0.2); }
.alert-info    { background: rgba(0,122,255,0.12);  color: var(--accent); border: 1px solid rgba(0,122,255,0.2); }

/* ── MODAL ──────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(6px);
  padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 16px;
}
.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── TABS (filter pills) ────────────────────────────────────────── */
.filter-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.filter-tabs::-webkit-scrollbar { display: none; }
.filter-tab {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: none;
  color: var(--text2);
  cursor: pointer;
  font-family: var(--font);
  white-space: nowrap;
  transition: all .15s;
  flex-shrink: 0;
}
.filter-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── EMPTY STATE ────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text2);
}
.empty-state-icon { font-size: 36px; margin-bottom: 12px; }
.empty-state-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty-state-sub   { font-size: 13px; }

/* ── DIVIDER ────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* ── LOADING ────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── LOGIN PAGE ─────────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.login-wrap { width: 100%; max-width: 360px; }
.login-brand { text-align: center; margin-bottom: 32px; }
.login-brand-icon { font-size: 40px; margin-bottom: 8px; }
.login-brand h1 { font-size: 24px; font-weight: 700; }
.login-brand p  { font-size: 13px; color: var(--text2); margin-top: 4px; }
.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 28px;
}

/* ── PIPELINE ───────────────────────────────────────────────────── */
.pipeline-mobile-tabs {
  display: none;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  margin-bottom: 12px;
  gap: 6px;
}
.pipeline-mobile-tabs::-webkit-scrollbar { display: none; }

.pipeline-wrap {
  display: grid;
  grid-template-columns: repeat(6, minmax(200px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 12px;
  align-items: start;
}

.pipeline-col {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  min-width: 220px;
}
.pipeline-col-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.pipeline-col-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text2);
}
.pipeline-col-count {
  font-size: 11px;
  background: var(--surface2);
  border-radius: 20px;
  padding: 2px 8px;
  color: var(--text2);
  font-weight: 600;
}
.pipeline-col-appointment .pipeline-col-header { border-top: 3px solid #7AB3FF; }
.pipeline-col-rescheduled .pipeline-col-header  { border-top: 3px solid var(--orange); }
.pipeline-col-proposal .pipeline-col-header     { border-top: 3px solid #A78BFA; }
.pipeline-col-won .pipeline-col-header          { border-top: 3px solid var(--green); }
.pipeline-col-lost .pipeline-col-header         { border-top: 3px solid var(--red); }

.pipeline-col-body { padding: 8px; min-height: 60px; display: flex; flex-direction: column; gap: 6px; }

.deal-card {
  background: var(--surface2);
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  transition: opacity .15s;
}
.deal-card:hover { opacity: 0.85; }
.deal-company { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deal-name    { font-size: 12px; color: var(--text2); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deal-value   { font-size: 13px; font-weight: 700; color: var(--accent); margin-top: 6px; }
.deal-appt    { font-size: 11px; color: var(--accent); margin-top: 3px; }
.deal-meta    { font-size: 11px; color: var(--text2); margin-top: 3px; opacity: 0.7; }

.stage-btns { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.stage-btn {
  border: 1px solid var(--border);
  background: none;
  color: var(--text2);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font);
  white-space: nowrap;
}
.stage-btn:hover  { border-color: var(--text2); color: var(--text); }
.stage-btn.target-won  { border-color: rgba(48,209,88,.3);  color: var(--green); }
.stage-btn.target-won:hover  { background: rgba(48,209,88,.1); }
.stage-btn.target-lost { border-color: rgba(255,69,58,.3);  color: var(--red); }
.stage-btn.target-lost:hover { background: rgba(255,69,58,.08); }

@media (max-width: 768px) {
  .pipeline-mobile-tabs { display: flex; }
  .pipeline-wrap { grid-template-columns: 1fr; min-width: unset; }
  .pipeline-col { min-width: unset; }
  .pipeline-col.hidden { display: none; }
}

/* ── UNIBOX ─────────────────────────────────────────────────────── */
.unibox-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: calc(100vh - 48px);
  margin: 0;
  overflow: hidden;
}
.unibox-sidebar {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.unibox-sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.unibox-sidebar-title { font-size: 17px; font-weight: 700; margin-bottom: 10px; }
.unibox-thread-list   { flex: 1; overflow-y: auto; }

.thread-item {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
}
.thread-item:hover { background: var(--surface2); }
.thread-item.active { background: rgba(0,122,255,0.1); }
.thread-item.unread .thread-from { font-weight: 700; }

.thread-avatar {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
  flex-shrink: 0;
}
.thread-body   { flex: 1; min-width: 0; }
.thread-top    { display: flex; justify-content: space-between; align-items: baseline; gap: 4px; }
.thread-from   { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-time   { font-size: 11px; color: var(--text2); flex-shrink: 0; }
.thread-preview{ font-size: 12px; color: var(--text2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.unibox-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.unibox-main-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.unibox-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.unibox-compose  {
  border-top: 1px solid var(--border);
  padding: 16px 20px;
  flex-shrink: 0;
}

.msg-bubble { max-width: 70%; }
.msg-bubble.outbound { align-self: flex-end; }
.msg-bubble.inbound  { align-self: flex-start; }
.msg-content {
  background: var(--surface2);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
}
.msg-bubble.outbound .msg-content { background: var(--accent); color: #fff; }
.msg-meta { font-size: 11px; color: var(--text2); margin-top: 4px; padding: 0 4px; }
.msg-bubble.outbound .msg-meta { text-align: right; }

@media (max-width: 768px) {
  .unibox-layout { grid-template-columns: 1fr; margin: 0; height: calc(100vh - var(--tab-h) - env(safe-area-inset-bottom)); }
  .unibox-main   { display: none; }
  .unibox-main.visible { display: flex; position: fixed; inset: 0; bottom: var(--tab-h); z-index: 50; background: var(--bg); }
  .unibox-sidebar { border-right: none; }
}

/* ── SCRAPER ────────────────────────────────────────────────────── */
.scraper-tabs { display: flex; gap: 0; margin-bottom: 16px; border-radius: 10px; overflow: hidden; background: var(--surface); border: 1px solid var(--border); width: fit-content; }
.scraper-tab  { padding: 8px 20px; font-size: 13px; font-weight: 600; cursor: pointer; border: none; background: none; color: var(--text2); font-family: var(--font); transition: all .15s; }
.scraper-tab.active { background: var(--accent); color: #fff; }

.result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.result-item:last-child { border-bottom: none; }
.result-name   { font-size: 14px; font-weight: 500; }
.result-detail { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* ── MISC ───────────────────────────────────────────────────────── */
.text-muted   { color: var(--text2); }
.text-accent  { color: var(--accent); }
.text-green   { color: var(--green); }
.text-orange  { color: var(--orange); }
.text-red     { color: var(--red); }
.text-sm      { font-size: 12px; }
.text-xs      { font-size: 11px; }
.fw-600       { font-weight: 600; }
.fw-700       { font-weight: 700; }
.mt-8         { margin-top: 8px; }
.mt-12        { margin-top: 12px; }
.mt-16        { margin-top: 16px; }
.mb-8         { margin-bottom: 8px; }
.mb-12        { margin-bottom: 12px; }
.mb-16        { margin-bottom: 16px; }
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; }
.gap-8        { gap: 8px; }
.gap-12       { gap: 12px; }
.ml-auto      { margin-left: auto; }
.w-full       { width: 100%; }
.hidden       { display: none !important; }
