/* ============ Tokens ============ */
:root {
    /* Flagship Media brand colours (sampled from the logo) */
    --brand-navy: #38314d;
    --brand-gold: #f4bc30;
    --brand-orange: #e8891f;
    --brand-red: #d13f33;
    --brand-gradient: linear-gradient(90deg, #f4bc30 0%, #e8891f 50%, #d13f33 100%);

    --bg: #f5f4f8;
    --surface: #ffffff;
    --surface-2: #f9f8fb;
    --border: #e5e2ec;
    --text: #221d33;
    --text-muted: #6d6880;
    --primary: #38314d;
    --primary-hover: #28223a;
    --primary-soft: #efedf5;
    --primary-border: #cfc9de;
    --link: #4d4470;
    --accent: #f4bc30;
    --accent-strong: #e8891f;
    --accent-soft: #fff6df;
    --focus-ring: 0 0 0 3px rgba(244, 188, 48, .35);
    --success: #13795b;
    --success-soft: #e6f6ef;
    --warning: #9a5a06;
    --warning-soft: #fff4dc;
    --danger: #d13f33;
    --danger-soft: #fbeceb;
    --info: #4d4470;
    --info-soft: #efedf5;
    --sidebar-bg: #231d35;
    --sidebar-text: #bdb7cc;
    --sidebar-active: #ffffff;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(34, 29, 51, .05), 0 1px 3px rgba(34, 29, 51, .06);
    --sidebar-width: 244px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.muted { color: var(--text-muted); }
.text-right { text-align: right; }

.icon { width: 18px; height: 18px; flex-shrink: 0; }

/* ============ Layout ============ */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    position: fixed;
    inset: 0 auto 0 0;
    overflow-y: auto;
    z-index: 30;
    transition: transform .2s ease;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 20px;
    color: #fff;
    text-decoration: none !important;
}
.brand-mark {
    width: 32px; height: 32px;
    display: grid; place-items: center;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
}
.brand-name { font-size: 17px; font-weight: 600; letter-spacing: .2px; }

.nav { padding: 4px 12px 24px; }
.nav-group {
    margin: 18px 8px 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: #8e87a3;
}
.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 8px;
    color: var(--sidebar-text);
    text-decoration: none !important;
}
.nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-link.active { background: rgba(255, 255, 255, .1); color: var(--sidebar-active); }
.nav-link.disabled { opacity: .45; cursor: default; }
.nav-link.disabled:hover { background: none; color: var(--sidebar-text); }
.soon {
    margin-left: auto;
    font-size: 10px;
    font-style: normal;
    padding: 1px 6px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, .2);
}

.main { flex: 1; margin-left: var(--sidebar-width); min-width: 0; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 12px;
    height: 60px;
    padding: 0 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.page-title { font-size: 18px; font-weight: 600; }
.icon-btn.menu-btn { display: none; }

.user-menu { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.user-menu form { margin: 0; }
.user-chip {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 10px 4px 4px;
    border-radius: 999px;
    color: var(--text);
    text-decoration: none !important;
}
.user-chip:hover { background: var(--surface-2); }

.avatar {
    width: 32px; height: 32px;
    display: grid; place-items: center;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }

.icon-btn {
    display: inline-grid; place-items: center;
    width: 36px; height: 36px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.content { padding: 24px; max-width: 1280px; }

.sidebar-backdrop { display: none; }

/* ============ Components ============ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.card-narrow { max-width: 640px; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-header h3 { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }
.card-footer {
    display: flex; justify-content: flex-end; gap: 8px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 0 0 var(--radius) var(--radius);
}

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 38px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none !important;
    white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger-outline { color: var(--danger); border-color: #f1c4c2; }
.btn-danger-outline:hover { background: var(--danger-soft); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }

.link-btn {
    border: 0; background: none; padding: 0 10px;
    color: var(--primary); font: inherit; font-size: 13px; cursor: pointer;
}

.alert {
    padding: 11px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    border: 1px solid transparent;
}
.alert-success { background: var(--success-soft); color: var(--success); border-color: #bfe6d5; }
.alert-error   { background: var(--danger-soft);  color: var(--danger);  border-color: #f4c7c5; }
.alert-warning { background: var(--warning-soft); color: var(--warning); border-color: #f5dea6; }
.alert-info    { background: var(--info-soft);    color: var(--info);    border-color: #d8d3e6; }

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-muted   { background: #f0eef4; color: var(--text-muted); }

/* ============ Forms ============ */
.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 6px; font-weight: 500; }
.field input,
.field select,
.field textarea {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    border: 1px solid #d6d2df;
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}
.field textarea { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; }
.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
}
.field input:disabled,
.field select:disabled { background: var(--surface-2); color: var(--text-muted); }
.field.has-error input,
.field.has-error select { border-color: var(--danger); }
.field-error { margin-top: 5px; color: var(--danger); font-size: 13px; }
.hint { margin-top: 5px; color: var(--text-muted); font-size: 12.5px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.checkbox { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--primary); }

.password-wrap { position: relative; }
.password-wrap input { padding-right: 60px; }
.password-wrap .link-btn { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); }

