/* ===========================================================
   Jangad — design tokens
   Palette inspired by the diamond trade: ink, paper, and a
   restrained gold for the one thing that should stand out —
   document numbers and money.
   =========================================================== */
:root {
    --ink: #1B1F27;
    --ink-soft: #2B303B;
    --paper: #F7F5F1;
    --paper-raised: #FFFFFF;
    --line: #E4E0D8;
    --text: #262A31;
    --text-muted: #6B7180;
    --gold: #B8933F;
    --gold-soft: #EFE3C6;
    --success: #2F6E4E;
    --success-bg: #E7F3EC;
    --error: #A23B3B;
    --error-bg: #F8E9E9;

    --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-display: Georgia, "Times New Roman", ui-serif, serif;
    --font-mono: "SF Mono", Consolas, "Courier New", monospace;

    /* Blank space reserved at the top of each printed page for pre-printed
       letterhead paper. Adjust this one value to match your letterhead's
       printed height (e.g. logo + address band). Used ONLY by the main
       Jangad print (.copy-sheet) - do not repurpose for other documents,
       see --letterhead-space-delivery below for that. */
    --letterhead-space: 5mm;

    /* Same idea, but for the Delivery Challan / Authority Letter pages -
       kept as its own separate variable on purpose, so adjusting one
       document's top margin never accidentally changes the other's. */
    --letterhead-space-delivery: 35mm;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font-ui);
    background: var(--paper);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}
a { color: inherit; text-decoration: none; }

/* ---------- Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 232px;
    flex-shrink: 0;
    background: var(--ink);
    color: #E9E7E2;
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 24px; }
.brand-mark {
    width: 30px; height: 30px; border-radius: 6px;
    background: linear-gradient(135deg, var(--gold), #8f6f2c);
    color: var(--ink);
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-display); font-weight: bold; font-size: 16px;
}
.brand-text { font-family: var(--font-display); font-size: 19px; letter-spacing: 0.5px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-group-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
    color: #8A8F9C; margin: 16px 8px 6px;
}
.nav-link {
    padding: 9px 12px; border-radius: 6px; color: #D7D5CF; font-size: 13.5px;
}
.nav-link:hover { background: var(--ink-soft); color: #fff; }

.sidebar-footer { border-top: 1px solid #3A3F4B; padding-top: 14px; margin-top: 12px; }
.user-chip { display: flex; flex-direction: column; padding: 4px 8px 10px; }
.user-name { font-size: 13px; color: #fff; }
.user-role { font-size: 11px; color: var(--gold-soft); text-transform: uppercase; letter-spacing: 0.05em; }
.btn-link {
    background: none; border: none; color: #C7B076; font-size: 13px; cursor: pointer;
    padding: 6px 8px; width: 100%; text-align: left; border-radius: 6px;
}
.btn-link:hover { background: var(--ink-soft); }

.content { flex: 1; padding: 32px 40px; max-width: none; }

/* ---------- Page header ---------- */
.page-header {
    display: flex; justify-content: space-between; align-items: flex-end;
    margin-bottom: 24px; gap: 16px; flex-wrap: wrap;
}
.page-header h1 { font-family: var(--font-display); font-size: 26px; margin: 0 0 4px; }
.page-subtitle { color: var(--text-muted); font-size: 13.5px; }

