/* ============================================================
   iLedger ERP - Design System
   Professional ERP shell: dark sidebar, clean data-dense content
   ============================================================ */
:root {
  --sidebar: #0e1726;
  --sidebar-hi: #16233a;
  --primary: #0f6c5c;      /* deep teal - accounting trust */
  --primary-soft: #e6f4f1;
  --accent: #b7791f;       /* gold accent */
  --bg: #f2f5f8;
  --card: #ffffff;
  --line: #e3e8ee;
  --text: #1a2433;
  --muted: #64748b;
  --ok: #15803d; --ok-bg: #dcfce7;
  --bad: #b91c1c; --bad-bg: #fee2e2;
  --warn: #a16207; --warn-bg: #fef3c7;
  --info-bg: #e0f2fe; --info: #0369a1;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.1);
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0; font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; }
.muted { color: var(--muted); font-size: .86rem; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.small { font-size: .82rem; }

/* ---------------- Layout shell ---------------- */
body { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; flex: 0 0 250px; background: var(--sidebar); color: #cbd5e1;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px 14px; border-bottom: 1px solid #1e2c44; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px; background: linear-gradient(135deg, var(--primary), #0d9488);
  color: #fff; font-size: 20px; font-weight: 700; display: grid; place-items: center;
}
img.brand-mark-img {
  width: 38px; height: 38px; border-radius: 10px; background: #fff;
  object-fit: contain; padding: 3px; flex: 0 0 38px;
}
.auth-logo img.brand-mark-img { width: 44px; height: 44px; flex-basis: 44px; }
.brand-name { color: #fff; font-weight: 700; font-size: 1rem; letter-spacing: .3px; }
.brand-sub { font-size: .68rem; color: #7c8db0; }
.branding-preview {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 10px;
  background: var(--sidebar, #16233b); margin-top: 8px;
}
.branding-preview .brand-name { font-size: .95rem; }
.branding-preview img.brand-mark-img { border: 1px solid #2a3b58; }
.nav { padding: 10px 10px 20px; flex: 1; }
.nav-group { font-size: .66rem; text-transform: uppercase; letter-spacing: 1.2px; color: #5d7097; margin: 16px 8px 6px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: #b7c3d8; font-size: .88rem; margin-bottom: 2px;
}
.nav-link:hover { background: var(--sidebar-hi); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav-link .icon { width: 18px; height: 18px; flex: 0 0 18px; }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid #1e2c44; }
.fy-chip {
  display: inline-block; background: var(--sidebar-hi); color: #fbbf24; border: 1px solid #2a3b5c;
  padding: 4px 12px; border-radius: 999px; font-size: .78rem; font-weight: 600;
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 22px;
  display: flex; align-items: center; gap: 14px; position: sticky; top: 0; z-index: 30;
}
.topbar-company { display: flex; flex-direction: column; line-height: 1.25; flex: 1; min-width: 0; }
.topbar-company strong { font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: .86rem; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: .8rem;
}
.icon-btn {
  background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; cursor: pointer;
  color: var(--text); display: inline-flex; align-items: center;
}
.icon-btn:hover { background: var(--bg); text-decoration: none; }
.content { padding: 22px; flex: 1; max-width: 1280px; width: 100%; margin: 0 auto; }
.app-foot {
  padding: 12px 22px; border-top: 1px solid var(--line); color: var(--muted); font-size: .75rem;
  display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}

/* ---------------- Cards, KPI ---------------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .card-body { padding: 16px; }
.card .card-head {
  padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between;
  align-items: center; gap: 10px; flex-wrap: wrap;
}
.card .card-head h2 { font-size: 1rem; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .kpi-label { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .6px; }
.kpi .kpi-value { font-size: 1.35rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .kpi-sub { font-size: .76rem; margin-top: 4px; }
.kpi.teal { border-top: 3px solid var(--primary); }
.kpi.gold { border-top: 3px solid var(--accent); }
.kpi.red { border-top: 3px solid var(--bad); }
.kpi.blue { border-top: 3px solid #0369a1; }

/* ---------------- Alerts ---------------- */
.alert { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: .9rem; border: 1px solid transparent; }
.alert-success { background: var(--ok-bg); color: var(--ok); border-color: #bbe7c9; }
.alert-error   { background: var(--bad-bg); color: var(--bad); border-color: #f5c2c2; }
.alert-warn    { background: var(--warn-bg); color: var(--warn); border-color: #f1dc9b; }
.alert-info    { background: var(--info-bg); color: var(--info); border-color: #bae0f5; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; border: 1px solid transparent; cursor: pointer;
  background: var(--primary); color: #fff; padding: 8px 16px; border-radius: 9px; font-size: .88rem;
  font-weight: 600; text-decoration: none; line-height: 1.2;
}
.btn:hover { filter: brightness(1.07); text-decoration: none; }
.btn.secondary { background: #fff; color: var(--text); border-color: #cfd7e0; }
.btn.secondary:hover { background: var(--bg); }
.btn.danger { background: var(--bad); }
.btn.sm { padding: 4px 10px; font-size: .78rem; border-radius: 7px; }
.btn.gold { background: var(--accent); }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; border-radius: 0 0 var(--radius) var(--radius); }
table.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
.tbl th {
  text-align: left; padding: 9px 12px; background: #f8fafc; border-bottom: 1px solid var(--line);
  font-size: .72rem; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); white-space: nowrap;
}
.tbl td { padding: 9px 12px; border-bottom: 1px solid #eef1f5; vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:hover td { background: #fafcfe; }
.tbl .num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tfoot td { font-weight: 700; background: #f8fafc; border-top: 2px solid var(--line); }
.tbl .actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------------- Badges ---------------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .72rem; font-weight: 700; letter-spacing: .3px; }
.badge.ok   { background: var(--ok-bg); color: var(--ok); }
.badge.bad  { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.gray { background: #eef1f5; color: var(--muted); }

/* ---------------- Forms ---------------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: .78rem; font-weight: 600; color: #3b4a5f; }
.field label .req { color: var(--bad); }
.field input, .field select, .field textarea {
  border: 1px solid #cfd7e0; border-radius: 8px; padding: 8px 10px; font-size: .9rem; font-family: inherit;
  background: #fff; color: var(--text); width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid rgba(15,108,92,.25); border-color: var(--primary);
}
.field .hint { font-size: .72rem; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; font-size: .88rem; }
.check input { width: 16px; height: 16px; }
.form-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

/* ---------------- Line items editor ---------------- */
.lines-table th { font-size: .68rem; }
.lines-table input, .lines-table select {
  width: 100%; min-width: 64px; border: 1px solid #d7dde6; border-radius: 6px; padding: 5px 7px; font-size: .84rem;
}
.lines-table td { padding: 5px 6px; }
.line-del { background: none; border: none; color: var(--bad); cursor: pointer; font-size: 1rem; padding: 4px; }
.totals-bar {
  display: flex; justify-content: flex-end; gap: 0; margin-top: 12px; border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden; flex-wrap: wrap;
}
.totals-bar .tcell { padding: 9px 18px; border-left: 1px solid var(--line); min-width: 130px; }
.totals-bar .tcell:first-child { border-left: 0; }
.totals-bar .tlabel { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.totals-bar .tvalue { font-weight: 700; font-variant-numeric: tabular-nums; font-size: .95rem; }
.totals-bar .grand { background: var(--primary); color: #fff; }
.totals-bar .grand .tlabel { color: #c9ebe4; }

/* ---------------- Tabs / filters ---------------- */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a {
  padding: 8px 16px; font-size: .88rem; font-weight: 600; color: var(--muted); border-radius: 8px 8px 0 0;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.tabs a:hover { color: var(--text); text-decoration: none; background: #f1f5f9; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); background: var(--primary-soft); }
.filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.filters .field { min-width: 140px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form select, .inline-form input { border: 1px solid #cfd7e0; border-radius: 8px; padding: 7px 10px; font-size: .86rem; }

/* ---------------- Ledger / voucher ---------------- */
.voucher { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 12px; overflow: hidden; }
.voucher .v-head { background: #f8fafc; padding: 9px 14px; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: .85rem; }
.voucher table { font-size: .85rem; }
.dr { color: var(--bad); font-weight: 600; }
.cr { color: var(--ok); font-weight: 600; }
.tot-dr { border-top: 2px solid var(--line); font-weight: 700; background: #fbfcfe; }

/* ---------------- Utility ---------------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.hide-sm { display: inline; }
.mobile-only { display: none; }
.progress { height: 7px; border-radius: 99px; background: #e8edf3; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); }
.hsn-note { font-size: .78rem; color: var(--muted); margin-top: 8px; }

/* ---------------- Login ---------------- */
body.auth-body { display: grid; place-items: center; min-height: 100vh; background: linear-gradient(140deg, #0e1726 0%, #14324a 55%, #0f6c5c 130%); }
.auth-card { width: 400px; max-width: calc(100vw - 32px); background: #fff; border-radius: 16px; padding: 30px; box-shadow: 0 18px 50px rgba(0,0,0,.35); }
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.auth-logo .brand-mark { width: 44px; height: 44px; font-size: 23px; }
.auth-title { font-size: 1.25rem; font-weight: 700; }
.auth-sub { color: var(--muted); font-size: .85rem; margin-bottom: 18px; }
.demo-creds { background: #f8fafc; border: 1px dashed #cbd5e1; border-radius: 10px; padding: 10px 12px; font-size: .8rem; color: var(--muted); margin-top: 16px; }
.demo-creds code { background: #eef1f5; padding: 1px 6px; border-radius: 5px; color: var(--text); }

/* ---------------- Responsive ---------------- */
@media (max-width: 920px) {
  .grid-2, .grid-3-2 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .sidebar {
    position: fixed; left: -260px; transition: left .22s ease; z-index: 100; height: 100dvh;
  }
  .sidebar.open { left: 0; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .mobile-only { display: inline-flex; }
  .hide-sm { display: none; }
  .content { padding: 14px; }
  html { font-size: 14px; }
}

/* ---- v1.2 multi-company ---- */
.badge.gold { background: #fdf3d7; color: #92650a; }
.inline-details { display: inline-block; position: relative; }
.inline-details summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; }
.inline-details summary::-webkit-details-marker { display: none; }
.inline-details[open] { display: inline-flex; gap: 6px; align-items: center; }
.topbar-company select { max-width: 260px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; font-weight: 600; }

/* ---- v1.4 announcements: rich content + composer ---- */
.ann-board-head {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  margin-bottom: 10px; flex-wrap: wrap;
}
.ann-board-title { display: flex; align-items: center; gap: 8px; color: var(--text); }
.ann-board-title svg { color: var(--primary); }
.ann-board-title h2 { font-size: 1.02rem; }

.ann-card {
  background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--primary);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 12px;
}
.ann-card .ann-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.ann-card .ann-title-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ann-card .ann-title { font-size: .98rem; }
.ann-card .ann-body { margin: 8px 0; font-size: .92rem; line-height: 1.55; }
.ann-card .ann-text { color: var(--text); }
.ann-card .ann-caption { margin-top: 8px; color: #3b4a5f; }
.ann-card .ann-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ann-card .ann-read-form { display: inline-flex; margin-left: 4px; }

.ann-media { margin: 0; }
.ann-media img {
  width: 100%; max-height: 380px; object-fit: cover; border-radius: 10px;
  border: 1px solid var(--line); display: block; background: #f1f5f9;
}
.ann-split { display: grid; grid-template-columns: minmax(180px, 300px) 1fr; gap: 14px; align-items: start; }
.ann-split .ann-media img { max-height: 220px; }
.ann-video {
  position: relative; padding-top: 56.25%; border-radius: 10px; overflow: hidden;
  background: #0b1220; border: 1px solid var(--line);
}
.ann-video iframe, .ann-video video {
  position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block;
}
.ann-video video { position: static; width: 100%; height: auto; max-height: 420px; background: #000; }

/* Composer */
.ann-composer { overflow: hidden; }
.ann-composer-head {
  display: flex; gap: 12px; align-items: center; padding: 16px 18px;
  background: linear-gradient(120deg, var(--primary-soft), #f0f7ff 70%, #fff);
  border-bottom: 1px solid var(--line);
}
.ann-composer-icon {
  width: 42px; height: 42px; border-radius: 11px; flex: 0 0 42px;
  background: var(--primary); color: #fff; display: grid; place-items: center;
  box-shadow: 0 4px 10px rgba(15,108,92,.28);
}
.ann-composer-grid {
  display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(260px, 1fr);
  gap: 20px; padding: 18px;
}
.ann-composer-form { display: flex; flex-direction: column; gap: 13px; }
.ann-composer-form .field { display: flex; flex-direction: column; gap: 5px; margin: 0; }
.ann-composer-form .field > label { font-size: .78rem; font-weight: 600; color: #3b4a5f; }
.ann-composer-form .field .req { color: var(--bad); }
.ann-composer-form .hint { font-size: .72rem; color: var(--muted); }

.type-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.type-card {
  border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 6px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  cursor: pointer; font-size: .74rem; font-weight: 600; color: var(--muted);
  background: #fff; transition: border-color .12s, background .12s, color .12s;
  text-align: center; user-select: none;
}
.type-card input { position: absolute; opacity: 0; pointer-events: none; }
.type-card:hover { border-color: #b9c7d6; color: var(--text); }
.type-card.selected {
  border-color: var(--primary); color: var(--primary); background: var(--primary-soft);
  box-shadow: 0 0 0 3px rgba(15,108,92,.08);
}

.seg { display: inline-flex; border: 1.5px solid var(--line); border-radius: 9px; overflow: hidden; width: fit-content; }
.seg-item { position: relative; }
.seg-item input { position: absolute; opacity: 0; pointer-events: none; }
.seg-item span {
  display: inline-block; padding: 7px 14px; font-size: .8rem; font-weight: 600;
  color: var(--muted); cursor: pointer; user-select: none;
}
.seg-item + .seg-item { border-left: 1.5px solid var(--line); }
.seg-item.selected { background: var(--primary); color: #fff; }
.seg-item.selected span { color: #fff; }

.style-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.spill {
  position: relative; cursor: pointer; user-select: none; font-size: .8rem; font-weight: 600;
  border-radius: 999px; padding: 7px 16px; border: 1.5px solid var(--line); color: var(--muted); background: #fff;
}
.spill input { position: absolute; opacity: 0; pointer-events: none; }
.spill-info.selected    { background: #e0f2fe; border-color: #7dd3fc; color: #0369a1; }
.spill-success.selected { background: var(--ok-bg); border-color: #86efac; color: var(--ok); }
.spill-warning.selected { background: var(--warn-bg); border-color: #fcd34d; color: var(--warn); }

.ann-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 2px; }
.ann-publish { padding: 10px 20px; font-size: .92rem; }

.ann-preview-side { min-width: 0; }
.ann-preview-label {
  text-transform: uppercase; letter-spacing: .6px; font-size: .68rem; font-weight: 700; margin-bottom: 8px;
}
.ann-preview { position: sticky; top: 66px; }
.ann-preview .ann-card { margin-bottom: 0; }
.ann-preview .ph { color: #9aa7b8; font-style: italic; }

@media (max-width: 980px) {
  .ann-composer-grid { grid-template-columns: 1fr; }
  .ann-preview { position: static; }
  .ann-split { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .type-cards { grid-template-columns: repeat(2, 1fr); }
}

/* hidden attribute must always win over display rules (composer panels) */
[hidden] { display: none !important; }

/* keep scrollIntoView targets clear of the sticky topbar (74px tall) */
button, .btn, a, .card, .ann-card { scroll-margin-top: 74px; }
