:root {
  /* Warm "paper" palette — easy on the eyes, high contrast, not stark white. */
  --bg: #f1ead9;          /* warm parchment page */
  --bg-2: #e9e0cd;        /* slightly deeper: header strip, input wells */
  --panel: #fbf7ee;       /* card / column surface (soft ivory) */
  --panel-2: #f4ecdb;     /* nested surface */
  --border: #d8ccb4;      /* warm tan hairline */
  --border-strong: #c4b596;
  --text: #2c2722;        /* warm near-black, strong contrast */
  --muted: #6a6053;       /* warm brown-grey, still AA on ivory */
  --accent: #1f7a72;      /* calm teal */
  --accent-2: #19655e;    /* deeper teal for hovers/primary */
  --accent-soft: #d9ece9;
  --green: #2f7a52;       /* money */
  --red: #b23227;         /* overdue / danger */
  --amber: #8a5a00;       /* premium accent */
  --radius: 12px;
  --shadow: 0 6px 22px rgba(86, 72, 48, 0.13);
  --shadow-sm: 0 1px 3px rgba(86, 72, 48, 0.10);
  --focus: 0 0 0 3px rgba(31, 122, 114, 0.35);
}

* { box-sizing: border-box; }
/* The `hidden` attribute must always win over explicit display rules (.board, .drawer, …). */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }

