:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --ink: #241f1a;
  --ink-soft: #6b6259;
  --ink-faint: #9a9086;
  --line: #e7e0d6;
  --line-strong: #d8cfc2;
  --accent: #8c4a3b;      /* terracotta */
  --accent-soft: #b9705f;
  --accent-wash: #f3e7e2;
  --gold: #a98544;
  --good: #4a7c59;
  --warn: #b3873a;
  --bad: #a4453a;
  --shadow: 0 1px 2px rgba(36,31,26,.05), 0 8px 28px rgba(36,31,26,.08);
  --radius: 12px;
  --radius-sm: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--ink);
  -webkit-font-smoothing: antialiased; font-size: 14.5px; line-height: 1.5;
}
h1,h2,h3,h4 { font-family: 'Cormorant Garamond', Georgia, serif; font-weight: 600; letter-spacing: .2px; margin: 0; color: var(--ink); }
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea {
  font-family: inherit; font-size: 14px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 9px 11px; width: 100%; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent-soft); box-shadow: 0 0 0 3px var(--accent-wash); }
label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-soft); margin: 0 0 5px; text-transform: uppercase; letter-spacing: .5px; }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent; border-radius: var(--radius-sm); padding: 9px 16px; font-size: 13.5px;
  font-weight: 600; background: var(--surface); color: var(--ink); transition: all .15s; white-space: nowrap; }
.btn:hover { border-color: var(--line-strong); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #7a3f32; border-color: transparent; }
.btn-ghost { background: transparent; border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--bad); border-color: transparent; background: transparent; }
.btn-danger:hover { background: #f8ebe9; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- auth screens ---------- */
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #fbf9f5, var(--bg)); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow); padding: 38px 34px; }
.brand { text-align: center; margin-bottom: 26px; }
.brand .mark { font-family: 'Cormorant Garamond', serif; font-size: 30px; font-weight: 700; letter-spacing: 1px; }
.brand .sub { font-size: 11px; letter-spacing: 3px; text-transform: uppercase; color: var(--ink-faint); margin-top: 4px; }
.auth-title { font-size: 24px; text-align: center; margin-bottom: 4px; }
.auth-note { text-align: center; color: var(--ink-soft); font-size: 13px; margin: 0 0 22px; }
.err { background: #f8ebe9; color: var(--bad); border: 1px solid #eccfca; padding: 9px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }

/* ---------- app shell ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { background: #2a2420; color: #e8e1d7; padding: 22px 16px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar .logo { font-family: 'Cormorant Garamond', serif; font-size: 23px; font-weight: 700; color: #fff; letter-spacing: .5px; padding: 4px 10px 2px; }
.sidebar .logo small { display: block; font-family: 'Inter'; font-size: 9.5px; letter-spacing: 2.5px; color: #a99e90; text-transform: uppercase; margin-top: 2px; }
.nav { margin-top: 26px; display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 8px; color: #cabfb0; font-weight: 500; font-size: 13.5px; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--accent); color: #fff; }
.nav a .ic { width: 17px; text-align: center; opacity: .9; }
.sidebar .spacer { flex: 1; }
.who { border-top: 1px solid rgba(255,255,255,.1); padding-top: 14px; font-size: 12.5px; color: #cabfb0; }
.who .nm { color: #fff; font-weight: 600; }
.who a { color: #a99e90; font-size: 12px; }

.main { padding: 30px 38px 60px; max-width: 1160px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 33px; line-height: 1.1; }
.page-head .sub { color: var(--ink-soft); font-size: 13.5px; margin-top: 3px; }

/* cards / stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px,1fr)); gap: 14px; margin-bottom: 26px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .k { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--ink-faint); font-weight: 600; }
.stat .v { font-family: 'Cormorant Garamond', serif; font-size: 32px; font-weight: 700; margin-top: 4px; line-height: 1; }
.stat .v small { font-size: 15px; color: var(--ink-soft); font-family: 'Inter'; font-weight: 500; }
.stat.accent .v { color: var(--accent); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 22px; overflow: hidden; }
.panel-head { padding: 15px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.panel-head h3 { font-size: 20px; }
.panel-body { padding: 6px 8px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
@media (max-width: 900px){ .two-col { grid-template-columns: 1fr; } .shell { grid-template-columns: 1fr; } .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; } .nav { flex-direction: row; margin-top: 0; flex-wrap: wrap; } .sidebar .spacer{ display:none; } .who{ border:0; padding-top:0; } }

/* toolbar */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .search { flex: 1; min-width: 200px; position: relative; }
.toolbar .search input { padding-left: 34px; }
.toolbar .search .mag { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-faint); }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 11px; border-radius: 6px; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.06); }

