@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&display=swap');

:root {
    --ink:        #14131a;
    --panel:      #1c1b24;
    --panel-2:    #232230;
    --border:     rgba(255,255,255,0.09);
    --border-2:   rgba(255,255,255,0.14);
    --text:       #ece8e0;
    --text-muted: #9a96a6;
    --brass:      #c3924f;
    --brass-soft: rgba(195,146,79,0.14);
    --ok:         #5fa776;
    --ok-soft:    rgba(95,167,118,0.14);
    --warn:       #d9a441;
    --warn-soft:  rgba(217,164,65,0.14);
    --danger:     #c1554b;
    --danger-soft:rgba(193,85,75,0.14);
    --radius:     10px;
    --radius-sm:  6px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--ink);
    color: var(--text);
    font-family: 'Vazirmatn', Tahoma, sans-serif;
    font-size: 15px;
    line-height: 1.7;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

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

.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--panel);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 22px 0;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 22px 22px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.brand-mark-img {
    width: 40px;
    height: 40px;
    object-fit: contain;
    flex-shrink: 0;
}

.brand-name { font-weight: 700; font-size: 15.5px; letter-spacing: 0.3px; }
.brand-sub { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 14px 12px;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    border-right: 2px solid transparent;
    transition: background 0.15s, color 0.15s;
}

.sidebar-nav a:hover { background: var(--panel-2); color: var(--text); }

.sidebar-nav a.active {
    background: var(--brass-soft);
    color: var(--brass);
    border-right-color: var(--brass);
}

.nav-icon { font-size: 15px; width: 18px; text-align: center; }

.sidebar-footer {
    padding: 14px 18px 0;
    border-top: 1px solid var(--border);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--panel-2);
    border: 1px solid var(--border-2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    color: var(--brass);
}

.user-name { font-size: 13.5px; font-weight: 600; }
.user-role { font-size: 11.5px; color: var(--text-muted); }

.logout-link {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
    padding: 6px 2px;
}
.logout-link:hover { color: var(--danger); }

/* ===================== Main content ===================== */
.main-content {
    flex: 1;
    padding: 26px 34px 50px;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 22px;
}

.page-title { font-size: 22px; font-weight: 700; margin: 0; }
.topbar-date { font-size: 13px; color: var(--text-muted); }

.content-body { display: flex; flex-direction: column; gap: 20px; }

/* ===================== Stat cards ===================== */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
}

.stat-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 18px 16px;
}

.stat-card.accent { border-color: rgba(195,146,79,0.35); }

.stat-label { font-size: 12.5px; color: var(--text-muted); margin-bottom: 10px; }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-card.accent .stat-value { color: var(--brass); }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ===================== Panels ===================== */
.panel-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
@media (max-width: 980px) { .panel-grid { grid-template-columns: 1fr; } }

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px 20px;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}
.panel-head h2 { font-size: 15.5px; font-weight: 700; margin: 0; }
.panel-link { font-size: 12.5px; color: var(--brass); }

.empty-note { color: var(--text-muted); font-size: 13.5px; padding: 10px 0; }

/* ===================== Tables ===================== */
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
    text-align: right;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 12px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}
.data-table td {
    padding: 11px 10px;
    border-bottom: 1px solid var(--border);
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr[onclick] { cursor: pointer; }
.data-table tbody tr[onclick]:hover { background: var(--panel-2); }

.row-actions { display: flex; gap: 4px; }

.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); font-weight: 600; }
.text-warning { color: var(--warn); font-weight: 600; }
.text-accent { color: var(--brass); font-weight: 600; }
.small { font-size: 12px; }

/* ===================== Badges ===================== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 11.5px;
    font-weight: 600;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warning { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-accent { background: var(--brass-soft); color: var(--brass); }

/* ===================== Buttons ===================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 600;
    border: 1px solid transparent;
    background: transparent;
}
.btn-primary { background: var(--brass); color: #201708; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--panel-2); color: var(--text); border-color: var(--border-2); }
.btn-ghost:hover { background: var(--border-2); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }

/* ===================== Toolbar / search ===================== */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.search-form { display: flex; gap: 8px; align-items: center; }
.search-form input {
    background: var(--panel);
    border: 1px solid var(--border-2);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 13.5px;
}

