/* Debrieft — app.css v2 */

/* ── Theme tokens ──────────────────────────────────────────────────────────── */
:root {
  --bg:        #0d0e11;
  --bg2:       #14161b;
  --bg3:       #1c1f27;
  --border:    #252831;
  --text:      #e8eaf0;
  --text2:     #8b90a0;
  --accent:    #6c63ff;
  --accent2:   #a78bfa;
  --green:     #34d399;
  --yellow:    #fbbf24;
  --orange:    #fb923c;
  --red:       #f87171;
  --teal:      #2dd4bf;
  --blue:      #60a5fa;
  --purple:    #c084fc;
  --radius:    10px;
  --radius-lg: 16px;
  --sidebar-w: 240px;
  --shadow:    0 4px 24px rgba(0,0,0,.35);
  --card-bg:   var(--bg2);
  --input-bg:  var(--bg3);
}

body.light {
  --bg:      #f3f4f8;
  --bg2:     #ffffff;
  --bg3:     #eef0f5;
  --border:  #e0e3ec;
  --text:    #1a1c28;
  --text2:   #636880;
  --accent:  #5b54f0;
  --accent2: #7c6ff0;
  --shadow:  0 4px 24px rgba(0,0,0,.07);
  --card-bg: #ffffff;
  --input-bg:#f3f4f8;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.6;
  transition: background .2s, color .2s;
}

/* ─────────────────────────────────────────── SIDEBAR */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: background .2s, border-color .2s;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
}

.brand-logo { height: 30px; width: auto; object-fit: contain; }

.brand-mark {
  width: 30px; height: 30px;
  background: var(--accent); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Syne', sans-serif; font-weight: 800; font-size: 15px;
  color: #fff; flex-shrink: 0;
}

.brand-name {
  font-family: 'Syne', sans-serif; font-weight: 700; font-size: 17px;
  letter-spacing: -.4px; color: var(--text);
}

.nav-links {
  list-style: none; padding: 12px 10px;
  flex: 1; display: flex; flex-direction: column; gap: 2px;
}

.nav-links a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius);
  color: var(--text2); text-decoration: none;
  font-size: 14px; font-weight: 500; transition: all .15s;
}

.nav-links a svg {
  width: 18px; height: 18px;
  stroke: currentColor; fill: none;
  stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
}

.nav-links a:hover { background: var(--bg3); color: var(--text); }
.nav-links a.active { background: var(--bg3); color: var(--accent2); }

.sidebar-footer {
  padding: 12px 10px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 3px;
}

.theme-toggle {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius);
  color: var(--text2); font-size: 14px; font-weight: 500;
  cursor: pointer; background: none; border: none; width: 100%;
  text-align: left; font-family: 'DM Sans', sans-serif; transition: all .15s;
}
.theme-toggle:hover { background: var(--bg3); color: var(--text); }
.theme-toggle svg {
  width: 18px; height: 18px; stroke: currentColor; fill: none;
  stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0;
}

.nav-settings {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius);
  color: var(--text2); text-decoration: none;
  font-size: 14px; font-weight: 500; transition: all .15s;
}
.nav-settings:hover { background: var(--bg3); color: var(--text); }
.nav-settings svg {
  width: 18px; height: 18px; stroke: currentColor; fill: none;
  stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
}

.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius);
  background: var(--bg3); margin-top: 2px;
}

.avatar {
  width: 30px; height: 30px; background: var(--accent); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff; flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.user-info strong { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info small  { font-size: 11px; color: var(--text2); }

.logout-btn { color: var(--text2); flex-shrink: 0; display: flex; }
.logout-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.logout-btn:hover { color: var(--red); }

/* ─────────────────────────────────────────── MAIN */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1; padding: 28px 32px;
  min-width: 0; max-width: calc(100vw - var(--sidebar-w));
}

/* ─────────────────────────────────────────── PAGE HEADER */
.page-header {
  display: flex; align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px; gap: 12px; flex-wrap: wrap;
}

.page-header h1 {
  font-family: 'Syne', sans-serif; font-size: 24px;
  font-weight: 700; line-height: 1.2;
}

.page-header .subtitle { color: var(--text2); font-size: 14px; margin-top: 3px; }

/* ─────────────────────────────────────────── CARDS */
.card {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 22px;
  transition: background .2s, border-color .2s;
}

.card-title { font-family: 'Syne', sans-serif; font-size: 16px; font-weight: 600; margin-bottom: 16px; }

/* ─────────────────────────────────────────── STAT CARDS */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 22px; }

