/* Luviton CRM — application styles. Brand colours are CSS variables (overridable from Settings). */
:root {
  --brand: #24496D;
  --brand-ink: #183450;
  --accent: #00B59F;
  --accent-soft: #e3f6f3;
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1d2733;
  --ink-2: #4a5868;
  --muted: #7a8797;
  --line: #e2e7ee;
  --line-2: #eef1f5;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --warn: #b7791f;
  --warn-soft: #fdf5e6;
  --ok: #1e8a5a;
  --ok-soft: #e7f6ee;
  --info: #2b6cb0;
  --info-soft: #e8f1fb;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --side-w: 236px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 var(--font); color: var(--ink); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; color: var(--brand-ink); }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; } h4 { font-size: .9rem; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: .92em; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- shell ---- */
.shell { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; }
.sidebar { background: var(--brand-ink); color: #cfdbe8; position: sticky; top: 0; height: 100vh; overflow-y: auto; padding-bottom: 2rem; }
.sidebar .brand { display: flex; align-items: center; gap: .5rem; padding: 14px 16px; background: #fff; border-bottom: 1px solid var(--line); }
.sidebar .brand img { height: 34px; width: auto; }
.nav-sec { padding: 14px 16px 4px; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: #8aa3bd; }
.nav a { display: flex; align-items: center; gap: .55rem; padding: 7px 16px; color: #dbe6f1; border-left: 3px solid transparent; }
.nav a:hover { background: rgba(255, 255, 255, .06); text-decoration: none; }
.nav a.active { background: rgba(0, 181, 159, .14); border-left-color: var(--accent); color: #fff; font-weight: 600; }
.nav .ic { width: 16px; text-align: center; opacity: .8; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: .75rem; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .search { flex: 1; max-width: 520px; }
.topbar .search input { width: 100%; }
.topbar .spacer { flex: 1; }
.btn.menu-btn { display: none; }
.bell { position: relative; padding: 6px 10px; border-radius: 6px; }
.bell .count { position: absolute; top: 0; right: 0; background: var(--danger); color: #fff; font-size: .65rem; border-radius: 10px; padding: 0 5px; }
.userchip { display: flex; flex-direction: column; line-height: 1.2; text-align: right; }
.userchip small { font-size: .72rem; }
.content { padding: 20px; max-width: 1400px; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: .75rem; margin-bottom: 14px; }
.page-head .sub { color: var(--muted); font-size: .85rem; }
.actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.breadcrumbs { font-size: .8rem; color: var(--muted); margin-bottom: 4px; }

/* ---- panels / cards ---- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.card > .hd { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: 11px 14px; border-bottom: 1px solid var(--line-2); }
.card > .hd h2, .card > .hd h3 { margin: 0; font-size: .95rem; }
.card > .bd { padding: 14px; }
.card > .bd.flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-side { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.kpi .lbl { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .val { font-size: 1.35rem; font-weight: 700; color: var(--brand-ink); font-variant-numeric: tabular-nums; }
.kpi .val.warn { color: var(--warn); } .kpi .val.danger { color: var(--danger); }
.kpi a { color: inherit; }
dl.props { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
dl.props dt { color: var(--muted); font-size: .82rem; }
dl.props dd { margin: 0; overflow-wrap: anywhere; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line-2); text-align: left; vertical-align: top; }
.tbl th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); background: #f8fafc; position: sticky; top: 0; }
.tbl tbody tr:hover { background: #fafcfe; }
.tbl td[data-label="Item"] { min-width: 200px; }
.tbl tfoot td { font-weight: 600; background: #f8fafc; }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl .sec td { background: var(--accent-soft); font-weight: 600; color: var(--brand-ink); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---- forms ---- */
label { display: block; font-size: .8rem; font-weight: 600; color: var(--ink-2); margin-bottom: 3px; }
input:not([type]), input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=datetime-local],
input[type=search], input[type=tel], input[type=file], select, textarea {
  width: 100%; padding: 7px 9px; border: 1px solid #cfd7e1; border-radius: 6px; font: inherit; background: #fff; color: var(--ink);
}
textarea { min-height: 76px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(0, 181, 159, .18); }
input[readonly] { background: #f6f8fa; }
.field { margin-bottom: 12px; }
.field .hint { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.req::after { content: " *"; color: var(--danger); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 14px; }
.form-grid .span2 { grid-column: span 2; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: .4rem; font-weight: 500; }
.check input { width: auto; }
.inline-form { display: inline; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; padding: 10px 14px; border-bottom: 1px solid var(--line-2); }
.filters .field { margin: 0; min-width: 140px; }
.filters input, .filters select { padding: 6px 8px; }

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; gap: .35rem; padding: 7px 13px; border: 1px solid #cfd7e1; border-radius: 6px; background: #fff; color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none !important; }
.btn:hover { background: #f4f7fa; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { filter: brightness(.95); background: var(--accent); }
.btn-danger { color: var(--danger); border-color: #efc2bd; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 4px 9px; font-size: .8rem; }
.btn-link { border: 0; background: none; color: var(--brand); padding: 0; font-weight: 500; cursor: pointer; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---- badges / alerts ---- */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .74rem; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.badge-success { background: var(--ok-soft); color: var(--ok); border-color: #c6ead6; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: #f3dfb8; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: #f4c7c2; }
.badge-info { background: var(--info-soft); color: var(--info); border-color: #c8dcf3; }
.badge-neutral { background: #eef1f5; color: var(--ink-2); border-color: #e0e5ec; }
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; border: 1px solid; }
.alert-success { background: var(--ok-soft); border-color: #bfe5cf; color: #14593b; }
.alert-error { background: var(--danger-soft); border-color: #f1bdb7; color: #8a2419; }
.alert-warn { background: var(--warn-soft); border-color: #f0d9a8; color: #7a5212; }
.alert-info { background: var(--info-soft); border-color: #c4d9f1; color: #1d4f85; }
.demo-flag { display: inline-block; font-size: .7rem; font-weight: 700; color: var(--warn); background: var(--warn-soft); border: 1px dashed #e6c27d; border-radius: 4px; padding: 0 6px; }

/* ---- timeline ---- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 12px 22px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2px solid var(--accent); }
.timeline .when { font-size: .75rem; color: var(--muted); }
.timeline .what { font-weight: 600; }

/* ---- kanban ---- */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: flex-start; }
.col { flex: 0 0 250px; background: #eaeef3; border-radius: var(--radius); padding: 8px; }
.col h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; display: flex; justify-content: space-between; margin: 2px 4px 8px; }
.col.drop { outline: 2px dashed var(--accent); }
.lead-card { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; box-shadow: var(--shadow); cursor: grab; }
.lead-card .t { font-weight: 600; }
.lead-card .m { font-size: .78rem; color: var(--muted); }

/* ---- tabs ---- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs a { padding: 8px 14px; border-bottom: 2px solid transparent; color: var(--ink-2); font-weight: 600; white-space: nowrap; }
.tabs a.active { border-bottom-color: var(--accent); color: var(--brand-ink); }
.tabs a:hover { text-decoration: none; background: #f4f7fa; }

/* ---- line editor ---- */
.lines-table input, .lines-table select, .lines-table textarea { padding: 5px 6px; font-size: .85rem; }
.lines-table td { padding: 4px 5px; }
.lines-table textarea { min-height: 34px; }
.lines-table .w-qty { width: 84px; } .lines-table .w-rate { width: 110px; } .lines-table .w-pct { width: 70px; }
.lines-table .w-unit { width: 64px; } .lines-table .w-code { width: 130px; } .lines-table .w-sec { width: 150px; }
.totals { margin-left: auto; max-width: 360px; }
.totals td { padding: 4px 8px; }
.totals tr.grand td { font-weight: 700; font-size: 1.05rem; border-top: 2px solid var(--brand); }

.notif-list li { padding: 10px 14px; border-bottom: 1px solid var(--line-2); list-style: none; }
.notif-list li.unread { background: #f3fbfa; }
.notif-list { margin: 0; padding: 0; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--brand-ink), var(--brand) 60%, #11615a); padding: 20px; }
.login-card { background: #fff; padding: 28px; border-radius: 12px; width: 100%; max-width: 380px; box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
.login-card img { height: 46px; display: block; margin: 0 auto 18px; }

.perm-matrix th, .perm-matrix td { text-align: center; }
.perm-matrix td:first-child, .perm-matrix th:first-child { text-align: left; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }

/* ---- responsive ---- */
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-side { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; width: var(--side-w); transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .35); }
  .btn.menu-btn { display: inline-flex; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .content { padding: 14px; }
  .userchip { display: none; }
  .form-grid .span2 { grid-column: auto; }
  .tbl.stack thead { display: none; }
  .tbl.stack tr { display: block; border-bottom: 1px solid var(--line); padding: 6px 0; }
  .tbl.stack td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: 3px 10px; text-align: right; }
  .tbl.stack td::before { content: attr(data-label); font-weight: 600; color: var(--muted); text-align: left; }
}

/* ---- print (documents and reports) ---- */
@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff; font-size: 11px; }
  .sidebar, .topbar, .no-print, .actions, .filters, .pager, .flash-area { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; }
  a { color: inherit; }
}

/* product thumbnails */
.thumb { display: inline-block; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 6px; flex: none; }
.thumb-empty { background: repeating-linear-gradient(45deg, #f4f6f9, #f4f6f9 6px, #eceff3 6px, #eceff3 12px); }

/* Luviton project-service chips (numbered, brand coloured) */
.svc-chips { display: flex; flex-wrap: wrap; gap: 10px; margin: 4px 0; }
.svc-chip { display: inline-flex; align-items: center; gap: 12px; padding: 11px 18px; border: 1px solid #d9dde3; background: #fff; color: var(--brand-ink);
  font-weight: 500; font-size: .95rem; border-radius: 2px; cursor: default; user-select: none; transition: background .15s, border-color .15s, box-shadow .15s; }
.svc-chip .n { color: var(--accent); font-weight: 700; font-size: .82rem; letter-spacing: .02em; font-variant-numeric: tabular-nums; }
.svc-chip.on { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: inset 4px 0 0 var(--accent); }
.svc-chip.on .n { color: #7fe3d6; }
label.svc-chip { cursor: pointer; margin: 0; }
label.svc-chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
label.svc-chip:hover { border-color: var(--accent); }
label.svc-chip:has(input:checked) { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: inset 4px 0 0 var(--accent); }
label.svc-chip:has(input:checked) .n { color: #7fe3d6; }
label.svc-chip:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.svc-chips.sm .svc-chip { padding: 6px 12px; font-size: .82rem; gap: 8px; }