/* table */
table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .7px; color: var(--ink-faint);
  font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); }
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 13.5px; vertical-align: middle; }
tbody tr { cursor: pointer; transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
.cname { font-weight: 600; }
.cmail { color: var(--ink-soft); font-size: 12.5px; }
.muted { color: var(--ink-faint); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* badges / pills */
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 20px; letter-spacing: .3px; }
.pill.vip { background: #f6edd6; color: #8a6a1f; }
.pill.good { background: #e7f0e9; color: var(--good); }
.pill.warn { background: #f7eeda; color: var(--warn); }
.pill.bad { background: #f8e7e4; color: var(--bad); }
.pill.gray { background: #efeae2; color: var(--ink-soft); }
.pill.email { background: #e6edf5; color: #3a5a86; }
.pill.text { background: #e9f0e6; color: #4a7040; }
.pill.call { background: #f0eaf5; color: #6a4a86; }
.pill.visit { background: #f5ece0; color: #8a5a20; }
.pill.note { background: #efeae2; color: var(--ink-soft); }

.empty { text-align: center; color: var(--ink-faint); padding: 40px 20px; font-size: 14px; }
.empty .big { font-family: 'Cormorant Garamond', serif; font-size: 22px; color: var(--ink-soft); margin-bottom: 4px; }

.pager { display: flex; align-items: center; justify-content: space-between; padding: 12px 6px 0; color: var(--ink-soft); font-size: 13px; }

/* ---------- modal / drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(36,31,26,.42); backdrop-filter: blur(2px); z-index: 40; display: flex; justify-content: flex-end; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } }
.drawer { width: min(620px, 96vw); background: var(--bg); height: 100%; overflow-y: auto; box-shadow: -10px 0 40px rgba(0,0,0,.2); animation: slide .2s ease; }
@keyframes slide { from { transform: translateX(30px); opacity: .6; } }
.drawer-head { position: sticky; top: 0; background: var(--bg); border-bottom: 1px solid var(--line); padding: 18px 24px; display: flex; align-items: flex-start; justify-content: space-between; z-index: 2; }
.drawer-body { padding: 20px 24px 60px; }
.x { background: transparent; border: 0; font-size: 22px; color: var(--ink-soft); line-height: 1; padding: 2px 6px; border-radius: 6px; }
.x:hover { background: var(--line); }

.modal-center { position: fixed; inset: 0; background: rgba(36,31,26,.42); backdrop-filter: blur(2px); z-index: 50; display: grid; place-items: center; padding: 20px; animation: fade .15s; }
.modal-card { width: min(520px, 96vw); max-height: 92vh; overflow-y: auto; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); }
.modal-card .mc-head { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-card .mc-body { padding: 20px 22px; }
.modal-card .mc-foot { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

/* detail sections */
.detail-name { font-size: 30px; line-height: 1.05; }
.detail-meta { color: var(--ink-soft); font-size: 13px; margin-top: 4px; display: flex; gap: 14px; flex-wrap: wrap; }
.section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-top: 16px; overflow: hidden; }
.section h4 { font-size: 17px; padding: 13px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.section .sbody { padding: 14px 18px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 14px; font-size: 13.5px; }
.kv dt { color: var(--ink-faint); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; padding-top: 1px; }
.kv dd { margin: 0; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.tl-head { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.tl-when { color: var(--ink-faint); font-size: 12px; margin-left: auto; }
.tl-sub { font-weight: 600; font-size: 13.5px; }
.tl-body { color: var(--ink-soft); font-size: 13px; white-space: pre-wrap; }

.tx-row { display: flex; justify-content: space-between; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); }
.tx-row:last-child { border-bottom: 0; }
.tx-amount { font-family: 'Cormorant Garamond', serif; font-size: 19px; font-weight: 700; }

.mini-form { background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: 10px; padding: 14px; margin-top: 12px; }
.inline-actions { display: flex; gap: 8px; margin-top: 10px; }
.tag { display:inline-block; background: var(--accent-wash); color: var(--accent); font-size: 11.5px; font-weight:600; padding: 3px 9px; border-radius: 6px; margin: 0 5px 5px 0; }

/* rich email editor */
.rte { border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); }
.rte-bar { display: flex; gap: 2px; flex-wrap: wrap; padding: 6px 8px; border-bottom: 1px solid var(--line); background: var(--surface-2); border-radius: 8px 8px 0 0; }
.rte-bar button { border: 0; background: transparent; border-radius: 6px; padding: 4px 9px; font-size: 13px; color: var(--ink); min-width: 30px; }
.rte-bar button:hover { background: var(--line); }
.rte-bar .sep { width: 1px; background: var(--line-strong); margin: 3px 4px; }
.rte-ed { min-height: 140px; max-height: 340px; overflow-y: auto; padding: 12px 14px; outline: none; font-size: 14px; line-height: 1.5; }
.rte-ed:empty:before { content: attr(data-ph); color: var(--ink-faint); }
.rte-ed img { max-width: 100%; border-radius: 6px; cursor: grab; }
.rte-ed img.sel { outline: 3px solid var(--accent-soft); outline-offset: 2px; }
.rte-imgbar { display: flex; gap: 4px; align-items: center; padding: 6px 10px; border-top: 1px dashed var(--line-strong); background: var(--accent-wash); font-size: 12px; border-radius: 0 0 8px 8px; }
.rte-imgbar button { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 6px; padding: 3px 9px; font-size: 12px; }
.rte-imgbar button:hover { border-color: var(--accent-soft); }
.rte-imgbar .lbl { color: #6d3a2f; font-weight: 600; margin-right: 2px; }

/* conversation thread */
.chat { display: flex; flex-direction: column; padding: 6px 0; max-height: 420px; overflow-y: auto; }
.msg { max-width: 78%; padding: 9px 13px; border-radius: 14px; margin: 5px 0; font-size: 13.5px; white-space: pre-wrap; line-height: 1.45; }
.msg.out { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.in { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg .msub { font-weight: 700; margin-bottom: 2px; }
.msg .mmeta { font-size: 10.5px; opacity: .75; margin-top: 4px; }
.msg.out .mmeta { color: #f3e0da; }
.sys-chip { align-self: center; margin: 8px 0; font-size: 11.5px; color: var(--ink-faint); background: var(--surface-2); border: 1px solid var(--line); border-radius: 20px; padding: 3px 12px; }
.chat-composer { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 6px; }
.chat-composer textarea { resize: vertical; }

/* toast */
#toast-root { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #2a2420; color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 13.5px; box-shadow: var(--shadow); animation: fade .15s; }
.toast.bad { background: var(--bad); }
.toast.good { background: var(--good); }

.hint { font-size: 12.5px; color: var(--ink-soft); margin-top: 6px; }
.callout { background: var(--accent-wash); border: 1px solid #e7cfc8; border-radius: 10px; padding: 12px 14px; font-size: 13px; color: #6d3a2f; margin-bottom: 16px; }
.spinner { display:inline-block; width:16px; height:16px; border:2px solid var(--line-strong); border-top-color: var(--accent); border-radius:50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-full { display:grid; place-items:center; min-height: 60vh; }