/* ============ Tables & lists ============ */
.toolbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.search {
    position: relative;
    flex: 1;
    max-width: 340px;
    margin: 0;
}
.search .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-muted); width: 16px; }
.search input {
    width: 100%; height: 38px;
    padding: 0 12px 0 34px;
    border: 1px solid #d6d2df;
    border-radius: 8px;
    font: inherit;
    background: var(--surface);
}
.search input:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus-ring); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th,
.table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th {
    background: var(--surface-2);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
}
.table th.text-right, .table td.text-right { text-align: right; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #faf9fc; }
.cell-user { display: flex; align-items: center; gap: 10px; }
.actions { display: inline-flex; gap: 6px; }
.actions form { margin: 0; }

.empty { padding: 28px 16px; text-align: center; color: var(--text-muted); }

.list-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pagination { display: flex; gap: 4px; }
.page-link {
    min-width: 34px; height: 34px;
    display: inline-grid; place-items: center;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    text-decoration: none !important;
}
.page-link.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-link.disabled { color: #b9b4c6; }

.back-link { display: inline-block; margin-bottom: 14px; color: var(--text-muted); }

/* ============ Dashboard ============ */
.welcome { margin-bottom: 20px; }
.welcome h2 { font-size: 20px; margin-bottom: 2px; }

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
}
.stat-label { color: var(--text-muted); font-size: 13px; }
.stat-value { font-size: 26px; font-weight: 600; margin: 4px 0; }
.stat-hint { font-size: 12px; color: var(--text-muted); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }

/* ============ Login ============ */
.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px 16px;
    background: linear-gradient(160deg, #f1eff6 0%, #faf9fb 60%);
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(16, 24, 40, .08);
    padding: 32px;
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; }
.auth-card h1 { font-size: 22px; margin-bottom: 4px; }
.auth-card > .muted { margin: 0 0 22px; }

/* ============ Responsive ============ */
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar-open .sidebar { transform: translateX(0); }
    .sidebar-open .sidebar-backdrop {
        display: block;
        position: fixed; inset: 0;
        background: rgba(15, 23, 42, .45);
        z-index: 25;
    }
    .main { margin-left: 0; }
    .icon-btn.menu-btn { display: inline-grid; }
    .topbar { padding: 0 16px; }
    .content { padding: 16px; }
    .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    .user-name { display: none; }
    .field-row { grid-template-columns: 1fr; gap: 0; }
    .search { max-width: none; }
    .auth-card { padding: 24px; }
}