/* ===================== Forms ===================== */
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); }
input:not([type="checkbox"]):not([type="radio"]), select {
    background: var(--ink);
    border: 1px solid var(--border-2);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 14px;
}
input:focus, select:focus { outline: none; border-color: var(--brass); }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; flex-shrink: 0; accent-color: var(--brass); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inline-label { flex-direction: row; align-items: center; gap: 8px; }

/* ===================== Alerts ===================== */
.alert {
    padding: 11px 16px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    border: 1px solid transparent;
}
.alert-success { background: var(--ok-soft); color: var(--ok); border-color: rgba(95,167,118,0.3); }
.alert-error   { background: var(--danger-soft); color: var(--danger); border-color: rgba(193,85,75,0.3); }
.alert-warning { background: var(--warn-soft); color: var(--warn); border-color: rgba(217,164,65,0.3); }

/* ===================== Modal ===================== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10,9,13,0.65);
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 20px;
}
.modal.open { display: flex; }
.modal-box {
    background: var(--panel);
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    width: 100%;
    max-width: 440px;
    padding: 22px 24px 26px;
}
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    line-height: 1;
}
.modal-form { display: flex; flex-direction: column; gap: 13px; }
.modal-note { font-size: 12px; color: var(--text-muted); margin: -4px 0 0; }

/* ===================== Product colors ===================== */
.color-quick-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.color-row { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
.color-row input[name="color_name[]"] { flex: 1; }
.color-row input[name="color_qty[]"] { width: 70px; }

.color-pick-list { display: flex; flex-direction: column; gap: 8px; }
.color-pick-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--panel-2);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 12px 14px;
    font-size: 14px;
    font-weight: 600;
}
.color-pick-btn:hover:not(:disabled) { border-color: var(--brass); color: var(--brass); }
.color-pick-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===================== Auth pages ===================== */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--ink);
}
.auth-box {
    width: 100%;
    max-width: 380px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 34px 30px;
}
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-logo { width: 180px; max-width: 70%; height: auto; display: block; margin: 0 auto; }
.brand-title { font-size: 20px; font-weight: 700; margin: 0; }
.brand-subtitle { font-size: 13px; color: var(--text-muted); margin: 4px 0 0; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }

/* ===================== Invoice new / bar chart ===================== */
.invoice-total-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}
.invoice-grand-total { font-size: 16px; font-weight: 700; color: var(--brass); }