.stat-card {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px 20px; transition: background .2s;
}

.stat-label { font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: .8px; font-weight: 600; }
.stat-value { font-family: 'Syne', sans-serif; font-size: 30px; font-weight: 700; margin-top: 4px; }

/* ─────────────────────────────────────────── TABLE */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }

th {
  text-align: left; font-size: 11px; text-transform: uppercase;
  letter-spacing: .8px; color: var(--text2); font-weight: 600;
  padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}

td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: var(--bg3); }

/* ─────────────────────────────────────────── BADGES */
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-purple { background: rgba(192,132,252,.15); color: var(--purple); }
.badge-blue   { background: rgba(96,165,250,.15);  color: var(--blue); }
.badge-green  { background: rgba(52,211,153,.15);  color: var(--green); }
.badge-yellow { background: rgba(251,191,36,.15);  color: var(--yellow); }
.badge-orange { background: rgba(251,146,60,.15);  color: var(--orange); }
.badge-teal   { background: rgba(45,212,191,.15);  color: var(--teal); }
.badge-gray   { background: rgba(139,144,160,.15); color: var(--text2); }
.badge-red    { background: rgba(248,113,113,.15); color: var(--red); }

/* ─────────────────────────────────────────── BUTTONS */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px; border-radius: var(--radius);
  font-family: 'DM Sans', sans-serif; font-size: 14px; font-weight: 500;
  cursor: pointer; text-decoration: none; border: none;
  transition: all .15s; white-space: nowrap; flex-shrink: 0;
}