/* ============ Phase 2: forms, lists, settings ============ */
.req { color: var(--danger); }
.uppercase { text-transform: uppercase; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.strong { font-weight: 600; color: var(--text); }
.sub { font-size: 12.5px; color: var(--text-muted); }
.sub-inline { font-size: 12px; color: var(--text-muted); }
.truncate { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table td.wrap { white-space: normal; min-width: 220px; }

.card-medium { max-width: 760px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-header p { margin: 2px 0 0; font-size: 13px; width: 100%; }
.card-header h3 + p { margin-top: 0; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 20px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-grid > p.hint { margin: -4px 0 16px; }

.filters { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; margin: 0; }
.filters select {
    height: 38px; padding: 0 10px;
    border: 1px solid #d6d2df; border-radius: 8px;
    background: var(--surface); font: inherit; color: var(--text);
}

.segmented { position: relative; display: inline-flex; border: 1px solid #d6d2df; border-radius: 8px; overflow: hidden; }
.segmented label { margin: 0; font-weight: 500; cursor: pointer; }
.field .segmented input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 8px 16px; border-right: 1px solid #d6d2df; }
.segmented label:last-child span { border-right: 0; }
.segmented input:checked + span { background: var(--primary); color: #fff; }
.segmented input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: -2px; }

.image-box {
    height: 110px;
    display: grid; place-items: center;
    margin-bottom: 8px;
    border: 1px dashed #d6d2df;
    border-radius: 8px;
    background: repeating-conic-gradient(#f3f1f6 0% 25%, #fff 0% 50%) 50% / 16px 16px;
    overflow: hidden;
}
.image-box img { max-width: 90%; max-height: 90px; object-fit: contain; }
.field input[type="file"] { height: auto; padding: 7px; }
.field .checkbox { margin-top: 8px; font-weight: 400; }

.sticky-actions {
    position: sticky; bottom: 0; z-index: 5;
    display: flex; justify-content: flex-end;
    padding: 12px 0;
    background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.checklist li { display: flex; align-items: center; gap: 10px; }
.checklist .check {
    width: 20px; height: 20px;
    display: grid; place-items: center;
    border: 1.5px solid #d6d2df; border-radius: 50%;
    font-size: 12px; color: #fff;
}
.checklist li.done .check { background: var(--success); border-color: var(--success); }
.checklist li.done span:last-child { color: var(--text-muted); text-decoration: line-through; }

@media (max-width: 700px) {
    .form-grid { grid-template-columns: 1fr; }
    .filters .search { flex-basis: 100%; }
}

/* ============ Phase 3: documents ============ */
.badge-info    { background: var(--info-soft); color: var(--info); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }

.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #0f664c; }
.btn.disabled { opacity: .55; cursor: default; pointer-events: none; }
.soon-inline { font-style: normal; font-size: 10px; padding: 1px 6px; border-radius: 999px; background: #f0eef4; color: var(--text-muted); }

.form-grid-3 { grid-template-columns: repeat(3, 1fr); }
.filters input[type="date"] {
    height: 38px; padding: 0 8px;
    border: 1px solid #d6d2df; border-radius: 8px;
    background: var(--surface); font: inherit; color: var(--text);
}
tr.row-link { cursor: pointer; }

/* Line items */
.items-table { width: 100%; border-collapse: collapse; min-width: 1040px; }
.items-table th {
    padding: 10px 8px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px;
    color: var(--text-muted); text-align: left;
}
.items-table td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.items-table input,
.items-table select,
.items-table textarea {
    width: 100%; height: 36px; padding: 0 8px;
    border: 1px solid #d6d2df; border-radius: 6px;
    background: var(--surface); font: inherit; color: var(--text);
}
.items-table textarea { height: auto; min-height: 32px; margin-top: 6px; padding: 6px 8px; resize: vertical; font-size: 13px; }
.items-table input:focus, .items-table select:focus, .items-table textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: var(--focus-ring);
}
.items-table .num { text-align: right; }
.items-table .is-invalid { border-color: var(--danger); background: #fffafa; }
.items-table .col-num { width: 34px; color: var(--text-muted); padding-top: 18px; }
.items-table .col-hsn { width: 96px; }
.items-table .col-extra { width: 120px; }
.items-table.no-extra .col-extra, .items-table.has-extra .add-extra-col { display: none; }
.items-table.has-extra .col-item { min-width: 340px; }
.items-table .add-extra-col { margin-left: 8px; font-size: 11.5px; text-transform: none; letter-spacing: 0; }
.items-table th.col-extra input { height: 30px; font-size: 12px; font-weight: 600; text-transform: none; }
.items-table .col-qty { width: 80px; }
.items-table .col-unit { width: 90px; }
.items-table .col-rate { width: 120px; }
.items-table .col-disc { width: 124px; }
.items-table .col-gst { width: 86px; }
.items-table .col-amount { width: 120px; text-align: right; font-weight: 600; padding-top: 18px; white-space: nowrap; }
.items-table th.col-amount { padding-top: 10px; }
.items-table .col-remove { width: 40px; }
.remove-row { font-size: 22px; line-height: 1; margin-top: 2px; }
/* Item + Description side by side; "+ Add line" adds more pairs. Qty / rate / GST sit at the bottom, by the last pair */
.items-table .col-item { min-width: 360px; }
.items-table .col-extra input { min-width: 110px; }
.items-table [data-field="qty"] { min-width: 56px; }
.items-table [data-field="discount_value"] { min-width: 48px; }
.items-table [data-field="unit"], .items-table [data-field="gst_rate"] { min-width: 78px; }
.items-table [data-field="rate"] { min-width: 100px; }
.line-pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr) 28px; gap: 6px; align-items: start; }
#doc-form .items-table .line-pair textarea { margin: 0; min-height: 36px; padding: 8px; line-height: 1.4; resize: vertical; overflow: hidden; font-size: 13px; }
.items-table .line-pair .remove-line { margin-top: 4px; }
.line-pair.sub-line { margin-top: 6px; }
/* "Description" tick off: only the item boxes (the hidden descriptions are still posted, so nothing typed is lost) */
.items-table.hide-desc .line-pair { grid-template-columns: minmax(0, 1fr) 28px; }
.items-table.hide-desc .line-pair textarea { display: none; }
.items-table .desc-toggle { display: inline-flex; align-items: center; gap: 4px; margin-left: 8px; font-size: 11.5px; font-weight: 600; text-transform: none; letter-spacing: 0; color: #4a4e66; cursor: pointer; white-space: nowrap; }
.items-table .desc-toggle input { margin: 0; width: 14px; height: 14px; }
.items-table .line-pair input { margin: 0; }
.items-table .sub-line input { height: 36px; font-size: 13px; }
.items-table .item-row > td:not(.col-item):not(.col-num):not(.col-extra) { vertical-align: bottom; padding-bottom: 38px; }
.items-table .item-row > td.col-amount { padding-bottom: 49px; }
.remove-line { flex: none; width: 28px; height: 28px; font-size: 18px; line-height: 1; }
.remove-line:hover { color: var(--danger); background: var(--danger-soft); }
.items-table .add-line { margin-top: 6px; font-size: 13px; }
.remove-row:hover { color: var(--danger); background: var(--danger-soft); }
.row-error { margin-top: 5px; color: var(--danger); font-size: 12.5px; }
.items-footer { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.input-group { display: flex; }
.input-group input { border-radius: 6px 0 0 6px !important; min-width: 0; }
.input-group select { width: 52px !important; flex-shrink: 0; border-left: 0 !important; border-radius: 0 6px 6px 0 !important; padding: 0 4px !important; }
.input-group-sm { margin-top: 6px; max-width: 150px; }
.input-group-sm input, .input-group-sm select {
    height: 32px; padding: 0 8px; border: 1px solid #d6d2df; background: var(--surface); font: inherit; color: var(--text);
}
.input-group.has-error input { border-color: var(--danger); }

.doc-bottom { display: grid; grid-template-columns: 1fr 380px; gap: 20px; align-items: start; }
.totals { width: 100%; border-collapse: collapse; }
.totals td { padding: 8px 0; vertical-align: top; }
.totals td:last-child { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.totals tr + tr td { border-top: 1px dashed var(--border); }
.totals .grand td { font-size: 18px; font-weight: 700; padding-top: 12px; border-top: 2px solid var(--text) !important; }

/* Document view */
.doc-toolbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    margin-bottom: 16px;
}
.doc-toolbar-info { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.doc-toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.doc-toolbar-actions form { margin: 0; }
.doc-audit { font-size: 12.5px; margin-top: 12px; }

@media (max-width: 1000px) {
    .doc-bottom { grid-template-columns: 1fr; }
    .form-grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 700px) {
    .form-grid-3 { grid-template-columns: 1fr; }
    .form-grid-3 .span-2 { grid-column: auto; }
}

/* Print: only the document */
@media print {
    @page { size: A4; margin: 10mm; }
    body { background: #fff; }
    .sidebar, .sidebar-backdrop, .topbar, .no-print, .alert { display: none !important; }
    .main { margin: 0; }
    .content { padding: 0; max-width: none; }
    .doc-paper { box-shadow: none !important; border: 0 !important; padding: 0 !important; margin: 0 !important; width: auto !important; }
}

/* ============ Phase 4: invoices & payments ============ */
tr.row-muted td { color: var(--text-muted); }
tr.row-muted .strong { color: var(--text-muted); text-decoration: line-through; }

.dropdown { position: relative; }
.dropdown > summary { list-style: none; }
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown-panel {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
    width: 300px; padding: 14px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: 0 10px 30px rgba(16, 24, 40, .12);
}
.dropdown-panel label { display: block; font-weight: 500; margin-bottom: 6px; }
.dropdown-panel input[type="text"] {
    width: 100%; height: 38px; padding: 0 10px; margin-bottom: 6px;
    border: 1px solid #d6d2df; border-radius: 8px; font: inherit;
}

.payments-card { margin-top: 20px; }
.payment-form { border-top: 1px solid var(--border); }
.payment-form h4 { margin: 0 0 14px; font-size: 14px; }

.welcome { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.welcome-actions { display: flex; gap: 8px; }
a.stat-link { color: inherit; text-decoration: none !important; transition: border-color .15s, box-shadow .15s; }
a.stat-link:hover { border-color: var(--primary-border); box-shadow: 0 4px 14px rgba(16, 24, 40, .08); }
.stat-alert .stat-value { color: var(--danger); }
.stat-value { font-size: 22px; font-variant-numeric: tabular-nums; }
.btn-primary-outline { color: var(--primary); border-color: var(--primary-border); }
.btn-primary-outline:hover { background: var(--primary-soft); }

/* ============ Roles & permissions ============ */
.field-label { display: block; font-weight: 500; margin-bottom: 4px; }
.perm-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin: 10px 0 16px; }
.perm-group {
    margin: 0; padding: 12px 14px 10px;
    border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2);
}
.perm-group legend { padding: 0 6px; font-weight: 600; }
.perm-group > .checkbox { display: flex; margin: 6px 0; font-weight: 400; }
.perm-note { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 13px; }
@media (max-width: 700px) { .perm-grid { grid-template-columns: 1fr; } }

/* ============ Phase 6: sharing ============ */
.share-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; margin-top: 20px; }
.share-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.wa-form { display: flex; gap: 0; margin: 0; }
.wa-form input {
    height: 38px; width: 160px; padding: 0 10px;
    border: 1px solid #d6d2df; border-right: 0; border-radius: 8px 0 0 8px; font: inherit;
}
.wa-form .btn { border-radius: 0 8px 8px 0; }
.btn-whatsapp { background: #1fa855; border-color: #1fa855; color: #fff; }
.btn-whatsapp:hover { background: #178a45; }
.share-link { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.share-link form { margin: 0; }
.copy-row { display: flex; gap: 6px; margin-bottom: 4px; }
.copy-row input {
    flex: 1; min-width: 0; height: 38px; padding: 0 10px;
    border: 1px solid #d6d2df; border-radius: 8px; background: var(--surface-2); font: inherit; font-size: 13px;
}

.timeline { list-style: none; margin: 0; padding: 12px 20px 16px; max-height: 360px; overflow-y: auto; }
.timeline li { position: relative; padding: 0 0 12px 18px; border-left: 2px solid var(--border); margin-left: 4px; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before {
    content: ""; position: absolute; left: -6px; top: 4px;
    width: 10px; height: 10px; border-radius: 50%; background: #c3bed0;
}
.timeline .timeline-emailed::before, .timeline .timeline-whatsapp::before { background: var(--primary); }
.timeline .timeline-viewed::before, .timeline .timeline-downloaded::before { background: var(--success); }
.timeline .timeline-email_failed::before, .timeline .timeline-link_revoked::before { background: var(--danger); }
.timeline-title { font-weight: 500; }

.customer-info { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; }
.customer-info .doc-label { margin: 0 0 3px; font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--text-muted); }
.customer-info .doc-label ~ .doc-label { margin-top: 12px; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 200px; height: 38px; padding: 0 10px; border: 1px solid #d6d2df; border-radius: 8px; font: inherit; }

/* Public page (customer view, no login) */
.public-page { background: #f1eff6; }
.public-bar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.public-bar-inner { max-width: 900px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.public-company { font-weight: 700; font-size: 16px; }
.public-actions { display: flex; gap: 8px; }
.public-main { max-width: 900px; margin: 0 auto; padding: 20px 16px 40px; }
.public-pay { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.public-footer { text-align: center; margin-top: 18px; font-size: 13px; }

@media (max-width: 900px) { .share-grid { grid-template-columns: 1fr; } }
@media print { .public-page { background: #fff; } .public-main { padding: 0; } }

/* ============ Responsive fixes (phones) ============ */
/* Grid children may shrink below their content (tables scroll inside instead of pushing the page wider) */
.grid-2 > *, .doc-bottom > *, .share-grid > *, .form-grid > *, .stats > * { min-width: 0; }

@media (max-width: 640px) {
    /* List tables become stacked cards; labels come from the table header (see app.js) */
    .table.stack thead { display: none; }
    .table.stack, .table.stack tbody, .table.stack tr, .table.stack td { display: block; width: 100%; }
    .table.stack tr { padding: 10px 0; border-bottom: 1px solid var(--border); }
    .table.stack tbody tr:last-child { border-bottom: 0; }
    .table.stack td {
        display: flex; justify-content: flex-end; align-items: center; flex-wrap: wrap; gap: 4px 6px;
        padding: 3px 16px; border: 0; white-space: normal; text-align: right;
    }
    .table.stack td::before {
        content: attr(data-label);
        flex-shrink: 0; margin-right: auto; text-align: left;
        font-size: 12px; font-weight: 400; color: var(--text-muted);
    }
    .table.stack td:first-child { font-size: 15px; }
    .table.stack td.text-right, .table.stack td.wrap { text-align: right; }
    .table.stack td > div, .table.stack .cell-user { text-align: right; }
    .table.stack td.empty { display: block; text-align: center; }
    .table.stack td.empty::before { content: none; }
    .table.stack .actions { margin-left: auto; }
    .table.stack .sub { text-align: right; }

    /* Compact toolbars */
    .doc-toolbar-actions .btn, .toolbar .btn { height: 34px; padding: 0 10px; font-size: 13px; }
    .doc-toolbar-actions { gap: 6px; }
    .page-title { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .content { padding: 12px; }
    .card-body { padding: 16px; }
    .card-header { padding: 14px 16px; }
    .stat-value { font-size: 17px; }
    .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat { padding: 12px; }
    .stat-hint { font-size: 11.5px; }
    .welcome-actions { width: 100%; }
    .welcome-actions .btn { flex: 1; }
    .wa-form { width: 100%; }
    .wa-form input { flex: 1; width: auto; }
    .dropdown-panel { position: fixed; left: 12px; right: 12px; top: auto; width: auto; }
}
.backup-help p { margin: 0 0 12px; }
.backup-help code { display: inline-block; margin-top: 4px; padding: 6px 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; font-size: 12px; word-break: break-all; }

/* ============ Brand (Flagship Media logo) ============ */
.brand-logo { width: 34px; height: 34px; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand .brand-name { font-size: 17px; font-weight: 800; letter-spacing: .6px; text-transform: uppercase; }
.brand-sub { font-size: 10px; font-weight: 600; letter-spacing: 4.2px; text-transform: uppercase; color: #aab3c2; }
.auth-logo { display: block; width: 220px; height: auto; }
.brand-full { display: block; width: 180px; height: auto; }

/* ============ Brand theme (Flagship Media) ============ */
/* Thin logo-gradient strip on top bars */
.topbar, .public-bar {
    background-image: var(--brand-gradient);
    background-size: 100% 3px;
    background-repeat: no-repeat;
    background-color: var(--surface);
}
.auth-card { position: relative; overflow: hidden; }
.auth-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--brand-gradient); }

/* Sidebar: gold marker on the active item */
.nav-link:hover { background: rgba(255, 255, 255, .07); }
.nav-link.active { background: rgba(255, 255, 255, .09); box-shadow: inset 3px 0 0 var(--accent); }
.nav-link.active .icon { color: var(--accent); }
.nav-group { color: #8e87a3; }

/* Positive actions (Record payment, Accept, Convert) use the logo gold with navy text */
.btn-success { background: var(--accent); border-color: var(--accent); color: var(--text); }
.btn-success:hover { background: #e9ad1c; border-color: #e9ad1c; }

/* Focus outline in gold everywhere */
.btn:focus-visible, .nav-link:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.checkbox input, .segmented input { accent-color: var(--primary); }
.stat-link:hover .stat-value { color: var(--primary); }
.brand-sub { color: var(--accent); }
.badge-accent { background: #fdecd9; color: #a4540c; }
.test-banner { position: fixed; z-index: 100; left: 0; right: 0; bottom: 0; padding: 6px 12px; background: var(--brand-red); color: #fff; font-size: 12.5px; font-weight: 600; text-align: center; }


/* ============ Quotation / invoice form: compact layout ============ */
.form-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
#doc-form .card { margin-bottom: 16px; }
#doc-form .card-header { padding: 14px 24px; }
#doc-form .card-body { padding: 18px 24px 4px; }
#doc-form .form-grid { column-gap: 16px; }
#doc-form .field { margin-bottom: 14px; }
#doc-form .field label { margin-bottom: 6px; }
#doc-form .field input, #doc-form .field select, #doc-form .xsel-btn { height: 40px; }
#doc-form .field textarea { min-height: 0; }
#doc-form .hint { margin-top: 4px; }
#doc-form .items-table td { padding: 8px; }
#doc-form .items-table .col-num, #doc-form .items-table .col-amount { padding-top: 14px; }
#doc-form .items-table textarea { margin-top: 4px; }
#doc-form .items-footer { padding: 12px 24px; }
#doc-form .totals-card .card-body { padding: 14px 24px; }
#doc-form .totals td { padding: 6px 0; }
#doc-form .totals .grand td { padding-top: 10px; }

/* "Or load a quotation" picker (invoice form) */
.form-grid-4 > .from-quote { grid-column: span 2; }
.from-quote-row { display: flex; gap: 8px; }
.from-quote-row > select, .from-quote-row > .xsel { flex: 1; min-width: 0; }
.from-quote .btn:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 1100px) {
    .form-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
    .form-grid-4 { grid-template-columns: 1fr; }
    .form-grid-4 .span-2, .form-grid-4 > .from-quote { grid-column: auto; }
    #doc-form .card-header, #doc-form .card-body, #doc-form .items-footer { padding-left: 16px; padding-right: 16px; }
}

/* Settings > Quotation labels */
.labels-group { margin: 4px 0 10px; font-size: 12px; font-weight: 600; letter-spacing: .5px; text-transform: uppercase; color: var(--text-muted); }
.labels-group ~ .labels-group { margin-top: 10px; padding-top: 14px; border-top: 1px solid var(--border); }
.labels-toggles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px 24px; padding-bottom: 16px; }
/* Quotation form: ✎ next to a label renames it on this quotation only (assets/js/label-edit.js) */
.label-edit { display: inline-flex; align-items: center; gap: 2px; max-width: 100%; }
.label-edit.is-own .label-edit-text { color: var(--primary); }
.label-edit-btn { border: 0; background: none; padding: 0 3px; font-size: 13px; line-height: 1; color: var(--text-muted); cursor: pointer; opacity: .55; }
.label-edit-btn:hover, .label-edit-btn:focus-visible { opacity: 1; color: var(--primary); }
.label-edit.is-own .label-edit-btn { opacity: 1; color: var(--primary); }
.label-edit.is-editing .label-edit-text, .label-edit.is-editing .label-edit-btn { display: none; }
input.label-edit-input { width: 15ch; min-width: 0; padding: 2px 6px; font: inherit; font-size: 13px; height: auto; text-transform: none; letter-spacing: normal; }
.items-table th .label-edit { vertical-align: middle; }
/* Quotation form: columns switched off in Settings > Quotation labels (inputs are kept, only hidden) */
.items-table.hide-col-hsn .col-hsn, .items-table.hide-col-disc .col-disc, .items-table.hide-col-gst .col-gst { display: none; }

/* Quotation view: attachments card */
.attach-list { list-style: none; margin: 0; padding: 0; }
.attach-list li { display: flex; align-items: center; gap: 14px; padding: 12px 24px; border-bottom: 1px solid var(--border); }
.attach-thumb { flex-shrink: 0; width: 56px; height: 56px; border-radius: 8px; overflow: hidden; display: grid; place-items: center; background: #fdeee4; color: #f26b21; font-weight: 700; font-size: 13px; text-decoration: none; }
.attach-thumb img { width: 100%; height: 100%; object-fit: cover; }
.attach-thumb span { color: #f26b21; }
.attach-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.attach-info a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-info .muted { font-size: 12.5px; }
.attach-upload { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
/* Drag-to-resize: the box is the printable width of the PDF page */
.attach-layout { border-bottom: 1px solid var(--border); }
.attach-layout-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.attach-layout-head > div { flex: 1; }
.attach-layout-head .muted { font-size: 12.5px; margin-top: 2px; }
.attach-saved { font-size: 12.5px; white-space: nowrap; padding-top: 6px; }
.attach-handle-icon { display: inline-block; width: 10px; height: 10px; border-right: 2px solid var(--primary); border-bottom: 2px solid var(--primary); vertical-align: middle; }
.attach-page {
    max-width: 760px; margin: 0 auto; min-height: 120px; text-align: center; line-height: 0;
    background-color: #fff; border: 1px solid var(--border); box-shadow: 0 2px 10px rgba(31, 36, 81, .06);
    background-image: linear-gradient(to bottom, transparent calc(100% - 1px), rgba(232, 65, 44, .35) calc(100% - 1px));
    background-repeat: repeat-y;
}
.attach-box { position: relative; display: inline-block; vertical-align: bottom; outline: 1px dashed transparent; }
.attach-box:hover, .attach-box.is-resizing { outline-color: var(--primary); }
.attach-box img { width: 100%; height: 100%; display: block; user-select: none; }
.attach-pct {
    position: absolute; top: 6px; left: 6px; padding: 2px 6px; border-radius: 4px; line-height: 1.4;
    background: rgba(31, 36, 81, .75); color: #fff; font-size: 11px; font-weight: 600; opacity: 0; transition: opacity .15s;
}
.attach-box:hover .attach-pct, .attach-box.is-resizing .attach-pct { opacity: 1; }
.attach-handle {
    position: absolute; right: -6px; bottom: -6px; width: 14px; height: 14px; border-radius: 3px;
    background: #fff; border: 2px solid var(--primary); cursor: nwse-resize; touch-action: none;
}
.attach-upload input[type="file"] { flex: 1; min-width: 220px; padding: 8px; border: 1px dashed var(--border); border-radius: 8px; }

/* Share card: signature on/off (quotations) */
.share-sign { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 14px 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; }
.share-sign .field-label { display: inline; margin: 0 6px 0 0; }
.share-sign-state { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #f0eef4; color: var(--text-muted); }
.share-sign-state.is-on { background: var(--success-soft); color: var(--success); }
.share-sign .hint { margin-top: 4px; }
.share-sign form { margin: 0; flex-shrink: 0; }
.from-quote.is-loading { opacity: .6; pointer-events: none; }
.from-quote.is-loading .hint::after { content: " Loading…"; font-weight: 600; }
.labels-toggle .hint { margin: 2px 0 0 24px; }
.labels-field-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.labels-field .labels-field-name { margin: 0 !important; }
.labels-show { display: inline-flex; align-items: center; gap: 5px; margin: 0 !important; font-size: 12.5px; font-weight: 500 !important; color: var(--text-muted); cursor: pointer; white-space: nowrap; }
.labels-show input { width: 15px; height: 15px; margin: 0; }
.labels-always { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.labels-noword { display: flex; align-items: center; height: 40px; padding: 0 14px; border: 1px dashed var(--border); border-radius: 12px; font-size: 13px; color: var(--text-muted); }
.labels-field.is-off input[type="text"], .labels-field.is-off .labels-noword { opacity: .45; text-decoration: line-through; }
.dash .field .labels-show { display: inline-flex; flex-direction: row; }
.dash .field .labels-show input[type="checkbox"] { width: 15px; height: 15px; padding: 0; border-radius: 4px; flex: none; }

/* Quotation view: text size (A- / A+) above the paper */
.doc-font { display: flex; align-items: center; justify-content: flex-end; gap: 6px; max-width: 210mm; margin: 0 auto 10px; font-size: 13px; }
.doc-font .btn { min-width: 36px; justify-content: center; font-weight: 700; }
.doc-font .doc-font-up { font-size: 15px; }
.doc-font-pct { min-width: 44px; text-align: center; font-weight: 700; }
.doc-font-saved { min-width: 70px; font-size: 12.5px; }

/* Quotation form: campaign details (Train branding format) */
.campaign-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.campaign-row { display: grid; grid-template-columns: minmax(140px, 260px) 1fr auto; gap: 8px; align-items: start; }
.campaign-row input,
.campaign-row textarea {
    width: 100%;
    min-height: 40px;
    padding: 9px 12px;
    border: 1px solid #d6d2df;
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    line-height: 1.4;
}
.campaign-row textarea { resize: vertical; overflow: hidden; }
.campaign-row input:focus, .campaign-row textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus-ring); }
.campaign-row-tools { display: flex; gap: 2px; padding-top: 4px; }
.campaign-gap { margin-top: 20px; }
@media (max-width: 600px) {
    .campaign-row { grid-template-columns: 1fr auto; }
    .campaign-row textarea { grid-column: 1; }
    .campaign-row-tools { grid-row: 1; grid-column: 2; }
}

/* ============ Popup (sweet-alert style, assets/js/app.js Popup) ============ */
html.pp-open { overflow: hidden; }
.pp-overlay {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
    background: rgba(28, 23, 41, .48);
    backdrop-filter: blur(2px);
    opacity: 0; transition: opacity .18s ease;
}
.pp-overlay.is-visible { opacity: 1; }
.pp-overlay.is-leaving { opacity: 0; transition-duration: .15s; }
.pp-box {
    position: relative; overflow: hidden;
    width: 100%; max-width: 420px;
    padding: 30px 28px 24px;
    background: var(--surface);
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(28, 23, 41, .28), 0 2px 8px rgba(28, 23, 41, .12);
    text-align: center;
    transform: scale(.88); transition: transform .26s cubic-bezier(.2, 1.4, .4, 1);
}
.pp-overlay.is-visible .pp-box { transform: scale(1); }
.pp-overlay.is-leaving .pp-box { transform: scale(.94); transition: transform .15s ease-in; }

.pp-icon { width: 76px; height: 76px; margin: 0 auto 16px; border-radius: 50%; }
.pp-icon svg { width: 100%; height: 100%; display: block; }
.pp-icon .pp-ring { fill: none; stroke-width: 2.5; opacity: .28; stroke: currentColor; }
.pp-icon .pp-draw {
    fill: none; stroke: currentColor; stroke-width: 3.6; stroke-linecap: round; stroke-linejoin: round;
    stroke-dasharray: 60; stroke-dashoffset: 60;
    animation: pp-draw .45s .12s ease-out forwards;
}
.pp-icon .pp-dot { fill: currentColor; opacity: 0; animation: pp-fade .2s .4s forwards; }
.pp-success .pp-icon { color: var(--success); background: var(--success-soft); }
.pp-error .pp-icon   { color: var(--danger);  background: var(--danger-soft); animation: pp-shake .4s .1s; }
.pp-warning .pp-icon { color: var(--accent-strong); background: var(--accent-soft); }
.pp-question .pp-icon { color: var(--primary); background: var(--primary-soft); }
.pp-info .pp-icon    { color: var(--info); background: var(--info-soft); }

.pp-title { font-size: 19px; font-weight: 700; color: var(--text); margin: 0 0 8px; overflow-wrap: anywhere; }
.pp-text { margin: 0; color: var(--text-muted); font-size: 14.5px; line-height: 1.55; overflow-wrap: anywhere; }
.pp-actions { display: flex; justify-content: center; gap: 10px; margin-top: 24px; flex-wrap: wrap; }
.pp-actions .btn { min-width: 112px; height: 42px; padding: 0 18px; font-size: 14px; }
.pp-box .pp-ok.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.pp-box .pp-ok.btn-danger:hover { background: #b8342a; border-color: #b8342a; }
.pp-actions .btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.pp-timer {
    position: absolute; left: 0; bottom: 0; height: 4px; width: 100%;
    background: var(--brand-gradient); transform-origin: left;
    animation: pp-timer linear forwards;
}

@keyframes pp-draw { to { stroke-dashoffset: 0; } }
@keyframes pp-fade { to { opacity: 1; } }
@keyframes pp-timer { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes pp-shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

@media (max-width: 480px) {
    .pp-box { padding: 26px 20px 20px; }
    .pp-actions .btn { flex: 1; }
}
@media (prefers-reduced-motion: reduce) {
    .pp-overlay, .pp-box, .pp-icon { transition: none !important; animation: none !important; }
    .pp-icon .pp-draw { animation: none; stroke-dashoffset: 0; }
    .pp-icon .pp-dot { animation: none; opacity: 1; }
}
@media print { .pp-overlay { display: none !important; } }
