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

:root {
    --bg: #090d16;
    --card: #111928;
    --card2: #1f2a3d;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --green: #10b981;
    --red: #f43f5e;
    --yellow: #f59e0b;
    --blue: #3b82f6;
    --border: rgba(255, 255, 255, 0.07);
    --border-hover: rgba(255, 255, 255, 0.12);
    --shadow: rgba(0, 0, 0, 0.4);
    color-scheme: dark;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* Custom Premium Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: var(--bg);
}
::-webkit-scrollbar-thumb {
    background: var(--card2);
    border-radius: 99px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

html {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Outfit', system-ui, -apple-system, sans-serif;
    min-height: 100%;
    overscroll-behavior-y: none;
    -webkit-font-smoothing: antialiased;
}

a {
    text-decoration: none;
    color: inherit;
}

.app {
    max-width: 560px;
    margin: auto;
    min-height: 100vh;
    padding-bottom: calc(82px + env(safe-area-inset-bottom));
    background: #090d16;
    position: relative;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    background: rgba(9, 13, 22, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    padding-top: max(14px, env(safe-area-inset-top));
}

.brand b {
    display: block;
    color: var(--green);
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.5px;
    text-shadow: 0 0 15px rgba(16, 185, 129, 0.2);
}

.brand small {
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
    margin-top: 1px;
}

.top-actions {
    display: flex;
    gap: 8px;
}

.main {
    padding: 16px;
}

/* Premium Containers */
.page-head, .hero, .card, .table-card, .filter-card, .form-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 4px 20px var(--shadow);
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.card:hover, .table-card:hover {
    border-color: var(--border-hover);
}

.hero, .page-head {
    background: linear-gradient(135deg, #111928, #182235);
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
}

.page-head h1, .hero h1 {
    margin: 0 0 6px;
    font-size: 26px;
    font-weight: 800;
    background: linear-gradient(to right, #ffffff, #d1d5db);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.page-head p, .hero p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}

/* Premium Buttons */
.btn, .primary, .secondary, .danger, .ghost, button {
    border: 0;
    border-radius: 16px;
    padding: 12px 18px;
    font-weight: 700;
    font-size: 15px;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.primary, .btn {
    background: var(--green);
    color: #022c22;
}
.primary:hover, .btn:hover {
    background: #059669;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}
.primary:active, .btn:active {
    transform: translateY(0);
}

.secondary {
    background: var(--card2);
    color: var(--text);
    border: 1px solid var(--border);
}
.secondary:hover {
    background: #2b394f;
    border-color: var(--border-hover);
}

.danger {
    background: rgba(244, 63, 94, 0.12);
    color: var(--red);
    border: 1px solid rgba(244, 63, 94, 0.25);
}
.danger:hover {
    background: rgba(244, 63, 94, 0.2);
    border-color: rgba(244, 63, 94, 0.35);
}

.ghost {
    background: #020617;
    color: var(--text);
    border: 1px solid var(--border);
}
.ghost:hover {
    background: #090d16;
}

.small {
    padding: 8px 12px;
    font-size: 13px;
    border-radius: 12px;
    min-height: 38px !important;
}

/* Grids & Layouts */
.grid {
    display: grid;
    gap: 14px;
}
.stats {
    grid-template-columns: 1fr 1fr;
}
.stat {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 16px;
    box-shadow: 0 4px 12px var(--shadow);
    transition: transform 0.2s ease, border-color 0.2s ease;
}
.stat:hover {
    transform: translateY(-2px);
    border-color: var(--border-hover);
}
.stat span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 8px;
    font-weight: 500;
}
.stat strong {
    color: var(--green);
    font-size: 22px;
    font-weight: 800;
}

.quick {
    grid-template-columns: 1fr 1fr;
}
.quick a {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 16px;
    display: grid;
    gap: 6px;
    transition: all 0.2s ease;
}
.quick a:hover {
    transform: translateY(-2px);
    border-color: var(--green);
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.1);
}
.quick .ico {
    font-size: 26px;
}
.quick small {
    color: var(--muted);
    font-weight: 500;
}

/* Modern Forms */
input, select, textarea {
    width: 100%;
    background: #05070c;
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 16px;
    padding: 12px 14px;
    font-size: 15px;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}
label {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 6px;
    font-weight: 500;
}
.form-grid {
    display: grid;
    gap: 14px;
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.filter-card {
    display: grid;
    gap: 12px;
}

/* Alerts styling */
.alert {
    border-radius: 18px;
    padding: 14px;
    margin-bottom: 16px;
    font-weight: 500;
    font-size: 14px;
    border: 1px solid transparent;
}
.success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--green);
    border-color: rgba(16, 185, 129, 0.2);
}
.error {
    background: rgba(244, 63, 94, 0.1);
    color: var(--red);
    border-color: rgba(244, 63, 94, 0.2);
}
.warn {
    background: rgba(245, 158, 11, 0.1);
    color: var(--yellow);
    border-color: rgba(245, 158, 11, 0.2);
}

/* Data Tables */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 16px;
}
.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 620px;
}
.data-table th, .data-table td {
    padding: 14px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    text-align: left;
    vertical-align: middle;
}
.data-table th {
    background: #05070c;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.data-table tr:last-child td {
    border-bottom: 0;
}
.data-table tr:hover td {
    background: rgba(255,255,255,0.01);
}
.muted {
    color: var(--muted);
    font-size: 13px;
}

/* Status Badges */
.badge {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 700;
    background: rgba(156, 163, 175, 0.12);
    color: var(--muted);
}
.badge.active, .badge.cleared, .badge.settled, .badge.delivered, .badge.accepted, .badge.verified {
    background: rgba(16, 185, 129, 0.12);
    color: var(--green);
}
.badge.returned, .badge.cancelled, .badge.inactive {
    background: rgba(244, 63, 94, 0.12);
    color: var(--red);
}
.badge.pending, .badge.pending_rep_accept, .badge.pending_store_verify, .badge.partially_paid {
    background: rgba(245, 158, 11, 0.12);
    color: var(--yellow);
}
.badge.collected {
    background: rgba(59, 130, 246, 0.12);
    color: var(--blue);
}

/* Premium Modal Drawers */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(2, 4, 8, 0.85);
    z-index: 100;
    display: none;
    align-items: flex-end;
    justify-content: center;
    padding: 12px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: fadeIn 0.25s ease-out;
}
.modal.show {
    display: flex;
}
.modal-box {
    width: 100%;
    max-width: 540px;
    max-height: 88vh;
    overflow: auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 28px;
    padding: 24px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.5);
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
}
.modal-head h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 800;
}
.close {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    background: #05070c;
    color: var(--text);
    border: 1px solid var(--border);
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 300;
}
.close:hover {
    background: var(--card2);
    border-color: var(--border-hover);
}