.btn svg {
  width: 16px; height: 16px; stroke: currentColor; fill: none;
  stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #5a52e8; }
.btn-ghost   { background: var(--bg3); color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); }
.btn-danger  { background: rgba(248,113,113,.1); color: var(--red); border: 1px solid rgba(248,113,113,.2); }
.btn-danger:hover { background: rgba(248,113,113,.2); }
.btn-sm  { padding: 6px 13px; font-size: 13px; }
.btn-ai  { background: linear-gradient(135deg, #6c63ff, #a78bfa); color: #fff; }
.btn-ai:hover { opacity: .9; }

/* ─────────────────────────────────────────── FORMS */
.form-group { margin-bottom: 18px; }

label { display: block; font-size: 13px; font-weight: 500; color: var(--text2); margin-bottom: 5px; }

input[type=text], input[type=email], input[type=password],
input[type=number], input[type=date], input[type=url],
select, textarea {
  width: 100%;
  background: var(--input-bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 13px;
  color: var(--text); font-family: 'DM Sans', sans-serif;
  font-size: 14px; outline: none;
  transition: border-color .15s, background .2s;
  -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108,99,255,.12);
}

textarea { resize: vertical; min-height: 100px; }
select option { background: var(--bg2); color: var(--text); }

.form-row        { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ─────────────────────────────────────────── FLASH */
.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 18px; font-size: 14px; }
.flash-success { background: rgba(52,211,153,.1);  border: 1px solid rgba(52,211,153,.2);  color: var(--green); }
.flash-error   { background: rgba(248,113,113,.1); border: 1px solid rgba(248,113,113,.2); color: var(--red); }
.flash-info    { background: rgba(96,165,250,.1);  border: 1px solid rgba(96,165,250,.2);  color: var(--blue); }

/* ─────────────────────────────────────────── TABS */
.tabs {
  display: flex; gap: 2px; border-bottom: 1px solid var(--border);
  margin-bottom: 22px; overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  padding: 9px 16px; font-size: 14px; font-weight: 500;
  color: var(--text2); text-decoration: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: all .15s; white-space: nowrap; flex-shrink: 0;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent2); border-bottom-color: var(--accent2); }

/* ─────────────────────────────────────────── PIPELINE */
.pipeline {
  display: flex; gap: 4px;
  background: var(--bg3); border-radius: var(--radius-lg);
  padding: 5px; margin-bottom: 22px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}

.pipeline-step {
  flex: 1; text-align: center; padding: 8px 10px;
  border-radius: var(--radius); font-size: 11px; font-weight: 600;
  color: var(--text2); text-transform: uppercase; letter-spacing: .4px;
  min-width: 72px; white-space: nowrap;
}
.pipeline-step.done    { background: rgba(52,211,153,.1); color: var(--green); }
.pipeline-step.current { background: var(--accent); color: #fff; }

/* ─────────────────────────────────────────── QUOTE LINE ITEMS */
.line-item-header {
  display: grid; grid-template-columns: 3fr 1fr 1fr 1fr 36px; gap: 8px;
  font-size: 11px; font-weight: 600; color: var(--text2);
  text-transform: uppercase; letter-spacing: .6px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border); margin-bottom: 8px;
}

.line-item-row {
  display: grid; grid-template-columns: 3fr 1fr 1fr 1fr 36px;
  gap: 8px; align-items: center; margin-bottom: 8px;
}

.line-item-total { font-size: 14px; color: var(--text2); text-align: right; padding-right: 4px; }

.quote-summary {
  margin-top: 16px; display: flex; flex-direction: column;
  align-items: flex-end; gap: 8px;
  border-top: 1px solid var(--border); padding-top: 16px;
}

.quote-summary .row       { display: flex; gap: 60px; font-size: 14px; }
.quote-summary .row.total { font-family: 'Syne', sans-serif; font-weight: 700; font-size: 20px; color: var(--accent2); }

/* ─────────────────────────────────────────── BRIEF */
.brief-content {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 24px; line-height: 1.8;
}

.brief-content h1, .brief-content h2 { font-family: 'Syne', sans-serif; font-weight: 700; margin: 20px 0 8px; color: var(--accent2); }
.brief-content h1 { font-size: 20px; }
.brief-content h2 { font-size: 17px; }
.brief-content h3 { font-size: 15px; font-weight: 600; margin: 14px 0 6px; }
.brief-content ul { padding-left: 20px; margin: 8px 0; }
.brief-content li { margin-bottom: 4px; }
.brief-content p  { margin-bottom: 10px; }
.brief-content strong { color: var(--text); }

/* ─────────────────────────────────────────── HANDOVER */
.handover-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; margin-top: 14px; }
.handover-item { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; }
.handover-item-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.handover-item-title  { font-weight: 600; font-size: 14px; }
.handover-item-content { font-size: 13px; color: var(--text2); white-space: pre-wrap; word-break: break-word; }
.sensitive-mask { filter: blur(5px); transition: filter .2s; cursor: pointer; user-select: none; }
.sensitive-mask:hover { filter: none; }

/* ─────────────────────────────────────────── AUTH */
.auth-wrap {
  min-height: 100vh; width: 100%;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 20px;
}

.auth-card {
  width: 100%; max-width: 420px;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 36px;
}

.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.auth-logo img { height: 34px; width: auto; }

.auth-card h2 { font-family: 'Syne', sans-serif; font-size: 22px; font-weight: 700; margin-bottom: 5px; }
.auth-card > p { color: var(--text2); font-size: 14px; margin-bottom: 24px; }

/* ─────────────────────────────────────────── PORTAL */
.portal-wrap    { max-width: 860px; margin: 0 auto; padding: 48px 24px; }
.portal-header  { text-align: center; margin-bottom: 48px; }
.portal-header h1 { font-family: 'Syne', sans-serif; font-size: 30px; font-weight: 800; }
.portal-section { margin-bottom: 28px; }
.portal-section h2 { font-family: 'Syne', sans-serif; font-size: 17px; font-weight: 600; margin-bottom: 14px; color: var(--accent2); }

