/* Ware House MS — app shell: mobile app-like, desktop-ready */
:root {
    /* Brand: logistics blue */
    --brand: #1558a0;
    --brand-dark: #0f4278;
    --brand-tint: #e8f0f9;
    --brand-on: #dce9f7;
    --bg: #f4f6f8;
    --card: #ffffff;
    --ink: #161b22;
    --muted: #67717d;
    --border: #e1e6ec;
    --danger: #c0392b;
    /* Status colours stay semantic, independent of brand */
    --ok: #1f7a4d;
    --ok-bg: #e7f6ee;
    --radius: 14px;
    --shadow: 0 2px 12px rgba(0, 0, 0, .06);
    --appbar-h: 56px;
    --bottomnav-h: 62px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

/* ---------------- App bar ---------------- */
.app-bar {
    position: sticky; top: 0; z-index: 40;
    height: var(--appbar-h);
    background: var(--brand);
    color: #fff;
    box-shadow: var(--shadow);
    padding-top: env(safe-area-inset-top);
}
.app-bar__inner {
    height: var(--appbar-h);
    max-width: 1100px; margin: 0 auto;
    display: flex; align-items: center; gap: 12px;
    padding: 0 16px;
}
.brand { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; font-weight: 700; }
.brand__mark { font-size: 20px; }
.brand__text { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 34vw; }
.topnav { display: none; margin-left: auto; gap: 4px; }
.topnav a {
    color: var(--brand-on); text-decoration: none; font-size: 14px; font-weight: 500;
    padding: 8px 12px; border-radius: 8px;
}
.topnav a:hover { background: rgba(255, 255, 255, .15); }
/* Who is signed in — on every page, phone and desktop. The topnav is hidden on a
   phone, so the chip is what pushes itself (and log-out) to the right edge. */
.user-chip { margin-left: auto; display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-chip__avatar {
    flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%;
    background: rgba(255, 255, 255, .2); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 700;
}
.user-chip__text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; max-width: 24vw; }
.user-chip__name, .user-chip__role { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip__name { font-size: 13px; font-weight: 600; color: #fff; }
.user-chip__role { font-size: 11px; color: var(--brand-on); }
.logout { margin-left: 4px; }
.logout button {
    background: rgba(255, 255, 255, .16); color: #fff; border: 0;
    width: 38px; height: 38px; border-radius: 10px; font-size: 18px; cursor: pointer;
}

/* ---------------- Content ---------------- */
.content {
    max-width: 1100px; margin: 0 auto;
    padding: 16px 16px calc(var(--bottomnav-h) + 24px);
}
.page-head { margin: 6px 0 16px; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-head--row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--muted); margin: 2px 0 0; }
.section-title { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 24px 0 10px; }

/* ---------------- Stat grid ---------------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat__num { font-size: 28px; font-weight: 800; color: var(--brand-dark); }
.stat__label { color: var(--muted); font-size: 13px; margin-top: 2px; }
.stat--link { display: block; text-decoration: none; }
/* Work still owed — amber only while the count is non-zero. */
.stat--alert { background: #fff6e0; }
.stat--alert .stat__num { color: #8a6d00; }


/* ---------------- Tiles ---------------- */
.tile-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tile {
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 18px 16px; text-decoration: none; color: var(--ink); font-weight: 600;
    display: flex; flex-direction: column; gap: 10px;
}
.tile:active { transform: scale(.98); }
.tile__icon { font-size: 26px; }

/* ---------------- Cards ---------------- */
.card-list { display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.card__title { font-weight: 700; }
.card__meta { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---------------- Buttons ---------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    border: 0; border-radius: 10px; padding: 10px 16px; font-size: 15px; font-weight: 600;
    text-decoration: none; cursor: pointer; min-height: 44px;
}
.btn--primary { background: var(--brand); color: #fff; }
.btn--primary:active { background: var(--brand-dark); }
.btn--ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--block { width: 100%; }

/* ---------------- Tables → cards on mobile ---------------- */
.data-table-wrap { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead { display: none; }
.data-table tr { display: block; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.data-table tr:last-child { border-bottom: 0; }
.data-table td { display: flex; justify-content: space-between; gap: 16px; padding: 4px 0; font-size: 15px; }
.data-table td::before {
    content: attr(data-label); color: var(--muted); font-size: 13px; font-weight: 600;
}
.data-table td.col-actions { justify-content: flex-end; gap: 18px; padding-top: 10px; }
.data-table td.col-actions::before { content: ""; }
.link-edit { color: var(--brand-dark); text-decoration: none; font-weight: 600; }
.link-delete { color: var(--danger); text-decoration: none; font-weight: 600; }
/* Some of these are <button>s inside a form (reopen a delivery, remove a row), which
   would otherwise carry the browser's default box. Make them read as links. */
button.link-delete {
    background: none; border: 0; padding: 8px 0; min-height: 44px;
    font: inherit; font-weight: 600; cursor: pointer;
}
button.link-delete:hover { text-decoration: underline; }

/* ---------------- Forms ---------------- */
.form-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 16px; max-width: 560px; }
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field input, .field select, .field textarea,
.form-card input, .form-card select, .form-card textarea {
    width: 100%; padding: 12px 14px; font-size: 16px;
    border: 1px solid var(--border); border-radius: 10px; background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.help { color: var(--muted); font-size: 12px; }
.field-error { color: var(--danger); font-size: 13px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* Long set-up forms (firm billing identity): grouped, and two columns on desktop. */
.form-card--wide { max-width: 820px; }
.form-group { border: 0; padding: 0; margin: 0 0 6px; }
.form-group + .form-group { border-top: 1px solid var(--border); padding-top: 16px; margin-top: 18px; }
.form-group > legend {
    padding: 0; font-size: 13px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .04em; color: var(--muted); margin-bottom: 12px;
}
.field--check { display: flex; align-items: center; gap: 10px; }
.field--check input[type="checkbox"] { width: 20px; height: 20px; flex: 0 0 auto; }
.field--check > span { margin-bottom: 0; font-weight: 500; }

/* ---------------- Messages / empty / pager ---------------- */
.messages { margin-bottom: 14px; display: flex; flex-direction: column; gap: 8px; }
.alert { padding: 12px 14px; border-radius: 10px; font-size: 14px; }
.alert--error { background: #fdecea; color: var(--danger); }
.alert--warning { background: #fff6e0; color: #8a6d00; }
.alert--success { background: var(--ok-bg); color: var(--ok); }
.alert--info { background: var(--brand-tint); color: var(--brand-dark); }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty__icon { font-size: 42px; margin-bottom: 8px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 16px; color: var(--muted); }
.pager a { color: var(--brand-dark); text-decoration: none; font-weight: 600; }

/* ---------------- Bottom nav (mobile) ---------------- */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
    height: var(--bottomnav-h);
    background: var(--card);
    border-top: 1px solid var(--border);
    display: flex; align-items: stretch;
    padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600;
}
.bottom-nav a span { font-size: 20px; }
.bottom-nav a:active { color: var(--brand); }

/* ---------------- Workflow components ---------------- */
.card--link { display: block; text-decoration: none; color: var(--ink); }
.card--link:active { transform: scale(.99); }
.card__row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pill { background: var(--brand-tint); color: var(--brand-dark); font-size: 13px; font-weight: 700;
        padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.badge { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.badge--ok { background: var(--ok-bg); color: var(--ok); }
.badge--warn { background: #fff6e0; color: #8a6d00; }
.badge--void { background: #fdecea; color: #c0392b; }
.line-metrics { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 10px 0; color: var(--muted); font-size: 14px; }
.line-metrics b { color: var(--ink); }

/* Two readings of one list (by party / by note) */
.tabs { display: flex; gap: 6px; margin: 0 0 14px; border-bottom: 1px solid var(--border); }
.tab {
    padding: 10px 16px; min-height: 44px; display: flex; align-items: center;
    text-decoration: none; color: var(--muted); font-weight: 600; font-size: 15px;
    border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tab--on { color: var(--brand-dark); border-bottom-color: var(--brand); }

/* "Up one level" link, top-left of every page below the dashboard. */
.backlink {
    display: inline-flex; align-items: center; min-height: 44px;
    margin: -4px 0 4px; padding: 0 4px 0 0;
    color: var(--brand-dark); text-decoration: none; font-weight: 600; font-size: 15px;
}
.backlink:hover { text-decoration: underline; }

/* A table sitting inside a card already has the card's chrome; wide ones scroll
   inside their own box so the page body never scrolls sideways. */
.data-table-wrap--flush { box-shadow: none; border-radius: 0; overflow-x: auto; margin: 8px -16px -18px; }
.data-table-wrap--flush .data-table { min-width: 100%; }
.row--void { opacity: .55; text-decoration: line-through; }
.row--void .badge { text-decoration: none; }
.line-card { border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-bottom: 12px; background: #fafbfd; }
.line-remove { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-top: 4px; }
.line-remove input { width: auto; }
.stat-grid--3 { grid-template-columns: repeat(3, 1fr); }

/* radio pills (source toggle) */
.radio-row { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.radio-pill { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border);
    border-radius: 10px; padding: 12px 14px; flex: 1; min-width: 140px; font-size: 14px; font-weight: 600; }
.radio-pill input { width: auto; }

/* detail rows */
.detail-list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 16px; }
.detail-row { display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 12px 16px; border-bottom: 1px solid var(--border); }
.detail-row:last-child { border-bottom: 0; }
.detail-row > span { color: var(--muted); font-size: 14px; }

/* ---------------- Login ---------------- */
.login-body {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(160deg, var(--brand) 0%, var(--brand-dark) 100%); padding: 20px;
}
.login-card {
    background: #fff; border-radius: 20px; box-shadow: 0 12px 40px rgba(0, 0, 0, .2);
    padding: 32px 24px; width: 100%; max-width: 380px; text-align: center;
}
.login-logo { font-size: 46px; }
.login-title { margin: 8px 0 2px; font-size: 22px; }
.login-sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.login-card .field { text-align: left; }

/* ---------------- Desktop ---------------- */
@media (min-width: 768px) {
    .topnav { display: flex; }
    .app-bar__inner .logout { margin-left: 4px; }
    .brand__text { max-width: 30vw; }
    .user-chip { margin-left: 8px; padding-left: 12px; border-left: 1px solid rgba(255, 255, 255, .25); }
    .user-chip__text { max-width: 160px; }
    .bottom-nav { display: none; }
    .content { padding-bottom: 32px; }
    .stat-grid { grid-template-columns: repeat(4, 1fr); }
    .tile-grid { grid-template-columns: repeat(5, 1fr); }

    /* Real table on desktop */
    .data-table thead { display: table-header-group; }
    .data-table { border-collapse: collapse; }
    .data-table tr { display: table-row; padding: 0; border-bottom: 0; }
    .data-table th, .data-table td { display: table-cell; padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); }
    .data-table td { justify-content: initial; }
    .data-table td::before { content: ""; }
    .data-table thead th { background: #eef2f7; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .03em; }
    .data-table td.col-actions { text-align: right; }

    /* The 7-column dispatch table needs room; let it scroll rather than squash. */
    .data-table-wrap--flush .data-table { min-width: 720px; }

    /* Two-up fields inside a grouped set-up form */
    .form-group__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
    .form-group__grid .field--full { grid-column: 1 / -1; }
}

/* ---------------- Search / filter bar ---------------- */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.filter-bar input[type="search"],
.filter-bar select {
    flex: 1 1 160px; min-height: 44px; padding: 8px 12px;
    border: 1px solid var(--border, #cdd6d1); border-radius: 10px;
    font-size: 15px; background: #fff;
}
.filter-bar .btn { flex: 0 0 auto; }

/* Bottom nav carries 5 slots — keep labels on one line down to 320px screens. */
.bottom-nav a { min-width: 0; padding: 0 2px; }
.bottom-nav a span { line-height: 1; }
@media (max-width: 360px) {
    .bottom-nav a { font-size: 10px; }
    .bottom-nav a span { font-size: 18px; }
}

/* ---------------- Statements (godown statement, goods passbook) ---------------- */
.filter-bar input[type="date"] {
    flex: 1 1 140px; min-height: 44px; padding: 8px 12px;
    border: 1px solid var(--border, #cdd6d1); border-radius: 10px;
    font-size: 15px; background: #fff;
}
.data-table td.num { font-variant-numeric: tabular-nums; }
/* On a phone each row becomes a card of label/value pairs. A value is one flex item
   (the templates wrap it in a <span>) and may break anywhere, so a long RR number
   wraps instead of stretching every card past the screen edge. */
.data-table-wrap--scroll td > span { min-width: 0; text-align: right; overflow-wrap: anywhere; }
.row--memo td { color: var(--muted); font-style: italic; }
.row--opening td, .row--total td { font-weight: 700; background: var(--brand-tint); }
.basis-note { font-size: 13px; color: var(--muted); margin: 10px 0 18px; line-height: 1.5; }
@media (min-width: 768px) {
    .data-table-wrap--scroll { overflow-x: auto; }
    .data-table-wrap--scroll td > span { text-align: inherit; overflow-wrap: normal; }
    /* Many numeric columns: tighter cells so the billing columns stay on screen. */
    .data-table--dense th, .data-table--dense td { padding: 10px 8px; font-size: 14px; }
    .data-table--dense thead th { font-size: 11px; letter-spacing: .02em; }
    .data-table td.num { text-align: right; white-space: nowrap; }
    .data-table th.num { text-align: right; }
    .data-table--dense td:first-child { min-width: 150px; }
    .data-table--dense td:nth-child(2) { min-width: 110px; }
}
