:root {
  --bg: #f2f4f7;
  --panel: #fff;
  --border: #d8dde4;
  --accent: #f7c845;
  --text: #1f2d3d;
  --muted: #6b778c;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", Arial, sans-serif; background: var(--bg); color: var(--text); }
.layout { display: grid; grid-template-columns: 240px 1fr; height: 100vh; }
.sidebar { background: #fef8e7; border-right: 1px solid var(--border); padding: 16px; }
.logo { font-weight: 700; margin-bottom: 16px; }
.menu { list-style: none; padding: 0; margin: 0; }
.menu li { margin: 4px 0; }
.menu button { width: 100%; text-align: left; padding: 8px 10px; border: 1px solid transparent; background: transparent; border-radius: 6px; cursor: pointer; }
.menu button.active { background: var(--accent); border-color: #e0b52e; }
.content { padding: 16px 20px; overflow: auto; }
h2 { margin-top: 0; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; margin-bottom: 16px; }
.card-header { display:flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.card-header .title h2, .card-header .title h3 { margin: 0; }
.card-header .title .muted { margin-top: 4px; }
.card-header .actions { display:flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.card-header + .space-top { margin-top: 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row .compact { flex: 0 0 auto; }
.row .compact input, .row .compact select { width: 160px; }
.row .compact input[type="number"] { width: 130px; }
.doc-head {
  display: grid;
  grid-auto-flow: row;
  gap: 12px;
  align-items: end;
}
.doc-head input,
.doc-head select,
.doc-head textarea {
  width: 100%;
}
.doc-head-receipt {
  /* One-line layout on desktop; supplier/warehouse expand to fill remaining space */
  grid-template-columns:
    170px
    minmax(240px, 1.2fr)
    minmax(240px, 1.2fr)
    minmax(220px, 1fr)
    160px
    160px;
}
.doc-head-writeoff {
  /* One-line layout on desktop; warehouse/from/to expand to fill remaining space */
  grid-template-columns:
    170px
    160px
    170px
    minmax(220px, 1fr)
    minmax(240px, 1fr)
    minmax(260px, 1.2fr)
    minmax(280px, 1.6fr)
    minmax(260px, 1.2fr);
}
@media (max-width: 1100px) {
  .doc-head-receipt,
  .doc-head-writeoff {
    grid-template-columns: repeat(2, minmax(260px, 1fr));
  }
}
@media (max-width: 640px) {
  .doc-head-receipt,
  .doc-head-writeoff {
    grid-template-columns: 1fr;
  }
}
.toolbar { align-items: flex-end; }
.toolbar .grow { flex: 1; min-width: 360px; }
.pager-bottom { display: flex; justify-content: flex-end; gap: 8px; align-items: center; margin-top: 12px; padding-bottom: 10px; }
.pager-bottom .muted { font-size: 12px; }
.row.toolbar + table { margin-top: 14px; }
.row.space-top + table { margin-top: 14px; }
.card-header + table { margin-top: 14px; }

.form-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 10px; }
.field { grid-column: span 4; }
.field.wide { grid-column: span 6; }
.field.full { grid-column: 1 / -1; }
.field.compact { grid-column: span 2; }
.field input, .field select, .field textarea { width: 100%; }
.field.compact input, .field.compact select { max-width: 160px; }
.field.compact input[type="number"] { max-width: 130px; }
.modal-actions { display:flex; justify-content:flex-end; gap: 8px; margin-top: 12px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
label { font-size: 12px; color: var(--muted); display: block; }
input, select, textarea, button { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
button { background: #fff; font-weight: 600; }
button.primary { background: var(--accent); border-color: #e0b52e; cursor: pointer; }
button.danger { background: #fee2e2; border-color: #fecaca; color: #7f1d1d; }
button:disabled { opacity: 0.6; cursor: not-allowed; }
button.icon-btn { padding: 6px 8px; border-radius: 8px; line-height: 1; }
button.icon-btn i { pointer-events: none; }
button.icon-btn:hover { background: #f7f9fc; }
button.icon-btn:focus { outline: 2px solid rgba(31,45,61,0.15); outline-offset: 1px; }
button.icon-btn.danger:hover { background: #fecaca; }
/* allow icons to be tinted in table cells */
i.danger { color: #b91c1c; }

.icon-pill { display:inline-flex; align-items:center; justify-content:center; width: 24px; height: 24px; border:1px solid var(--border); border-radius: 8px; background:#fff; vertical-align: middle; }
.icon-pill.danger { border-color:#fecaca; background:#fff1f2; }
.meta-dl {
  display: grid;
  grid-template-columns: repeat(6, minmax(180px, 1fr));
  gap: 8px 14px;
  margin: 0;
  padding: 0;
}
.meta-dl .meta {
  min-width: 0;
}
.meta-dl dt {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}
.meta-dl dd {
  margin: 2px 0 0 0;
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.meta-dl dd .icon-pill { margin-right: 6px; }
@media (max-width: 1200px) {
  .meta-dl { grid-template-columns: repeat(4, minmax(180px, 1fr)); }
}
@media (max-width: 900px) {
  .meta-dl { grid-template-columns: repeat(3, minmax(180px, 1fr)); }
}
@media (max-width: 640px) {
  .meta-dl { grid-template-columns: repeat(2, minmax(160px, 1fr)); }
}
@media (max-width: 420px) {
  .meta-dl { grid-template-columns: 1fr; }
}
.legend { display:flex; gap: 12px; align-items:center; flex-wrap: wrap; }
.legend-dot { width:10px; height:10px; border-radius: 999px; display:inline-block; }
.legend-in { background:#2563eb; }
.legend-out { background:#b91c1c; }
pre { background: #f7f9fc; border: 1px solid var(--border); border-radius: 6px; padding: 10px; overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 800; background: #f8fafc; position: sticky; top: 0; z-index: 1; }
tbody tr:nth-child(even) { background: #fbfcfe; }
tbody tr:hover { background: #f5f9ff; }
.muted { color: var(--muted); font-size: 12px; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.35); display:none; z-index: 50; }
.modal { position: fixed; top: 5vh; left: 50%; transform: translateX(-50%); width: min(1320px, 96vw); height: 90vh; max-height: 90vh; overflow:auto; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; display:none; z-index: 60; }
.modal#receipt-detail-modal, .modal#writeoff-detail-modal { z-index: 80; }
.modal-header { display:flex; justify-content: space-between; align-items:center; gap: 8px; border-bottom:1px solid var(--border); padding-bottom:8px; margin-bottom:12px; }
.modal-title { font-weight: 700; }
.space-top { margin-top: 8px; }
.section-title { font-size: 12px; color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; }
.pagination { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.pill { display:inline-block; padding:2px 6px; border-radius:4px; background:#eef2f7; font-size:12px; }
.suggest-btn { width:100%; text-align:left; padding:8px 10px; border:0; background:#fff; cursor:pointer; }
.suggest-btn:hover { background:#f7f9fc; }
.clickable { cursor: pointer; }
tr.clickable:hover { background: #f7f9fc; }
button, a { cursor: pointer; }

/* admin audit: keep selected item hint compact (avoid breaking toolbar layout) */
#admin-audit-card .audit-selected {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  line-height: 14px;
  height: 14px;
}

/* Auth gate (login before entering the app) */
.auth-gate { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 18px; background: radial-gradient(1200px 600px at 20% 10%, rgba(247,200,69,0.35), transparent), radial-gradient(1000px 600px at 80% 30%, rgba(37,99,235,0.18), transparent), var(--bg); z-index: 200; }
.auth-card { width: min(520px, 96vw); background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; box-shadow: 0 12px 32px rgba(0,0,0,0.08); }
.auth-title { font-weight: 900; font-size: 18px; }

/* nested overlay inside item detail modal */
.itd-doc-overlay { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.40); padding: 12px; border-radius: 10px; z-index: 10; }
.itd-doc-panel { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px; max-height: calc(92vh - 90px); overflow: auto; }

/* dashboard */
.dash-grid { display:grid; grid-template-columns: repeat(12, 1fr); gap: 12px; }
.dash-stat { grid-column: span 4; background:#fbfcfe; border:1px solid var(--border); border-radius:10px; padding: 12px; }
.dash-panel { grid-column: span 6; background:#fff; border:1px solid var(--border); border-radius:10px; padding: 12px; }
.dash-big { font-size: 28px; font-weight: 800; margin-top: 6px; }