/* ─────────────────────────────────────────── SIG PAD */
.sig-wrap { background: #fff; border-radius: var(--radius); overflow: hidden; display: inline-block; max-width: 100%; }
#sig-canvas { display: block; cursor: crosshair; max-width: 100%; }

/* ─────────────────────────────────────────── AI SPINNER */
.ai-spinner { display: none; align-items: center; gap: 10px; color: var(--accent2); font-size: 14px; margin-top: 12px; }
.ai-spinner.visible { display: flex; }
.spinner { width: 18px; height: 18px; border: 2px solid rgba(108,99,255,.2); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─────────────────────────────────────────── EMPTY STATE */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text2); }
.empty-state h3 { font-family: 'Syne', sans-serif; font-size: 17px; color: var(--text); margin-bottom: 6px; margin-top: 14px; }
.empty-state .big-icon { font-size: 44px; opacity: .3; }

/* ─────────────────────────────────────────── MOBILE TOPBAR */
.mobile-topbar {
  display: none;
  position: fixed; top: 0; left: 0; right: 0;
  height: 54px;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  z-index: 150;
  align-items: center; padding: 0 16px; gap: 10px;
  transition: background .2s;
}

.mobile-topbar img { height: 26px; width: auto; object-fit: contain; }
.mobile-topbar .spacer { flex: 1; }

.icon-btn {
  width: 36px; height: 36px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text2); cursor: pointer; flex-shrink: 0;
  text-decoration: none; transition: color .15s;
}

.icon-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { color: var(--text); }

/* ─────────────────────────────────────────── MOBILE BOTTOM NAV */
.mobile-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg2); border-top: 1px solid var(--border);
  z-index: 200;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  transition: background .2s;
}

.mobile-nav-inner { display: flex; align-items: stretch; }

.mobile-nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 4px; padding: 10px 4px;
  text-decoration: none; color: var(--text2);
  font-size: 9px; font-weight: 600; letter-spacing: .4px;
  text-transform: uppercase; transition: color .15s;
  border: none; background: none; cursor: pointer;
  font-family: 'DM Sans', sans-serif;
}

.mobile-nav-item svg {
  width: 22px; height: 22px; stroke: currentColor; fill: none;
  stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
}

.mobile-nav-item.active { color: var(--accent2); }
.mobile-nav-item:hover  { color: var(--accent2); }

/* ─────────────────────────────────────────── RESPONSIVE */
@media (max-width: 768px) {
  .sidebar      { display: none; }
  .mobile-topbar{ display: flex; }
  .mobile-nav   { display: block; }

  .main-content {
    margin-left: 0;
    max-width: 100vw;
    padding: 16px;
    padding-top: calc(54px + 16px);
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px) + 16px);
  }

  .form-row, .form-row.cols-3 { grid-template-columns: 1fr; }

  .page-header { flex-direction: column; gap: 10px; }

  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-value { font-size: 24px; }

  /* Quote line items stack */
  .line-item-header { display: none; }
  .line-item-row {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    background: var(--bg3); border-radius: var(--radius);
    padding: 10px; margin-bottom: 10px; gap: 6px;
  }
  .line-item-row input.line-item-desc { grid-column: 1 / -1; }
  .line-item-total { text-align: left; }
  .quote-summary .row { gap: 24px; }

  .pipeline { flex-wrap: nowrap; }
  .pipeline-step { font-size: 10px; padding: 6px 8px; min-width: 66px; }

  .handover-grid { grid-template-columns: 1fr; }

  .tab  { padding: 9px 12px; font-size: 13px; }

  .auth-card { padding: 24px 20px; }

  td, th { padding: 10px 12px; }
  .hide-mobile { display: none !important; }

  .brief-content { padding: 16px; }
  .quote-summary { align-items: flex-start; }

  .page-header h1 { font-size: 20px; }
}

@media (max-width: 400px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .main-content { padding: 12px; padding-top: 70px; padding-bottom: 80px; }
}