/* ---------- Flash messages ---------- */
.flash { padding: 11px 16px; border-radius: 8px; margin-bottom: 20px; font-size: 13.5px; }
.flash-success { background: var(--success-bg); color: var(--success); }
.flash-error { background: var(--error-bg); color: var(--error); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 16px; border-radius: 7px; font-size: 13.5px; font-weight: 500;
    border: 1px solid transparent; cursor: pointer; background: none;
}
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--ink-soft); }
.btn-gold { background: var(--gold); color: #221A08; }
.btn-gold:hover { background: #a68434; }
.btn-outline { border-color: var(--line); color: var(--text); background: var(--paper-raised); }
.btn-outline:hover { border-color: var(--gold); }
.btn-danger { color: var(--error); background: var(--error-bg); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

/* ---------- Cards / tables ---------- */
.card {
    background: var(--paper-raised); border: 1px solid var(--line);
    border-radius: 10px; padding: 22px; margin-bottom: 20px;
}
.table-wrap { background: var(--paper-raised); border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; font-size: 13.5px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; background: #FAF9F6; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #FBFAF7; }
.doc-no { font-family: var(--font-mono); color: var(--gold); font-weight: 600; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.text-muted { color: var(--text-muted); }
.empty-state { padding: 48px 20px; text-align: center; color: var(--text-muted); }

/* ---------- Column filters (table lists) ---------- */
.filter-row th { padding: 8px 10px; background: #FAF9F6; border-bottom: 1px solid var(--line); }
.filter-input {
    width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;
    font-size: 12.5px; font-family: var(--font-ui); background: var(--paper-raised); color: var(--text);
}
.filter-input:focus { outline: 2px solid var(--gold); outline-offset: 1px; border-color: var(--gold); }
.filter-range { display: flex; gap: 4px; }
.filter-range .filter-input { min-width: 0; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.badge-pending { background: #FCF1DA; color: #8A5A15; }
.badge-converted { background: var(--success-bg); color: var(--success); }
.badge-returned { background: #EDEBE4; color: var(--text-muted); }
.badge-cancelled { background: var(--error-bg); color: var(--error); }
.badge-admin { background: var(--gold-soft); color: #6B4E14; }
.badge-staff { background: #E7EAF3; color: #3B4A78; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
.form-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.form-field.full { grid-column: 1 / -1; }
label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; }
input[type=text], input[type=number], input[type=date], input[type=email],
input[type=password], select, textarea {
    padding: 9px 12px; border: 1px solid var(--line); border-radius: 7px;
    font-size: 13.5px; font-family: var(--font-ui); background: var(--paper-raised); color: var(--text);
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--gold); outline-offset: 1px; border-color: var(--gold);
}
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.form-actions { margin-top: 20px; display: flex; gap: 10px; }

/* ---------- Line items table (Jangad / Invoice forms) ---------- */
.items-table th, .items-table td { padding: 8px 10px; }
.items-table input { width: 100%; }
.add-row-btn { margin-top: 10px; }
.item-entry-row { display: flex; gap: 12px; align-items: flex-end; }

/* ---------- Compact layout for the Jangad create/edit form ----------
   3 fields per row instead of 2, and smaller inputs, so the whole form
   fits on one screen without scrolling to reach the item list. */
.jangad-form .form-grid { grid-template-columns: repeat(3, 1fr); gap: 12px 16px; }
.jangad-form .form-field { gap: 4px; margin-bottom: 0; }
.jangad-form label { font-size: 11.5px; }
.jangad-form input[type=text], .jangad-form input[type=number], .jangad-form input[type=date],
.jangad-form select, .jangad-form textarea {
    padding: 6px 10px; font-size: 12.5px;
}
.jangad-form textarea { min-height: 44px; }
.jangad-form h3 { font-size: 15px; margin-top: 16px !important; }
.jangad-form .item-entry-row { gap: 8px; margin-bottom: 6px; }
.jangad-form .items-table th, .jangad-form .items-table td { padding: 6px 10px; font-size: 12.5px; }

@media (max-width: 900px) {
    .jangad-form .form-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
    .jangad-form .form-grid { grid-template-columns: 1fr; }
}

/* ---------- Login ---------- */
.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: var(--ink);
}
.login-card {
    background: var(--paper-raised); width: 360px; padding: 36px 32px; border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.login-card .brand { padding: 0 0 20px; justify-content: center; }
.login-card h1 { font-family: var(--font-display); font-size: 20px; text-align: center; margin: 0 0 4px; }
.login-sub { text-align: center; color: var(--text-muted); font-size: 12.5px; margin-bottom: 24px; }

/* ---------- Print / document view (Delivery Challan layout) ---------- */
.challan-sheet {
    background: var(--paper-raised); border: 1px solid var(--line); border-radius: 10px;
    padding: 20px 24px; max-width: 900px; font-size: 11px; color: var(--ink);
}
/* The main app's table CSS forces white-space: nowrap globally - undo that inside the
   challan print sheet so addresses and other long text actually wrap onto 2-3 lines. */
.challan-sheet th, .challan-sheet td { white-space: normal; }

/* Per request: the main Jangad print/view has no outer border, no lines
   above the 3 signature areas, and larger Terms & Condition text. Scoped to
   .copy-sheet only so the Delivery Challan/Authority Letter (which still use
   the bordered card look) are unaffected. */
.copy-sheet { border: none; border-radius: 0; }
.copy-sheet .challan-sign { border-top: none; padding-top: 16px; }
.challan-terms-text { font-size: 12px; color: var(--text-muted); white-space: pre-line; line-height: 1.5; margin-bottom: 10px; }

/* The Delivery Challan and Authority Letter each occupy a FULL page (unlike
   the 3-per-page Jangad print above), so they read at a larger, comfortable
   size rather than the compact sizing tuned for that other document. */
.delivery-sheet, .authority-letter { font-size: 13px; }

.challan-topline { display: flex; justify-content: space-between; align-items: baseline; font-weight: 700; font-size: 12px; margin-bottom: 6px; }
.challan-header {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
    margin-bottom: 8px; border: 1px solid var(--ink); padding: 8px 10px;
}
/* ---- SCREEN (visual) sizing - kept compact so it always fits the on-screen card ---- */
.challan-company { flex: 0 0 260px; font-size: 13px; line-height: 1.5; overflow-wrap: break-word; word-break: break-word; }
.challan-company-name { font-family: var(--font-display); font-size: 20px; font-weight: 700; margin-bottom: 4px; overflow-wrap: break-word; word-break: break-word; }
.challan-company-address { font-size: 13px; line-height: 1.5; overflow-wrap: break-word; word-break: break-word; }
.challan-company-phone { font-size: 13px; line-height: 1.5; }
.challan-logo { flex-shrink: 0; align-self: flex-start; text-align: center; }
.challan-logo img { max-width: 170px; max-height: 170px; object-fit: contain; }
.challan-memo-box { border: none; border-left: 1px solid var(--ink); padding-left: 10px; width: 380px; flex-shrink: 0; }
.challan-memo-row { display: grid; grid-template-columns: 62px 1fr 40px 1fr; padding: 3px 6px; border-bottom: 1px solid var(--line); font-size: 10.5px; }
.challan-memo-row:last-child { border-bottom: none; }
.challan-memo-row .ml { font-weight: 700; white-space: nowrap; }
.challan-memo-row .mv { padding-left: 8px; word-break: break-word; overflow-wrap: break-word; }
.challan-memo-row .mv-wide { grid-column: 2 / span 3; }

.challan-transport-block { border: 1px solid var(--ink); margin-bottom: 8px; }
.challan-transport-row { display: grid; border-bottom: 1px solid var(--line); font-size: 10px; }
.challan-transport-row:last-child { border-bottom: none; }
.challan-transport-row.single { grid-template-columns: 150px 1fr; }
.challan-transport-row.double { grid-template-columns: 150px 1fr 110px 1fr; }
.challan-transport-row > span { padding: 3px 6px; border-right: 1px solid var(--line); }
.challan-transport-row > span:last-child { border-right: none; }
.challan-transport-row .tl { font-weight: 700; white-space: nowrap; }

.challan-purpose { font-size: 10px; margin-bottom: 8px; }

.challan-items-table { width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 4px; table-layout: fixed; }
.challan-items-table th, .challan-items-table td { border-bottom: 1px solid var(--line); padding: 3px 6px; text-align: left; overflow-wrap: break-word; }
.challan-items-table th { border-bottom: 1px solid var(--ink); font-weight: 700; }
.challan-items-table th:nth-child(1), .challan-items-table td:nth-child(1) { width: 7%; }
.challan-items-table th:nth-child(2), .challan-items-table td:nth-child(2) { width: 35%; }
.challan-items-table th:nth-child(3), .challan-items-table td:nth-child(3) { width: 17%; }
.challan-items-table th:nth-child(4), .challan-items-table td:nth-child(4) { width: 19%; }
.challan-items-table th:nth-child(5), .challan-items-table td:nth-child(5) { width: 22%; }
.challan-items-table .sr { text-align: center; }
.challan-items-table .num { text-align: right; }
.challan-total-row td { border-top: 1px solid var(--ink); font-weight: 700; }

/* Plain bordered grid for the Shipper/Consignee header block - matches the
   old software's report output exactly: a real ruled table/grid, not a
   rounded "card" box. */
.challan-header-grid { width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 10px; }
.challan-header-grid td { border: 1px solid var(--ink); padding: 4px 8px; vertical-align: top; }
.challan-header-grid .addr-cell { line-height: 1.5; width: 45%; }

/* Delivery Challan's item table has an extra header row for CGST/SGST (or
   IGST) group labels spanning 2 sub-columns each. Column widths are set via
   an explicit <colgroup> in the template (not nth-child) because
   table-layout:fixed only reads the FIRST header row to size columns, and
   that row's cells don't map 1:1 to actual columns once colspan is involved. */
.gst-items-table { table-layout: fixed; }
.gst-items-table th, .gst-items-table td { font-size: 10px; padding: 5px 7px; }
.gst-items-table thead tr:first-child th { text-align: center; }
.gst-items-table thead tr:last-child th { text-align: right; }
.gst-items-table th { white-space: nowrap; }
.gst-items-table .num { text-align: right; white-space: nowrap; }
.gst-items-table td:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.authority-goods-table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin: 6px 0 14px; }
.authority-goods-table th, .authority-goods-table td { border: 1px solid var(--line); padding: 4px 6px; text-align: left; }
.authority-goods-table th { background: #FAF9F6; font-weight: 700; }
.authority-goods-table .sr { width: 40px; text-align: center; }
.authority-goods-table .num { text-align: right; }

.challan-grand-total {
    display: flex; justify-content: space-between; font-weight: 700; font-size: 13px;
    border-top: 2px solid var(--ink); padding-top: 6px; margin-bottom: 6px;
}
.challan-remarks { font-size: 9.5px; color: var(--text-muted); margin-bottom: 6px; }

.challan-terms-head {
    display: flex; justify-content: space-between; font-weight: 700; font-size: 9.5px;
    margin-bottom: 3px; padding-top: 6px; border-top: 1px solid var(--line);
}

.challan-sign-row { display: flex; justify-content: space-between; margin-top: 22px; font-size: 12px; font-weight: 600; }
.challan-sign { flex: 1; text-align: center; padding-top: 6px; border-top: 1px solid var(--ink); margin: 0 12px; }

/* ============================================================
   PRINT-ONLY RULES for the two document types below.
   Kept as ONE @media print block (matching the rest of the file),
   but clearly split into two halves so it's obvious which document
   any given rule belongs to:

     Part A: JANGAD PRINT (.copy-sheet)        - DO NOT MODIFY
             per explicit instruction, this document's sizing/
             position/zoom is finalized. Leave Part A alone even
             when changing the Delivery Challan in Part B.
     Part B: DELIVERY CHALLAN / AUTHORITY LETTER (.delivery-sheet,
             .authority-letter) - safe to adjust for that document.

   They share nothing but the base .challan-sheet rule right below,
   and even that is immediately re-specialized per document (zoom
   for Part A, its own padding-top for Part B) so changing one
   document's numbers should never visibly affect the other.
   ============================================================ */
@media print {
    .challan-sheet {
        padding: var(--letterhead-space) 10px 6px;
        width: 100%; max-width: none; border-radius: 0;
        display: flex; flex-direction: column;
    }

    /* ---- Part A: JANGAD PRINT (.copy-sheet) - DO NOT MODIFY ---- */
    .challan-sheet.copy-sheet {
        zoom: 0.85;
    }
    .copy-sheet .challan-company { flex-basis: 340px; font-size: 15px; }
    .copy-sheet .challan-company-name { font-size: 24px; }
    .copy-sheet .challan-company-address { font-size: 14px; }
    .copy-sheet .challan-company-phone { font-size: 14px; }
    .copy-sheet .challan-logo img { max-width: 210px; max-height: 210px; }
    .copy-sheet .challan-memo-box { width: 430px; }
    .copy-sheet .challan-memo-row { grid-template-columns: 72px 1fr 48px 1fr; font-size: 11.5px; }

    /* ---- Part B: DELIVERY CHALLAN / AUTHORITY LETTER ---- */
    .delivery-sheet, .authority-letter {
        padding-top: var(--letterhead-space-delivery);
        padding-left: 15mm; padding-right: 15mm; padding-bottom: 15mm;
    }
    .challan-sign-row { margin-top: auto; padding-top: 10mm; }
}

/* ---------- Delivery Challan ---------- */
.delivery-summary { display: flex; justify-content: space-between; gap: 16px; margin-top: 8px; font-size: 12px; }
.delivery-summary-words { flex: 1; }
.delivery-summary-totals { min-width: 260px; }
.delivery-summary-totals table { width: 100%; border-collapse: collapse; }
.delivery-summary-totals td { padding: 3px 5px; border-bottom: 1px solid var(--line); }
.delivery-summary-totals tr:last-child td { border-top: 1px solid var(--ink); border-bottom: none; font-weight: 700; }

.delivery-declaration { font-size: 11px; color: var(--text-muted); margin-top: 12px; line-height: 1.5; }

/* ---------- Authority Letter (Delivery Challan page 2) ---------- */
.authority-letter { margin-top: 14px; font-size: 11px; }
.authority-to-date { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; font-size: 13px; }
.authority-reps-table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin: 6px 0; }
.authority-reps-table th, .authority-reps-table td { border: 1px solid var(--ink); padding: 8px 10px; text-align: left; }
.authority-reps-table th { background: #FAF9F6; font-weight: 700; }
.authority-reps-table .sr { width: 50px; text-align: center; }

@media print {
    .authority-letter { page-break-before: always; padding-top: var(--letterhead-space-delivery); }
}

/* Jangad print: show one copy on screen, three labelled copies when printing - one full page each */
.print-only { display: none; }

@page { size: A4; margin: 0; }

@media print {
    .sidebar, .no-print { display: none !important; }
    .content { padding: 0; max-width: none; }
    body { background: #fff; }

    .screen-only { display: none !important; }
    .print-only { display: block !important; }

    .copy-sheet {
        max-width: none; width: 100%; border: none; border-radius: 0; background: #fff;
        padding: var(--letterhead-space) 10mm 10mm; box-sizing: border-box;
        min-height: 148mm;
        page-break-after: always;
    }
    .copy-sheet:last-child { page-break-after: auto; }
}

@media (max-width: 720px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; }
    .content { padding: 20px; }
    .form-grid { grid-template-columns: 1fr; }
}