.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 160px;
    padding-top: 10px;
}
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.bar-track { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.bar-fill { width: 100%; background: var(--brass); border-radius: 4px 4px 0 0; min-height: 4px; }
.bar-label { font-size: 10.5px; color: var(--text-muted); margin-top: 6px; }

.invoice-payments-print { display: none; }
@media print {
    .invoice-payments-print { display: block; }
}

/* ===================== Invoice sheet ===================== */
.invoice-logo-row { text-align: center; margin-bottom: 8px; }
.invoice-logo-main { height: 3cm; width: 3cm; display: inline-block; object-fit: contain; }
.invoice-header { display: flex; justify-content: space-between; margin-bottom: 22px; padding-bottom: 18px; border-bottom: 1px dashed var(--border-2); }
.brand-name-lg { font-size: 19px; font-weight: 700; }
.invoice-meta { text-align: left; font-size: 13px; }
.invoice-meta div { margin-bottom: 3px; }
.invoice-items-table { margin-bottom: 18px; }
.invoice-items-table tfoot td { border-top: 1.5px solid var(--border-2); font-weight: 700; }
.invoice-summary { text-align: left; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.invoice-summary .grand { font-size: 16px; }
.invoice-footer { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--border); }
.invoice-payments { margin-top: 16px; }
.invoice-payments h3 { font-size: 13.5px; margin: 0 0 8px; color: var(--text-muted); }
.invoice-prior-debt { margin-top: 16px; }
.invoice-prior-debt h3 { font-size: 13.5px; margin: 0 0 8px; color: var(--danger); }

.status-select {
    background: var(--panel-2);
    border: 1px solid var(--border-2);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 5px 8px;
    font-size: 12.5px;
}
.status-select.status-cleared { color: var(--ok); }
.status-select.status-pending { color: var(--warn); }
.status-select.status-bounced { color: var(--danger); }
.inline-status-form { display: inline-block; }

@media print {
    @page { size: A4; margin: 14mm 12mm; }
    @page invoiceA5 { size: A5; margin: 8mm; }

    .sidebar, .topbar, .no-print, .alert { display: none !important; }
    .app-shell { display: block !important; }
    .main-content { padding: 0 !important; }
    body, .invoice-sheet { background: #fff !important; color: #000 !important; }
    .panel.invoice-sheet { border: none !important; padding: 0 !important; }

    .invoice-sheet.a5-print { page: invoiceA5; }
    .invoice-sheet.a5-print .invoice-header { margin-bottom: 10px; padding-bottom: 6px; }
    .invoice-sheet.a5-print th,
    .invoice-sheet.a5-print td { font-size: 12px; padding: 6px 7px; }
    .invoice-sheet.a5-print table { margin-bottom: 10px; }

    .invoice-sheet .invoice-header {
        border-bottom: 2px solid #000;
        padding-bottom: 10px;
        margin-bottom: 18px;
        font-weight: 700;
    }
    .invoice-sheet .brand-name-lg { color: #000 !important; font-size: 20px; }
    .invoice-sheet .text-muted,
    .invoice-sheet .invoice-meta,
    .invoice-sheet .invoice-summary,
    .invoice-sheet .text-accent,
    .invoice-sheet .text-danger,
    .invoice-sheet .invoice-prior-debt h3 { color: #000 !important; font-weight: 700 !important; }
    .invoice-sheet .invoice-meta { font-size: 14px; }

    .invoice-sheet table {
        width: 100%;
        border-collapse: collapse;
        margin-bottom: 16px;
    }
    .invoice-sheet th, .invoice-sheet td {
        border: 2px solid #000 !important;
        padding: 8px 10px;
        color: #000 !important;
        background: #fff !important;
        font-size: 13.5px;
        font-weight: 700;
    }
    .invoice-sheet th { background: #eee !important; font-weight: 800; }

    .invoice-sheet .invoice-summary { border-top: none; }
    .invoice-sheet .invoice-summary .grand {
        font-size: 17px;
        border-top: 2px solid #000;
        padding-top: 8px;
        margin-top: 4px;
    }
    .invoice-sheet .badge {
        background: none !important;
        border: 1px solid #000 !important;
        color: #000 !important;
        border-radius: 4px;
    }
}

/* ===================== Date field with calendar picker ===================== */
.date-field { display: flex; align-items: stretch; gap: 6px; }
.date-field input { flex: 1; cursor: pointer; background: var(--ink); }
.date-picker-btn {
    background: var(--panel-2);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    color: var(--brass);
    font-size: 15px;
    padding: 0 12px;
    flex-shrink: 0;
}
.date-picker-btn:hover { background: var(--border-2); }
.field-inactive { opacity: 0.35; pointer-events: none; }

.jalali-cal-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10,9,13,0.65);
    align-items: center;
    justify-content: center;
    z-index: 300;
    padding: 20px;
}
.jalali-cal-modal.open { display: flex; }
.jalali-cal-box {
    background: var(--panel-2);
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    padding: 14px;
    width: 100%;
    max-width: 260px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.45);
}
.cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-title { font-size: 13.5px; font-weight: 600; }
.cal-nav {
    background: var(--panel);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    color: var(--text);
    width: 26px; height: 26px;
    font-size: 14px;
    line-height: 1;
}
.cal-nav:hover { background: var(--border-2); }
.cal-weekdays, .cal-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
    text-align: center;
}
.cal-weekdays div { font-size: 11px; color: var(--text-muted); padding: 4px 0; }
.cal-day {
    font-size: 12.5px;
    padding: 6px 0;
    border-radius: 6px;
    cursor: pointer;
}
.cal-day:hover { background: var(--brass-soft); color: var(--brass); }
.cal-day.today { border: 1px solid var(--brass); }

/* ===================== Product search dropdown ===================== */
.product-search-popup {
    display: none;
    position: absolute;
    z-index: 200;
    background: var(--panel-2);
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    max-height: 280px;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0,0,0,0.45);
}
.product-search-popup.open { display: block; }
.product-search-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.product-search-item:last-child { border-bottom: none; }
.product-search-item:hover { background: var(--brass-soft); color: var(--brass); }
.product-search-empty { padding: 12px; font-size: 12.5px; color: var(--text-muted); text-align: center; }