/* --- Brand / login --------------------------------------------------------- */
.brand { font-weight: 800; font-size: 19px; display: flex; align-items: center; gap: 9px; letter-spacing: .2px; color: var(--text); }
.brand-dot { width: 13px; height: 13px; border-radius: 50%; background: radial-gradient(circle at 32% 30%, #4fb3a8, var(--accent-2)); box-shadow: 0 0 0 4px rgba(31, 122, 114, .14); }
.brand-sub { color: var(--accent-2); font-weight: 700; }

.login-body { display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, #f1ead9, #e7dcc6); }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 42px 38px; width: 360px; box-shadow: var(--shadow); text-align: center; }
.login-card .brand { justify-content: center; font-size: 26px; }
.login-tag { color: var(--muted); margin: 10px 0 28px; font-size: 15px; }
.login-quote { margin: 16px 0 28px; transition: opacity .25s ease; min-height: 78px; display: flex; flex-direction: column; justify-content: center; }
.login-quote blockquote { margin: 0; font-size: 15.5px; line-height: 1.55; color: var(--text); font-style: italic; }
.login-quote figcaption { margin-top: 9px; font-size: 12.5px; color: var(--accent-2); font-weight: 600; }
.login-error { background: #f7e4df; border: 1px solid #e3b3aa; color: #8c241a; padding: 11px 13px; border-radius: 9px; margin-bottom: 18px; font-size: 14px; }
.login-hint { color: var(--muted); }
#password-form { display: flex; flex-direction: column; gap: 11px; }

/* --- Buttons --------------------------------------------------------------- */
.btn { background: var(--panel); color: var(--text); border: 1px solid var(--border-strong); border-radius: 9px; padding: 9px 15px; font-size: 14px; font-weight: 600; cursor: pointer; transition: background .12s, border-color .12s, box-shadow .12s; text-decoration: none; display: inline-flex; align-items: center; box-shadow: var(--shadow-sm); }
.btn:hover { background: #fff; border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-danger { background: #fff; border-color: #e0b4ac; color: var(--red); }
.btn-danger:hover { background: #fbeae6; border-color: var(--red); }
.btn-ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--bg-2); color: var(--text); border-color: var(--border); }
.btn-google { background: #fff; color: #2c2722; border: 1px solid var(--border-strong); justify-content: center; padding: 12px; font-weight: 700; font-size: 15px; }
.btn-sm { padding: 5px 11px; font-size: 13px; }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; line-height: 1; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { color: var(--text); background: var(--bg-2); }

input, select, textarea { background: #fffdf7; border: 1px solid var(--border-strong); color: var(--text); border-radius: 8px; padding: 9px 11px; font-size: 14px; font-family: inherit; }
input::placeholder, textarea::placeholder { color: #9a8f7d; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }

/* --- Top bar --------------------------------------------------------------- */
.topbar { display: flex; align-items: center; gap: 18px; padding: 13px 22px; background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap; position: sticky; top: 0; z-index: 20; box-shadow: var(--shadow-sm); }
.summary { display: flex; align-items: center; gap: 16px; flex: 1; flex-wrap: wrap; }
.kpi { display: flex; flex-direction: column; line-height: 1.15; }
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); font-weight: 700; }
.kpi-val { font-size: 19px; font-weight: 800; color: var(--accent-2); }
.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip { background: var(--bg-2); border: 1px solid var(--border); border-radius: 20px; padding: 4px 12px; font-size: 12px; color: var(--muted); }
.chip b { color: var(--text); font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search { width: 210px; }
.me { color: var(--muted); font-size: 13px; font-weight: 600; }
.viewtoggle { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 9px; overflow: hidden; box-shadow: var(--shadow-sm); }
.viewtoggle button { background: var(--panel); border: none; color: var(--muted); padding: 9px 16px; cursor: pointer; font-size: 14px; font-weight: 600; }
.viewtoggle button:hover { background: var(--bg-2); }
.viewtoggle button.active { background: var(--accent); color: #fff; }

/* --- Board ----------------------------------------------------------------- */
main { padding: 20px 22px 64px; }
.board { display: flex; gap: 16px; align-items: flex-start; overflow-x: auto; }
.column { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); width: 286px; min-width: 286px; display: flex; flex-direction: column; max-height: calc(100vh - 140px); box-shadow: var(--shadow-sm); }
.col-head { display: flex; justify-content: space-between; align-items: center; padding: 13px 15px; font-weight: 700; font-size: 15px; border-bottom: 2px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; background: var(--panel-2); }
.col-count { color: var(--muted); font-size: 12px; font-weight: 600; }
.col-list { padding: 11px; display: flex; flex-direction: column; gap: 11px; overflow-y: auto; min-height: 60px; }
.card { background: #fff; border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 10px; padding: 12px 13px; cursor: pointer; transition: border-color .12s, box-shadow .12s, transform .04s; box-shadow: var(--shadow-sm); }
.card:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); }
.card { touch-action: pan-y; }   /* let the page scroll until a long-press grabs the card */
.drag-ghost { position: fixed; top: 0; left: 0; z-index: 80; pointer-events: none; box-shadow: var(--shadow); opacity: .96; transform: rotate(1.5deg); }
.card-placeholder { border: 2px dashed var(--accent); border-radius: 10px; background: var(--accent-soft); }
body.dragging-active { cursor: grabbing; user-select: none; -webkit-user-select: none; touch-action: none; }
.card-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.card-name { font-weight: 700; font-size: 15px; }
.card-company { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card-meta { display: flex; gap: 8px; align-items: center; margin-top: 9px; flex-wrap: wrap; }
.card-value { font-weight: 800; color: var(--green); font-size: 15px; }
.card-ta { font-size: 12px; color: var(--accent-2); background: var(--accent-soft); padding: 2px 9px; border-radius: 10px; font-weight: 600; }
.card-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; font-size: 12px; color: var(--muted); }
.due { background: var(--bg-2); padding: 3px 9px; border-radius: 7px; font-weight: 600; }
.due.overdue { background: #f7e0db; color: var(--red); }

.badge { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; padding: 3px 8px; border-radius: 7px; font-weight: 800; }
.badge-basic { background: #ece3d1; color: #6a6053; }
.badge-pro { background: #d7e8ec; color: #1c6378; }
.badge-premium { background: #f4e6c6; color: var(--amber); }
.badge-admin { background: #d8ebe0; color: #2f7a52; }
.badge-editor { background: #d9e4f1; color: #2a5d8f; }

/* --- Table ----------------------------------------------------------------- */
.table-view { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.deals-table { width: 100%; border-collapse: collapse; }
.deals-table th, .deals-table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
.deals-table th { background: var(--panel-2); color: var(--muted); cursor: pointer; user-select: none; font-weight: 700; white-space: nowrap; position: sticky; top: 0; border-bottom: 2px solid var(--border-strong); }
.deals-table th:hover { color: var(--accent-2); }
.deals-table td.num, .deals-table th.num { text-align: right; }
.deals-table tbody tr:hover td { background: #fffdf6; }
.deals-table .link { color: var(--accent-2); cursor: pointer; font-weight: 700; }
.deals-table .link:hover { text-decoration: underline; }
.deals-table .overdue { color: var(--red); font-weight: 600; }
.inline { width: 100%; min-width: 96px; background: transparent; border: 1px solid transparent; padding: 5px 7px; font-weight: 500; box-shadow: none; }
.inline:hover { border-color: var(--border-strong); background: #fffdf6; }
.inline:focus { border-color: var(--accent); background: #fff; }

/* --- Dashboard ------------------------------------------------------------- */
.dashboard { display: flex; flex-direction: column; gap: 16px; }
.dash-controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.period-presets { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 9px; overflow: hidden; box-shadow: var(--shadow-sm); }
.period-presets button { background: var(--panel); border: none; border-right: 1px solid var(--border); color: var(--muted); padding: 8px 14px; cursor: pointer; font-size: 13px; font-weight: 600; }
.period-presets button:last-child { border-right: none; }
.period-presets button:hover { background: var(--bg-2); color: var(--text); }
.period-presets button.active { background: var(--accent); color: #fff; }
.period-custom { display: inline-flex; align-items: center; gap: 8px; }
.period-arrow { color: var(--muted); }
.period-note { color: var(--muted); font-size: 12px; font-style: italic; }

#dash-tip { position: fixed; z-index: 70; background: var(--text); color: #fbf7ee; border-radius: 9px; padding: 9px 12px; box-shadow: var(--shadow); pointer-events: none; min-width: 150px; }
#dash-tip .tip-stage { font-weight: 800; margin-bottom: 5px; }
#dash-tip .tip-row { display: flex; justify-content: space-between; gap: 16px; font-size: 12.5px; line-height: 1.7; }
#dash-tip .tip-row span { color: #c9bfa9; }
.funnel-row { cursor: default; border-radius: 7px; padding: 2px 4px; }
.funnel-row:hover { background: #fffdf6; }
.scorecards { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 14px; }
.scorecard { background: var(--panel); border: 1px solid var(--border); border-top: 3px solid var(--border-strong); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-sm); }
.scorecard.accent { border-top-color: var(--accent); }
.scorecard.good { border-top-color: var(--green); }
.sc-label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 700; }
.sc-value { font-size: 26px; font-weight: 800; color: var(--text); margin: 6px 0 3px; letter-spacing: -.3px; }
.scorecard.accent .sc-value { color: var(--accent-2); }
.scorecard.good .sc-value { color: var(--green); }
.sc-sub { font-size: 12px; color: var(--muted); }

.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 16px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.panel.span { grid-column: 1 / -1; }
.panel h3 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.panel-count { background: var(--accent-soft); color: var(--accent-2); border-radius: 20px; padding: 1px 9px; font-size: 12px; font-weight: 700; letter-spacing: 0; }
.panel-empty { color: var(--muted); font-size: 14px; padding: 6px 0; }

.funnel { display: flex; flex-direction: column; gap: 9px; }
.funnel-row { display: grid; grid-template-columns: 130px 1fr 150px; align-items: center; gap: 12px; }
.funnel-stage { font-weight: 600; font-size: 14px; }
.funnel-bar-wrap { background: var(--bg-2); border-radius: 7px; height: 22px; overflow: hidden; }
.funnel-bar { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 7px; min-width: 4px; }
.funnel-row.closed .funnel-bar { background: var(--border-strong); }
.funnel-meta { text-align: right; color: var(--muted); font-size: 13px; font-weight: 600; }

.d-list, .act-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.d-line { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 6px; border-bottom: 1px solid var(--border); cursor: pointer; border-radius: 7px; }
.d-line:last-child { border-bottom: none; }
.d-line:hover { background: #fffdf6; }
.d-line-main { display: flex; flex-direction: column; min-width: 0; }
.d-line-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.d-line-co { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.d-line-right { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.d-amt { font-weight: 800; color: var(--green); font-size: 13px; }
.d-date { background: var(--bg-2); padding: 2px 8px; border-radius: 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.d-date.overdue { background: #f7e0db; color: var(--red); }

.owner-table { width: 100%; border-collapse: collapse; }
.owner-table th, .owner-table td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
.owner-table th { color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.owner-table td.num, .owner-table th.num { text-align: right; }
.owner-table tbody tr:last-child td { border-bottom: none; }

.act { padding: 9px 6px; border-bottom: 1px solid var(--border); cursor: pointer; border-radius: 7px; }
.act:last-child { border-bottom: none; }
.act:hover { background: #fffdf6; }
.act-body { font-size: 14px; }
.act-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* --- Drawer / overlay ------------------------------------------------------ */
.overlay { position: fixed; inset: 0; background: rgba(50, 42, 28, 0.34); z-index: 30; }
.drawer { position: fixed; top: 0; right: 0; height: 100%; width: 440px; max-width: 94vw; background: var(--panel); border-left: 1px solid var(--border-strong); box-shadow: var(--shadow); z-index: 40; display: flex; flex-direction: column; overflow-y: auto; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.drawer-head h2 { margin: 0; font-size: 18px; }
.deal-form { padding: 18px 22px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 600; }
.field input, .field select { width: 100%; }
.field:nth-child(1) { grid-column: 1 / -1; }
.drawer-actions { display: flex; gap: 11px; padding: 4px 22px 18px; }
.drawer-actions .btn { flex: 1; justify-content: center; padding: 11px; }
.notes { padding: 18px 22px; border-top: 1px solid var(--border); }
.notes h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 0 0 12px; }
.note-add { display: flex; flex-direction: column; gap: 9px; margin-bottom: 16px; }
.note-add textarea { resize: vertical; min-height: 60px; }
.notes-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 11px; }
.notes-list li { background: #fffdf6; border: 1px solid var(--border); border-radius: 9px; padding: 11px 13px; }
.note-meta { color: var(--muted); font-size: 12px; margin-top: 6px; }
.note-empty { color: var(--muted); }

/* --- Team panel ------------------------------------------------------------ */
.team-add { display: flex; gap: 9px; padding: 18px 22px; }
.team-add input { flex: 1; }
.users-list { list-style: none; padding: 0 22px; margin: 0; display: flex; flex-direction: column; gap: 9px; }
.users-list li { display: flex; align-items: center; gap: 11px; background: #fffdf6; border: 1px solid var(--border); border-radius: 9px; padding: 11px 13px; }
.u-email { flex: 1; font-weight: 600; }

/* --- Toast ----------------------------------------------------------------- */
.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); background: var(--text); border: 1px solid var(--text); color: #fbf7ee; padding: 12px 20px; border-radius: 10px; box-shadow: var(--shadow); z-index: 60; font-weight: 600; max-width: 92vw; text-align: center; }
.toast-err { background: var(--red); border-color: var(--red); color: #fff; }

/* --- Mobile / smartphone --------------------------------------------------- */
/* Board columns swipe one-at-a-time; the drawer goes full-screen; forms single-column;
   touch targets grow. Native HTML5 drag is gone — kanban uses long-press pointer drag. */
@media (max-width: 760px) {
  body { font-size: 16px; }                 /* comfortable default text size on phones */
  .topbar { gap: 10px 12px; padding: 11px 14px; }
  .brand { font-size: 18px; width: 100%; }
  .summary { order: 3; width: 100%; gap: 12px; }
  .kpi-val { font-size: 18px; }
  .chips { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
  .chip { white-space: nowrap; }
  .topbar-actions { order: 2; width: 100%; gap: 8px; flex-wrap: wrap; }
  .search { flex: 1 1 100%; order: -2; width: auto; min-height: 44px; }
  .viewtoggle { flex: 1 1 100%; order: -1; }   /* its own row so labels never clip */
  .viewtoggle button { flex: 1; min-height: 44px; }
  .btn { min-height: 44px; flex: 1 1 auto; justify-content: center; }
  #new-deal { flex-basis: 100%; }              /* primary action gets a full-width row */
  .me { display: none; }                    /* email shown in the drawer/elsewhere; save space */

  main { padding: 14px 12px 80px; }
  .board { gap: 12px; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; }
  .column { width: 86vw; min-width: 86vw; max-height: none; scroll-snap-align: start; }
  .col-list { max-height: none; }

  .drawer { width: 100vw; max-width: 100vw; border-left: none; }
  .deal-form { grid-template-columns: 1fr; gap: 13px; }
  .field:nth-child(1) { grid-column: auto; }
  .field input, .field select, .note-add textarea { min-height: 44px; font-size: 16px; }  /* 16px stops iOS zoom-on-focus */

  .deals-table th, .deals-table td { padding: 10px 11px; }
  .inline { min-width: 80px; }

  .funnel-row { grid-template-columns: 96px 1fr; }
  .funnel-meta { grid-column: 2; text-align: left; }   /* meta drops below the bar */
  .scorecards { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
  .sc-value { font-size: 22px; }
}

/* Honor reduced-motion preferences. */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .card:hover { transform: none; }
}