/* Premium Bottom Nav */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 560px;
    background: rgba(17, 25, 40, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    padding: 8px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 40;
}
.bottom-nav a {
    height: 56px;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    gap: 2px;
    transition: all 0.2s ease;
}
.bottom-nav a:hover {
    background: rgba(255, 255, 255, 0.04);
}
.bottom-nav a small {
    font-size: 10px;
    color: var(--muted);
    font-weight: 600;
}

/* Product Catalog */
.catalog {
    grid-template-columns: 1fr 1fr;
}
.product {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 20px;
    overflow: hidden;
    transition: transform 0.2s ease, border-color 0.2s ease;
}
.product:hover {
    transform: translateY(-2px);
    border-color: var(--border-hover);
}
.product img {
    width: 100%;
    height: 130px;
    object-fit: cover;
    background: #05070c;
}
.product .p {
    padding: 14px;
}
.product b {
    display: block;
    font-size: 15px;
    margin-bottom: 4px;
}
.product small {
    color: var(--muted);
    font-size: 12px;
}

.line {
    height: 1px;
    background: var(--border);
    margin: 16px 0;
}

.mini-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.right {
    text-align: right;
}

/* Responsive adjustments */
@media(max-width: 430px) {
    .quick, .catalog {
        grid-template-columns: 1fr;
    }
    .stats {
        grid-template-columns: 1fr 1fr;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
    .page-head h1 {
        font-size: 22px;
    }
    .data-table {
        min-width: 700px;
    }
}

@media(min-width: 700px) {
    .modal {
        align-items: center;
    }
    .app {
        border-left: 1px solid var(--border);
        border-right: 1px solid var(--border);
    }
}

.inline-link {
    color: var(--green);
    font-weight: 700;
    text-decoration: underline;
}

.checkline {
    display: flex;
    gap: 10px;
    align-items: center;
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}
.checkline input {
    width: auto;
}

/* Print View CSS */
.print-sheet {
    background: #fff;
    color: #111;
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 16px;
}
.print-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 14px;
    margin-bottom: 14px;
}
.print-head h1 {
    margin: 0;
    font-size: 26px;
    font-weight: 800;
    color: #111;
}
.print-head p {
    margin: 4px 0 0;
    color: #4b5563;
}
.print-meta {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}
.print-meta div {
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 10px;
}
.print-meta b, .print-meta span {
    display: block;
}
.print-meta b {
    font-size: 12px;
    color: #4b5563;
    text-transform: uppercase;
    margin-bottom: 2px;
}
.print-meta span {
    color: #111;
    font-weight: 600;
}
.print-table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
}
.print-table th, .print-table td {
    border: 1px solid #e5e7eb;
    padding: 10px;
    text-align: left;
    color: #111;
}
.print-table th {
    background: #f3f4f6;
    font-weight: 700;
}
.print-totals {
    max-width: 360px;
    margin-left: auto;
    display: grid;
    gap: 8px;
}
.print-totals div {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #e5e7eb;
    padding: 6px 0;
}
.signature-row {
    display: flex;
    justify-content: space-between;
    gap: 30px;
    margin-top: 48px;
}
.signature-row span {
    border-top: 1px solid #111;
    padding-top: 10px;
    min-width: 160px;
    text-align: center;
    font-weight: 600;
    font-size: 13px;
}
.no-print {
    display: inline-flex;
}
.mini-actions a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

