/* ════════════════════════════════════════════════════════════════
   SOS CRM — Stylesheet
   Aesthetic: refined, professional. Deep evergreen + warm amber.
   ════════════════════════════════════════════════════════════════ */

:root {
  --ink:        #18201c;
  --ink-soft:   #50584f;
  --ink-faint:  #8a9089;
  --canvas:     #f1f2ee;
  --card:       #ffffff;
  --sidebar:    #13201b;
  --sidebar-2:  #1b2e26;
  --primary:    #0e7a57;
  --primary-d:  #0a5c41;
  --primary-l:  #e4f2ec;
  --amber:      #cf8a1e;
  --amber-l:    #fbeed3;
  --red:        #c0392b;
  --red-l:      #f8e4e1;
  --blue:       #2f6db5;
  --border:     #e3e4de;
  --border-d:   #d2d4cb;
  --shadow-sm:  0 1px 2px rgba(20,30,24,.06), 0 1px 3px rgba(20,30,24,.04);
  --shadow-md:  0 4px 14px rgba(20,30,24,.08), 0 2px 5px rgba(20,30,24,.05);
  --shadow-lg:  0 18px 50px rgba(20,30,24,.18);
  --r:          13px;
  --r-sm:       9px;
  --sans:       'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --display:    'Bricolage Grotesque', var(--sans);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--canvas);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
::selection { background: var(--primary); color: #fff; }

/* ── Boot spinner ─────────────────────────────────────────────── */
.boot { height: 100vh; display: grid; place-items: center; }
.boot-spin {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ════════════ LOGIN ════════════ */
.login {
  min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr;
}
.login-art {
  background: radial-gradient(120% 120% at 15% 10%, var(--sidebar-2) 0%, var(--sidebar) 55%);
  position: relative; overflow: hidden; color: #fff;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 54px;
}
.login-art::before {
  content: ""; position: absolute; inset: 0;
  background-image:
    radial-gradient(circle at 80% 70%, rgba(14,122,87,.55), transparent 45%),
    radial-gradient(circle at 90% 18%, rgba(207,138,30,.30), transparent 38%);
}
.login-art::after {
  content: ""; position: absolute; inset: 0; opacity: .4;
  background-image: linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px);
  background-size: 46px 46px;
}
.login-art > * { position: relative; z-index: 1; }
.login-brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 17px; }
.login-headline { font-family: var(--display); font-size: 44px; line-height: 1.08; font-weight: 600; max-width: 11ch; }
.login-headline span { color: #79e7c0; }
.login-sub { color: rgba(255,255,255,.7); margin-top: 18px; max-width: 34ch; }
.login-feats { display: flex; flex-direction: column; gap: 11px; }
.login-feat { display: flex; align-items: center; gap: 11px; color: rgba(255,255,255,.85); font-size: 13.5px; }
.login-feat .dot { width: 7px; height: 7px; border-radius: 50%; background: #79e7c0; flex: none; }

.login-form-side { display: grid; place-items: center; padding: 40px; }
.login-card { width: 100%; max-width: 370px; }
.login-card h1 { font-family: var(--display); font-size: 27px; font-weight: 600; }
.login-card .muted { color: var(--ink-soft); margin: 6px 0 30px; }

/* ════════════ APP SHELL ════════════ */
.shell { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--sidebar); color: #c9d2cd;
  display: flex; flex-direction: column; padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
}
.sb-brand {
  display: flex; align-items: center; gap: 11px; padding: 6px 10px 22px;
  color: #fff; font-weight: 700; font-size: 15.5px;
}
.sb-logo {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: linear-gradient(150deg, var(--primary), #14b083);
  display: grid; place-items: center; font-family: var(--display);
  font-weight: 700; color: #fff; font-size: 17px;
}
.sb-section { font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase;
  color: #5d6f67; padding: 16px 12px 7px; font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9.5px 12px; border-radius: 9px; color: #aab6b0;
  font-weight: 500; font-size: 13.5px; transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--sidebar-2); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item .ico { width: 18px; text-align: center; flex: none; }
.nav-item .count {
  margin-left: auto; background: rgba(255,255,255,.13); color: #fff;
  font-size: 11px; padding: 1px 7px; border-radius: 20px; font-weight: 600;
}
.sb-foot { margin-top: auto; padding: 14px 10px 4px; border-top: 1px solid #25362e; }
.sb-user { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  background: linear-gradient(150deg, var(--amber), #e2a945);
  display: grid; place-items: center; color: #3a2a05; font-weight: 700;
  font-family: var(--display); font-size: 14px;
}
.sb-user .nm { color: #fff; font-weight: 600; font-size: 13px; }
.sb-user .rl { color: #6f817a; font-size: 11px; text-transform: capitalize; }

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 64px; background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 0 28px;
  position: sticky; top: 0; z-index: 20;
}
.topbar h2 { font-family: var(--display); font-size: 19px; font-weight: 600; }
.topbar .crumb { color: var(--ink-faint); font-size: 12.5px; }
.topbar-actions { margin-left: auto; display: flex; gap: 10px; align-items: center; }

.content { padding: 26px 28px 48px; max-width: 1280px; width: 100%; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  padding: 9px 16px; border-radius: var(--r-sm); font-weight: 600; font-size: 13px;
  transition: transform .08s, box-shadow .15s, background .15s; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-d); }
.btn-ghost { background: var(--card); color: var(--ink); border: 1px solid var(--border-d); }
.btn-ghost:hover { background: #fafbf9; border-color: var(--ink-faint); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { filter: brightness(.93); }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ── Stat cards ─────────────────────────────────────────── */
.stat-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 22px;
}
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r);
  padding: 16px 17px; box-shadow: var(--shadow-sm);
  animation: rise .5s both;
}
.stat:nth-child(2){animation-delay:.05s}.stat:nth-child(3){animation-delay:.1s}
.stat:nth-child(4){animation-delay:.15s}.stat:nth-child(5){animation-delay:.2s}
@keyframes rise { from { opacity: 0; transform: translateY(9px); } }
.stat .lbl { display: flex; align-items: center; gap: 7px; color: var(--ink-soft);
  font-size: 12px; font-weight: 600; }
.stat .ico-box {
  width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center;
  font-size: 14px; background: var(--primary-l);
}
.stat .num { font-family: var(--display); font-size: 30px; font-weight: 600; margin-top: 10px;
  letter-spacing: -.01em; }
.stat .meta { font-size: 11.5px; color: var(--ink-faint); margin-top: 2px; }
.stat.amber .ico-box { background: var(--amber-l); }
.stat.amber .num { color: var(--amber); }

/* ── Card / panel ───────────────────────────────────────── */
.panel {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r);
  box-shadow: var(--shadow-sm); overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 12px; padding: 15px 18px;
  border-bottom: 1px solid var(--border);
}
.panel-head h3 { font-family: var(--display); font-size: 15.5px; font-weight: 600; }
.panel-head .sub { color: var(--ink-faint); font-size: 12px; }

/* ── Filter bar ─────────────────────────────────────────── */
.filterbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  padding: 13px 18px; border-bottom: 1px solid var(--border); background: #fafbf9; }
.search {
  display: flex; align-items: center; gap: 8px; background: var(--card);
  border: 1px solid var(--border-d); border-radius: var(--r-sm); padding: 0 11px;
  flex: 1; min-width: 200px; height: 36px;
}
.search input { border: none; outline: none; flex: 1; background: none; }
.search .ico { color: var(--ink-faint); }
select.f-select {
  height: 36px; border: 1px solid var(--border-d); border-radius: var(--r-sm);
  background: var(--card); padding: 0 30px 0 11px; font-weight: 500; outline: none;
  appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%2350584f' stroke-width='2'%3E%3Cpath d='M3 4.5L6 8l3-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
select.f-select:focus { border-color: var(--primary); }

/* ── Table ──────────────────────────────────────────────── */
.tbl-scroll { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left; font-size: 11px; letter-spacing: .04em; text-transform: uppercase;
  color: var(--ink-faint); font-weight: 700; padding: 11px 16px;
  border-bottom: 1px solid var(--border); background: #fafbf9; white-space: nowrap;
}
.tbl td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr { transition: background .12s; }
.tbl tbody tr:hover { background: #f7f9f6; }
.cust-cell { display: flex; align-items: center; gap: 11px; }
.cust-cell .av {
  width: 33px; height: 33px; border-radius: 9px; flex: none; display: grid;
  place-items: center; font-weight: 700; font-size: 12.5px; font-family: var(--display);
  background: var(--primary-l); color: var(--primary-d);
}
.cust-cell .nm { font-weight: 600; }
.cust-cell .sub { font-size: 11.5px; color: var(--ink-faint); }

/* service chips */
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px;
  border-radius: 20px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.chip.svc { background: var(--primary-l); color: var(--primary-d); }
.chip.cust { background: #eef0 ; }
.tag {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 6px;
  background: #eef0ea; color: var(--ink-soft);
}
.tag.res { background: #e7f1fb; color: var(--blue); }
.tag.biz { background: var(--amber-l); color: var(--amber); }
.tag.com { background: #efe9f7; color: #6b4ba3; }

.row-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center;
  color: var(--ink-soft); transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--primary-l); color: var(--primary-d); }
.icon-btn.del:hover { background: var(--red-l); color: var(--red); }

.reminder-pill {
  font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 20px;
  background: #eef0ea; color: var(--ink-soft);
}
.reminder-pill.soon { background: var(--amber-l); color: var(--amber); }
.reminder-pill.over { background: var(--red-l); color: var(--red); }

/* empty state */
.empty { padding: 56px 20px; text-align: center; color: var(--ink-faint); }
.empty .big { font-size: 34px; margin-bottom: 8px; }
.empty .t { font-weight: 600; color: var(--ink-soft); font-size: 15px; }

/* ── Forms ──────────────────────────────────────────────── */
.form-section { margin-bottom: 22px; }
.form-section > .fs-title {
  font-family: var(--display); font-size: 13px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; color: var(--primary-d); margin-bottom: 13px;
  display: flex; align-items: center; gap: 8px;
}
.form-section > .fs-title::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: 1fr 1fr; }
.g3 { grid-template-columns: 1fr 1fr 1fr; }
.g4 { grid-template-columns: 1fr 1fr 1fr 1fr; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.field label .req { color: var(--red); }
.field input, .field select, .field textarea {
  height: 38px; border: 1px solid var(--border-d); border-radius: var(--r-sm);
  padding: 0 11px; outline: none; background: var(--card); transition: border .15s, box-shadow .15s;
}
.field textarea { height: auto; padding: 9px 11px; resize: vertical; min-height: 64px; }
.field select { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%2350584f' stroke-width='2'%3E%3Cpath d='M3 4.5L6 8l3-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; padding-right: 30px; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-l);
}
.field .hint { font-size: 11px; color: var(--ink-faint); }
.field input[readonly] { background: #f4f5f2; color: var(--ink-soft); }
.span2 { grid-column: span 2; } .span-all { grid-column: 1 / -1; }

.notice {
  display: flex; gap: 10px; padding: 11px 13px; border-radius: var(--r-sm);
  font-size: 12.5px; background: var(--amber-l); color: #80590f;
  border: 1px solid #ecd9a8; margin-bottom: 16px;
}
.form-bar {
  display: flex; gap: 10px; justify-content: flex-end; padding: 16px 0 0;
  border-top: 1px solid var(--border); margin-top: 6px;
}

/* segmented control */
.seg { display: inline-flex; background: #eef0ea; border-radius: var(--r-sm); padding: 3px; gap: 3px; }
.seg button {
  padding: 7px 14px; border-radius: 6px; font-weight: 600; font-size: 12.5px;
  color: var(--ink-soft); transition: background .15s, color .15s;
}
.seg button.on { background: var(--card); color: var(--primary-d); box-shadow: var(--shadow-sm); }

/* ── Detail view ────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; }
.dl { display: grid; grid-template-columns: 150px 1fr; gap: 9px 16px; }
.dl dt { color: var(--ink-faint); font-size: 12.5px; font-weight: 600; }
.dl dd { font-weight: 500; }
.hist-item { display: flex; gap: 11px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.hist-item:last-child { border: none; }
.hist-dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--primary);
  margin-top: 5px; flex: none;
}
.hist-item .ha { font-weight: 600; text-transform: capitalize; }
.hist-item .hd { font-size: 12px; color: var(--ink-soft); word-break: break-word; }
.hist-item .ht { font-size: 11px; color: var(--ink-faint); }

/* ── Toast ──────────────────────────────────────────────── */
.toast-wrap { position: fixed; top: 18px; right: 18px; z-index: 200;
  display: flex; flex-direction: column; gap: 9px; pointer-events: none; }
.toast { pointer-events: auto; }
.toast {
  background: var(--ink); color: #fff; padding: 11px 16px; border-radius: var(--r-sm);
  font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 9px; animation: toastIn .25s both;
  max-width: 360px;
}
.toast.ok { background: #11633f; } .toast.err { background: #a5281b; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } }

/* ── Modal ──────────────────────────────────────────────── */
.modal-wrap {
  position: fixed; inset: 0; z-index: 150; background: rgba(20,28,22,.5);
  display: grid; place-items: center; padding: 20px; animation: fade .15s both;
}
/* Critical: the [hidden] attribute must win over display:grid above,
   otherwise this full-screen layer covers the page and blocks all clicks. */
.modal-wrap[hidden] { display: none !important; }
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--card); border-radius: var(--r); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 420px; padding: 24px; animation: rise .2s both;
}
.modal h3 { font-family: var(--display); font-size: 18px; font-weight: 600; }
.modal p { color: var(--ink-soft); margin: 8px 0 18px; }
.modal-bar { display: flex; gap: 9px; justify-content: flex-end; }

/* ── Misc ───────────────────────────────────────────────── */
.role-badge {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 8px; border-radius: 20px; background: var(--primary-l); color: var(--primary-d);
}
.role-badge.admin   { background: #2a1c3e; color: #d9c4f5; }
.role-badge.manager { background: #1c2e3e; color: #c4daf5; }
.dot-on { width: 8px; height: 8px; border-radius: 50%; background: #29a36a; display: inline-block; }
.dot-off { width: 8px; height: 8px; border-radius: 50%; background: #c2554a; display: inline-block; }
.spinner-sm {
  width: 15px; height: 15px; border-radius: 50%; border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff; animation: spin .6s linear infinite;
}
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.page-head h2 { font-family: var(--display); font-size: 22px; font-weight: 600; }
.page-head .actions { margin-left: auto; display: flex; gap: 9px; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 1080px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; }
  .login-art { display: none; }
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 80; width: 244px;
    transform: translateX(-100%); transition: transform .2s;
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: grid !important; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 70; }
}
@media (max-width: 620px) {
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .content { padding: 18px 16px 40px; }
  .topbar { padding: 0 16px; }
}
.menu-btn { display: none; width: 36px; height: 36px; border-radius: 8px;
  border: 1px solid var(--border-d); place-items: center; }

/* ── Address autocomplete ───────────────────────────────── */
.addr-wrap { position: relative; }
.addr-suggest {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 40;
  background: var(--card); border: 1px solid var(--border-d); border-radius: var(--r-sm);
  box-shadow: var(--shadow-md); margin-top: 5px; overflow: hidden;
  max-height: 256px; overflow-y: auto;
}
.addr-item {
  padding: 9px 13px; cursor: pointer; font-size: 13px;
  border-bottom: 1px solid var(--border); transition: background .1s;
}
.addr-item:last-child { border-bottom: none; }
.addr-item:hover { background: var(--primary-l); }
.addr-empty { padding: 10px 13px; color: var(--ink-faint); font-size: 12.5px; }

/* ── Sales status badge ─────────────────────────────────── */
.sbadge {
  display: inline-flex; align-items: center; font-size: 10px; font-weight: 700;
  padding: 2px 8px; border-radius: 20px; text-transform: uppercase; letter-spacing: .03em;
}
.sbadge.submitted { background: #e7f1fb; color: var(--blue); }
.sbadge.paid      { background: var(--primary-l); color: var(--primary-d); }
.sbadge.cancelled { background: var(--red-l); color: var(--red); }
