/* Indian Hardwoods v2 - one stylesheet for the whole app. */
:root {
  --ink: #1d2420;
  --ink-soft: #56615a;
  --paper: #f3f5f2;
  --surface: #ffffff;
  --line: #d8ddd6;
  --rosewood: #7a2e26;
  --rosewood-dark: #5e211b;
  --stock: #2f5d4a;
  --sold: #9a5a14;
  --sawn: #3f5468;
  --danger: #b42318;
  --ok-bg: #e7f1ea;
  --err-bg: #fbe9e7;
  --info-bg: #e9eef3;
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Malayalam", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 var(--font); color: var(--ink); background: var(--paper); }
a { color: var(--rosewood); }
a:hover { color: var(--rosewood-dark); }
h1 { font-size: 1.45rem; line-height: 1.25; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
.muted { color: var(--ink-soft); }
.small { font-size: .85rem; }
.d-block { display: block; }
:focus-visible { outline: 3px solid #e0a23b; outline-offset: 2px; }

/* ---------- Top bar ---------- */
.topbar { background: var(--rosewood); color: #fff; display: flex; align-items: center; gap: 1rem; padding: 0 1rem; min-height: 54px; position: sticky; top: 0; z-index: 10; }
.brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.05rem; white-space: nowrap; }
.brand:hover { color: #fff; }
.mainnav { display: flex; align-items: center; gap: .25rem; flex: 1; }
.mainnav a { color: #f6e9e6; text-decoration: none; padding: .45rem .7rem; border-radius: var(--radius); }
.mainnav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.mainnav a[aria-current="page"] { background: rgba(255,255,255,.2); color: #fff; font-weight: 600; }
.nav-user { margin-left: auto; display: flex; gap: .25rem; }
.menu-toggle { display: none; margin-left: auto; background: transparent; border: 1px solid rgba(255,255,255,.5); color: #fff; padding: .35rem .8rem; border-radius: var(--radius); font: inherit; }

@media (max-width: 860px) {
  .menu-toggle { display: block; }
  .topbar { flex-wrap: wrap; }
  .mainnav { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; padding-bottom: .5rem; }
  .mainnav.open { display: flex; }
  .nav-user { margin-left: 0; flex-direction: column; border-top: 1px solid rgba(255,255,255,.25); padding-top: .25rem; }
}

/* ---------- Page ---------- */
.page { max-width: 1280px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.page-head p { margin: .2rem 0 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.panel-quiet { background: transparent; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 1rem; }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 1.5rem; text-align: center; }

/* ---------- Messages ---------- */
.flash { padding: .7rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; border-left: 4px solid var(--stock); background: var(--ok-bg); }
.flash-error { border-color: var(--danger); background: var(--err-bg); }
.flash-info { border-color: var(--sawn); background: var(--info-bg); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; min-height: 40px; padding: .45rem .95rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--ink-soft); color: var(--ink); }
.btn-primary { background: var(--rosewood); border-color: var(--rosewood); color: #fff; }
.btn-primary:hover { background: var(--rosewood-dark); border-color: var(--rosewood-dark); color: #fff; }
.btn-danger { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--rosewood); }
.btn-small { min-height: 32px; padding: .2rem .6rem; font-size: .88rem; }
.btn-block { width: 100%; }

/* ---------- Forms ---------- */
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .9rem; }
input, select, textarea { font: inherit; font-weight: 400; color: var(--ink); background: #fff; border: 1px solid #bfc6bd; border-radius: var(--radius); padding: .5rem .6rem; min-height: 42px; width: 100%; }
textarea { min-height: 0; }
input[aria-invalid="true"] { border-color: var(--danger); background: #fffafa; }
.field-error { color: var(--danger); font-weight: 600; font-size: .85rem; }
.check-line { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; }
.check-line input { width: auto; min-height: 0; }
.hint { color: var(--ink-soft); font-size: .86rem; margin: .5rem 0 0; }

.log-form fieldset { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 1rem; margin: 0 0 1rem; display: grid; gap: .9rem; }
.log-form legend { font-weight: 700; padding: 0 .35rem; }
.log-form.narrow { max-width: 520px; display: grid; gap: .9rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .9rem; }
.form-actions { display: flex; flex-wrap: wrap; gap: .6rem; }

/* Live calculation: the figure staff look at while measuring */
.calc { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; padding: .8rem 1rem; background: #f7efe9; border-radius: var(--radius); font-size: .95rem; }
.calc strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; color: var(--rosewood-dark); }

.inline-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .75rem; }
.inline-form input, .inline-form select { width: auto; flex: 1 1 160px; }

/* ---------- Filters ---------- */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .7rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem; margin-bottom: 1rem; }
.filters .f-search { grid-column: span 2; }
.f-buttons { display: flex; gap: .5rem; align-items: flex-end; }
@media (max-width: 520px) { .filters .f-search { grid-column: auto; } }

.tabs { display: flex; flex-wrap: wrap; gap: .25rem; border-bottom: 2px solid var(--line); margin-bottom: .75rem; }
.tabs a { padding: .5rem .85rem; text-decoration: none; color: var(--ink-soft); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tabs a span { font-weight: 400; font-variant-numeric: tabular-nums; }
.tabs a[aria-current="true"] { color: var(--ink); border-color: var(--rosewood); }

.totals { display: flex; flex-wrap: wrap; gap: .4rem 1.75rem; margin: 0 0 .9rem; }
.totals strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }

/* ---------- Dashboard numbers ---------- */
.stat-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 1.25rem; }
.stat { background: var(--surface); padding: 1rem; text-decoration: none; color: var(--ink); display: flex; flex-direction: column; border-top: 4px solid var(--rosewood); }
.stat:hover { background: #fbfbfa; color: var(--ink); }
.stat-value { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-label { color: var(--ink-soft); font-size: .9rem; }
.stat-stock { border-top-color: var(--stock); }
.stat-sold { border-top-color: var(--sold); }
.stat-sawn { border-top-color: var(--sawn); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel .table-wrap { border: 0; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: .5rem .65rem; border-bottom: 1px solid #eceeea; text-align: left; vertical-align: top; white-space: nowrap; }
.table th { background: #f7f8f6; font-size: .82rem; color: var(--ink-soft); position: sticky; top: 0; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr:hover { background: #fafbf9; }
.table .check { width: 1%; }
.table .check input { width: 20px; height: 20px; min-height: 0; }
.row-muted td { color: var(--ink-soft); }

.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 700; color: #fff; vertical-align: middle; }
.badge-stock { background: var(--stock); }
.badge-sold { background: var(--sold); }
.badge-sawn { background: var(--sawn); }

.bulkbar { position: sticky; top: 54px; z-index: 5; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; background: #fff8e8; border: 1px solid #e8d3a3; border-radius: var(--radius); padding: .5rem .75rem; margin-bottom: .6rem; }
.bulkbar select, .bulkbar input { width: auto; flex: 0 1 220px; }
.bulkbar[hidden] { display: none; }

.pager { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: center; margin-top: 1rem; }

/* ---------- Log view ---------- */
.facts { margin: 0; display: grid; gap: .45rem; }
.facts div { display: grid; grid-template-columns: 9.5rem 1fr; gap: .75rem; }
.facts dt { color: var(--ink-soft); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; }
.log-photo { max-width: 100%; max-height: 420px; border-radius: var(--radius); }

/* ---------- Login ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 1rem; background: var(--rosewood); }
.login-card { background: var(--surface); width: 100%; max-width: 380px; padding: 2rem 1.75rem; border-radius: 10px; display: grid; gap: 1rem; }
.login-card form { display: grid; gap: 1rem; }
.login-logo { max-width: 220px; margin: 0 auto; display: block; }

@media print {
  .topbar, .filters, .bulkbar, .pager, .actions, .tabs, .btn, .inline-form, .check, .panel-quiet { display: none !important; }
  body { background: #fff; }
  .table th { position: static; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
input.bad { border-color: var(--danger); }

.big-figure { font-size: 1.9rem; font-weight: 700; margin: 0 0 .75rem; font-variant-numeric: tabular-nums; color: var(--rosewood-dark); }
.big-figure small { font-size: .9rem; font-weight: 400; }
.split-table input, .split-table select { min-width: 90px; }
.split-table td { white-space: nowrap; }
.badge-unpaid { background: var(--danger); }
.row-low td { background: #fff6e5; }

/* ---------- Compact action forms ---------- */
.log-form-inline { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .7rem; align-items: end; margin-top: .75rem; }
details summary { cursor: pointer; font-weight: 600; margin: .25rem 0 .5rem; }
.sale-lines select { min-width: 260px; }
.sale-lines input { min-width: 90px; }

/* ---------- Invoice ---------- */
.invoice { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1rem; max-width: 900px; }
.invoice.is-cancelled { background: repeating-linear-gradient(-45deg, #fff, #fff 24px, #fdf2f1 24px, #fdf2f1 48px); }
.inv-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1rem; border-bottom: 2px solid var(--ink); padding-bottom: 1rem; margin-bottom: 1rem; }
.inv-logo { max-height: 56px; display: block; margin-bottom: .4rem; }
.inv-company { font-size: 1.2rem; }
.inv-meta { text-align: right; }
.inv-title { font-size: 1.3rem; font-weight: 700; }
.inv-barcode svg { max-width: 100%; height: auto; }
.inv-to { margin-bottom: 1rem; }
.inv-table tfoot td { border-bottom: 0; padding-top: .25rem; padding-bottom: .25rem; }
.inv-total td { font-size: 1.1rem; font-weight: 700; border-top: 2px solid var(--ink); }
.inv-sign { display: flex; justify-content: space-between; margin-top: 3rem; }
.inv-sign div { border-top: 1px solid var(--ink); padding-top: .3rem; min-width: 180px; text-align: center; }

@media print {
  .no-print, .flash { display: none !important; }
  .page { padding: 0; max-width: none; }
  .invoice { border: 0; padding: 0; max-width: none; }
  .invoice .table th, .invoice .table td { white-space: normal; }
}
.verify-card { max-width: 460px; } .verify-card .facts div { grid-template-columns: 8rem 1fr; }
.measure-table input, .bulk-table input { min-width: 80px; max-width: 120px; }
.bulk-edit-table input, .bulk-edit-table select { min-width: 90px; }
.bulk-edit-table input[type=date] { min-width: 130px; }

@media (min-width: 861px) {
  .topbar { flex-wrap: wrap; padding-top: .25rem; padding-bottom: .25rem; }
  .mainnav { flex-wrap: wrap; row-gap: 0; }
  .mainnav a { padding: .35rem .55rem; font-size: .92rem; }
}
.subnav { display: flex; flex-wrap: wrap; gap: .5rem; margin: -.25rem 0 1rem; }
.plain { margin: 0; padding-left: 1.1rem; } .plain li { margin: .25rem 0; } .table td.wrap { white-space: normal; min-width: 200px; }
.print-only { display: none; }
@media print { .print-only { display: block; font-size: 14px; } .stat-strip { grid-template-columns: repeat(3, 1fr); } .table th { background: #eee !important; } }