@media print {
    body {
        background: #fff !important;
        color: #111 !important;
    }
    .topbar, .bottom-nav, .no-print, .filter-card, .primary, .secondary, .primary.small, .main>.page-head button, .modal {
        display: none !important;
    }
    .app {
        max-width: none !important;
        padding: 0 !important;
    }
    .main {
        padding: 0 !important;
    }
    .card, .table-card, .print-sheet {
        box-shadow: none !important;
        border: none !important;
        background: #fff !important;
        color: #111 !important;
    }
    .data-table th, .data-table td {
        color: #111 !important;
        border-color: #d1d5db !important;
    }
    .data-table th {
        background: #f3f4f6 !important;
    }
    .muted {
        color: #4b5563 !important;
    }
    a {
        color: #111 !important;
    }
}

/* Settings & Permission styling improvements */
.permissions-table select {
    min-width: 96px;
    padding: 8px;
    font-size: 13px;
    border-radius: 12px;
}
.settings-table input {
    min-width: 95px;
}
.settings-table td:last-child {
    min-width: 150px;
}
.view-only form button.primary, .view-only form button.danger {
    opacity: 0.55;
    pointer-events: none;
}
.view-only .page-head .primary {
    display: none;
}

/* System Dialog Alerts */
.system-dialog {
    position: fixed;
    inset: 0;
    background: rgba(2, 4, 8, 0.85);
    z-index: 250;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: fadeIn 0.2s ease-out;
}
.system-dialog.show {
    display: flex;
}
.system-dialog-box {
    width: 100%;
    max-width: 420px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 26px;
    padding: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: scaleIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.system-dialog-box h3 {
    margin: 0 0 10px;
    font-size: 20px;
    font-weight: 800;
}
.system-dialog-box p {
    margin: 0 0 20px;
    color: var(--muted);
    line-height: 1.6;
    font-size: 14px;
}
.dialog-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}
.dialog-actions button {
    min-width: 90px;
}
.permission-pill {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(16, 185, 129, 0.12);
    color: var(--green);
    font-size: 12px;
    font-weight: 700;
}

.menu-grid {
    margin-top: 14px;
}
.menu-grid a small {
    color: var(--muted);
}

/* mobile forms styling */
input, select, textarea, button, .primary, .secondary, .danger, .ghost {
    min-height: 48px;
}
textarea {
    min-height: 96px;
    resize: vertical;
}
.mobile-form {
    gap: 16px;
}
.mobile-rows {
    display: grid;
    gap: 14px;
}
.entry-card {
    background: #05070c;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 16px;
    display: grid;
    gap: 12px;
}
.mobile-section-title {
    color: var(--green);
    font-weight: 800;
    font-size: 15px;
    margin-top: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.discount-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.row-note {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    color: var(--muted);
    font-size: 13px;
}
.row-note b {
    color: var(--green);
    white-space: nowrap;
}
.remove-wide {
    width: 100%;
}
.cheque-fields {
    display: none;
    gap: 12px;
}
.total-box {
    background: #05070c;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 16px;
    display: grid;
    gap: 10px;
}
.total-box div {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 14px;
}
.total-box .big {
    border-top: 1px solid var(--border);
    padding-top: 10px;
    font-size: 16px;
    font-weight: 700;
}
.ok-text {
    color: var(--green);
}
.warn-text {
    color: var(--yellow);
}
.mobile-line-summary {
    background: #05070c;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 12px;
    margin-bottom: 8px;
    display: grid;
    gap: 4px;
}
.mobile-line-summary span {
    color: var(--muted);
    font-size: 12px;
}
.full-sheet .modal-box {
    max-height: 92vh;
}
.data-table td .mini-actions .small {
    min-height: 38px;
}

/* Chequeflow, cards, chain styling */
select option {
    background: #0b1220;
    color: var(--text);
}
.stat strong {
    word-break: break-all;
}
.diff-pos {
    color: var(--green);
    font-weight: 700;
}
.diff-neg {
    color: var(--red);
    font-weight: 700;
}
.diff-zero {
    color: var(--muted);
    font-weight: 700;
}
.entry-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}
.entry-title b {
    color: var(--text);
    font-size: 14px;
}
.qty-compare {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: var(--muted);
    font-size: 13px;
    margin-top: -2px;
}
.qty-compare b {
    color: var(--text);
}
.empty-hint {
    color: var(--muted);
    font-size: 14px;
    text-align: center;
    padding: 24px 8px;
}
.chq-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 16px;
    display: grid;
    gap: 12px;
    margin-bottom: 14px;
}
.payment-row {
    display: grid;
    gap: 12px;
}
.chq-chain {
    margin-top: 4px;
    padding-left: 16px;
    border-left: 2px dashed var(--border);
    display: grid;
    gap: 12px;
}
.chq-node {
    background: #05070c;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px;
    display: grid;
    gap: 10px;
}
.chq-node-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.chq-node-head b {
    font-size: 14px;
}
.chq-amounts {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    font-size: 12px;
    color: var(--muted);
}
.chq-amounts b {
    display: block;
    color: var(--text);
    font-size: 14px;
    margin-top: 2px;
}
.chq-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.chq-actions form {
    display: flex;
    gap: 8px;
    align-items: center;
}
.chq-actions select {
    min-width: 122px;
}

/* Quick links grids */
.grid.quick-links {
    grid-template-columns: repeat(3, 1fr);
}
.quick-links a {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 14px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-align: center;
    min-height: 90px;
}
.quick-links .ico {
    font-size: 26px;
}
.quick-links small {
    color: var(--muted);
    font-size: 11px;
}

@media(max-width: 430px) {
    .grid.quick-links {
        grid-template-columns: repeat(3, 1fr);
    }
    .chq-amounts {
        grid-template-columns: repeat(3, 1fr);
    }
}
@media(max-width: 360px) {
    .chq-amounts {
        grid-template-columns: 1fr 1fr;
    }
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
@keyframes scaleIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
