:root {
    --olive-950: #1b2410;
    --olive-900: #283618;
    --olive-800: #384A22;
    --olive-700: #4A602D;
    --olive-100: #E9EDC9;
    --beige-50: #FDFBF7;
    --beige-100: #F7F3E9;
    --beige-200: #EFE8D8;
    --beige-300: #DDD2BC;
    --gold: #BC6C25;
    --gold-bright: #DDA15E;
    --red: #C53030;
    --red-bg: #FFF5F5;
    --green: #22543D;
    --green-bg: #F0FFF4;
    --blue: #1E3A8A;
    --blue-bg: #EFF6FF;
    --purple: #553C9A;
    --purple-bg: #FAF5FF;
    --teal: #0F766E;
    --teal-bg: #F0FDFA;
    --text-dark: #2D3748;
    --text-muted: #718096;
    --white: #FFFFFF;
    --border: #E2E8F0;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
    max-width: 100%;
    overflow-x: hidden;
}
body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--beige-50);
    color: var(--text-dark);
    line-height: 1.5;
    direction: rtl;
    padding-bottom: 50px;
}

/* Auth / Login & Blocked Screens */
.auth-overlay {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(145deg, var(--olive-950) 0%, var(--olive-900) 55%, var(--olive-800) 100%);
}
.auth-card {
    background: var(--beige-50);
    border: 2px solid var(--gold-bright);
    border-radius: 18px;
    padding: 28px 24px;
    width: 100%;
    max-width: 410px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.4);
    text-align: center;
}
.auth-logo {
    width: 76px;
    height: 76px;
    margin: 0 auto 12px auto;
    border-radius: 18px;
    overflow: hidden;
    border: 2px solid var(--gold-bright);
    background: var(--olive-950);
    display: flex;
    align-items: center;
    justify-content: center;
}
.auth-title { font-size: 22px; font-weight: 900; color: var(--olive-900); }
.auth-sub { font-size: 12.5px; color: var(--text-muted); margin-bottom: 18px; }
.auth-error {
    background: var(--red-bg);
    border: 1px solid #FC8181;
    color: var(--red);
    padding: 9px 12px;
    border-radius: 9px;
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 12px;
    display: none;
    text-align: right;
}

/* Top Header */
header {
    background: linear-gradient(135deg, var(--olive-950), var(--olive-900));
    color: var(--white);
    padding: 10px 18px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.22);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 2px solid var(--gold);
    max-width: 100%;
}
.header-container {
    max-width: 1380px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}
.brand-box { display: flex; align-items: center; gap: 10px; min-width: 0; max-width: 100%; }
.brand-logo-container {
    width: 48px; height: 48px;
    background: var(--olive-950);
    border-radius: 13px;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid var(--gold-bright);
    overflow: hidden; cursor: pointer; flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.brand-logo-img { width: 100%; height: 100%; object-fit: cover; }
.brand-title {
    font-size: 17px; font-weight: 900; color: var(--beige-100);
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.brand-sub {
    font-size: 11px; color: var(--gold-bright); font-weight: 600;
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 2px;
}
.station-select-header {
    background: rgba(255,255,255,0.12); color: #FFF;
    border: 1px solid var(--gold-bright); border-radius: 7px;
    padding: 3px 8px; font-size: 11.5px; font-weight: 700; cursor: pointer; width: auto;
}
.station-select-header option { color: #000; background: #FFF; }
.btn-mini {
    background: var(--olive-800); border: 1px solid var(--olive-700);
    color: var(--beige-200); font-size: 10.5px; padding: 3px 8px;
    border-radius: 6px; cursor: pointer; font-weight: 700;
}

/* Nav Tabs */
nav {
    display: flex; gap: 4px; background: rgba(0,0,0,0.25);
    padding: 4px; border-radius: 11px; overflow-x: auto; max-width: 100%;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.nav-btn {
    background: transparent; border: none; color: var(--beige-100);
    padding: 7px 11px; font-size: 12px; font-weight: 700;
    border-radius: 8px; cursor: pointer; white-space: nowrap; transition: all 0.2s;
    flex-shrink: 0;
}
.nav-btn.active {
    background: var(--beige-100); color: var(--olive-900);
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

/* Header Actions */
.header-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; max-width: 100%; }
.btn-action {
    background: var(--olive-800); color: var(--white);
    border: 1px solid var(--olive-700); padding: 6px 10px;
    border-radius: 8px; font-size: 11.5px; font-weight: 700;
    cursor: pointer; display: inline-flex; align-items: center; gap: 4px;
}
.btn-action:hover { background: var(--olive-700); }
.btn-logout { background: #7F1D1D; border-color: #991B1B; }
.btn-logout:hover { background: #991B1B; }
.user-pill {
    font-size: 11px; font-weight: 800; color: var(--beige-100);
    background: rgba(255,255,255,0.1); padding: 4px 10px;
    border-radius: 20px; border: 1px solid rgba(221,161,94,0.4);
    max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sync-badge {
    font-size: 10.5px; padding: 3px 9px; border-radius: 20px;
    font-weight: 800; display: inline-flex; align-items: center; gap: 4px;
}
.sync-online { background: #065F46; color: #A7F3D0; border: 1px solid #10B981; }
.sync-offline { background: #9A3412; color: #FED7AA; border: 1px solid #F97316; }

/* Main Container */
main { max-width: 1380px; margin: 18px auto; padding: 0 14px; width: 100%; }

/* Card System */
.card {
    background: var(--white); border: 1px solid var(--beige-300);
    border-radius: 14px; padding: 18px;
    box-shadow: 0 4px 14px rgba(40,54,24,0.06); margin-bottom: 18px;
    min-width: 0; max-width: 100%;
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--beige-200); padding-bottom: 10px;
    margin-bottom: 14px; flex-wrap: wrap; gap: 8px;
}
.card-title { font-size: 15.5px; font-weight: 800; color: var(--olive-900); }

/* Forms */
.form-group { margin-bottom: 11px; text-align: right; min-width: 0; max-width: 100%; }
label { display: block; font-size: 12px; font-weight: 700; color: var(--text-dark); margin-bottom: 4px; }
input, select, textarea {
    width: 100%; max-width: 100%; min-width: 0;
    padding: 9px 11px; border-radius: 9px;
    border: 1px solid #CBD5E0; background: #FAFAFA;
    font-size: 13.5px; color: var(--text-dark); direction: rtl;
}
select {
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--olive-700); background: #FFF;
    box-shadow: 0 0 0 3px rgba(74,96,45,0.15);
}

.btn-primary {
    background: var(--olive-900); color: var(--white); border: none;
    padding: 10px 14px; border-radius: 10px; font-size: 13px;
    font-weight: 700; cursor: pointer; width: 100%; min-height: 40px;
    box-shadow: 0 2px 8px rgba(40,54,24,0.2); transition: background 0.2s;
}
.btn-primary:hover { background: var(--olive-800); }
.btn-gold {
    background: var(--gold); color: var(--white); border: none;
    padding: 9px 14px; border-radius: 9px; font-size: 12.5px;
    font-weight: 700; cursor: pointer; min-height: 38px;
}
.btn-gold:hover { background: #9C571B; }
.btn-danger {
    background: var(--red); color: var(--white); border: none;
    padding: 10px 14px; border-radius: 10px; font-size: 13px;
    font-weight: 700; cursor: pointer; width: 100%; min-height: 40px;
}
.btn-print {
    background: #0F766E; color: white; border: none;
    padding: 5px 9px; border-radius: 6px; font-size: 11.5px;
    font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 3px;
}
.btn-wa {
    background: #15803D; color: white; border: none;
    padding: 5px 9px; border-radius: 6px; font-size: 11.5px;
    font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 3px;
}
.btn-edit {
    background: #D97706; color: white; border: none;
    padding: 5px 9px; border-radius: 6px; font-size: 11.5px;
    font-weight: 700; cursor: pointer;
}
.btn-blue {
    background: #1E3A8A; color: white; border: none;
    padding: 6px 10px; border-radius: 6px; font-size: 11.5px;
    font-weight: 700; cursor: pointer;
}

/* Grids (min-width: 0 prevents grid children from blowing out mobile width!) */
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.layout-pos { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 18px; }
.layout-pos > *, .grid-2 > *, .grid-3 > *, .grid-4 > * { min-width: 0; max-width: 100%; }

/* KPI Boxes */
.kpi-box {
    background: var(--white); border: 1px solid var(--beige-300);
    border-radius: 12px; padding: 13px; text-align: right;
    min-width: 0; max-width: 100%;
}
.kpi-label { font-size: 11.5px; font-weight: 700; color: var(--text-muted); }
.kpi-val { font-size: 18px; font-weight: 900; color: var(--olive-900); margin: 3px 0; word-break: break-word; }
.kpi-desc { font-size: 10.5px; color: var(--text-muted); }

/* Tables */
.table-wrap {
    overflow-x: auto; width: 100%; max-width: 100%;
    -webkit-overflow-scrolling: touch;
}
table { width: 100%; border-collapse: collapse; font-size: 12.5px; text-align: right; }
th {
    background: var(--beige-100); color: var(--text-dark);
    font-weight: 800; padding: 9px 10px;
    border-bottom: 2px solid var(--beige-300); white-space: nowrap;
}
td { padding: 9px 10px; border-bottom: 1px solid #EDF2F7; }
tr:hover { background: var(--beige-50); }

/* Badges */
.badge { display: inline-block; padding: 2px 7px; border-radius: 6px; font-size: 10.5px; font-weight: 700; }
.badge-green { background: var(--green-bg); color: var(--green); border: 1px solid #C6F6D5; }
.badge-red { background: var(--red-bg); color: var(--red); border: 1px solid #FED7D7; }
.badge-gold { background: #FEFCBF; color: #744210; border: 1px solid #FAF089; }
.badge-blue { background: var(--blue-bg); color: var(--blue); border: 1px solid #BFDBFE; }
.badge-purple { background: var(--purple-bg); color: var(--purple); border: 1px solid #E9D8FD; }
.badge-teal { background: var(--teal-bg); color: var(--teal); border: 1px solid #99F6E4; }
.badge-gray { background: #EDF2F7; color: #4A5568; }

/* Alert Banner */
.conflict-alert {
    background: #FFF5F5; border: 1.5px solid #FC8181; color: #9B2C2C;
    padding: 10px 12px; border-radius: 10px; font-size: 12px;
    margin-bottom: 12px; display: none;
}

/* Gift / Discount / Split Box */
.gift-box-panel {
    background: #FFFBEB; border: 1px dashed #F59E0B;
    border-radius: 10px; padding: 10px; margin-top: 6px; margin-bottom: 8px;
}

/* Permission Checkboxes Grid */
.perm-grid {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px;
    margin: 10px 0;
}
.perm-item {
    display: flex; align-items: center; gap: 8px;
    background: var(--beige-50); border: 1px solid var(--beige-300);
    padding: 8px 10px; border-radius: 8px; cursor: pointer;
    font-size: 12px; font-weight: 700; margin: 0;
}
.perm-item input[type="checkbox"] { width: 17px; height: 17px; cursor: pointer; flex-shrink: 0; }

/* Dynamic Lists Chips */
.list-item-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 8px; padding: 8px 10px; border-bottom: 1px solid #EDF2F7;
}
.list-item-row:last-child { border-bottom: none; }

/* Toast Notification */
#toastBox {
    position: fixed; bottom: 24px; left: 20px;
    background: var(--olive-900); color: #FFF; padding: 12px 18px;
    border-radius: 10px; border-right: 5px solid var(--gold-bright);
    font-size: 13px; font-weight: 700; box-shadow: 0 8px 24px rgba(0,0,0,0.28);
    z-index: 3000; display: none; max-width: calc(100vw - 40px);
    animation: slideUp 0.25s ease-out;
}
@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Modal */
.modal {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.58); display: none;
    align-items: center; justify-content: center; z-index: 1500; padding: 14px;
}
.modal.open { display: flex; }
.modal-card {
    background: var(--white); border-radius: 14px; width: 100%;
    max-width: 680px; padding: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.28);
    max-height: 92vh; overflow-y: auto;
}
.modal-actions {
    display: flex; justify-content: flex-end; gap: 8px;
    margin-top: 16px; padding-top: 12px; border-top: 1px solid #EDF2F7;
}
.btn-secondary {
    background: #E2E8F0; border: none; color: #4A5568;
    padding: 8px 14px; border-radius: 8px; font-size: 12.5px;
    font-weight: 700; cursor: pointer; min-height: 36px;
}

/* Filter Pill Bar */
.filter-bar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.filter-pill {
    background: var(--beige-100); border: 1px solid var(--beige-300);
    color: var(--olive-900); padding: 6px 13px; border-radius: 20px;
    font-size: 12px; font-weight: 700; cursor: pointer;
}
.filter-pill.active { background: var(--olive-900); color: #FFF; border-color: var(--olive-900); }

/* Mobile Responsive (< 960px and < 768px) */
@media (max-width: 960px) {
    .layout-pos { grid-template-columns: minmax(0, 1fr); }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
    .perm-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 768px) {
    header { padding: 8px 10px; }
    .header-container { gap: 8px; }
    .brand-logo-container { width: 40px; height: 40px; }
    .brand-title { font-size: 14.5px; }
    nav { width: 100%; }
    .header-actions { width: 100%; justify-content: space-between; }
    main { padding: 0 10px; margin: 12px auto; }
    .card { padding: 14px 12px; border-radius: 12px; }
    input, select, textarea { font-size: 16px !important; padding: 10px 11px; }
    #clientSearchInput { width: 100% !important; }
    .nav-btn { padding: 8px 10px; font-size: 12px; }
    #toastBox { bottom: 16px; left: 12px; right: 12px; text-align: center; }
}

/* Print Areas */
#receiptPrintArea, #statementPrintArea { display: none; }
@media print {
    body * { visibility: hidden; }
    body.printing-receipt #receiptPrintArea, body.printing-receipt #receiptPrintArea * { visibility: visible; }
    body.printing-receipt #receiptPrintArea {
        display: block !important; position: absolute; top: 0; left: 0;
        width: 78mm; padding: 4mm; font-family: system-ui, sans-serif;
        direction: rtl; text-align: center; color: #000; background: #FFF;
    }
    .receipt-header { border-bottom: 1px dashed #000; padding-bottom: 6px; margin-bottom: 6px; }
    .receipt-logo { max-width: 54px; max-height: 54px; margin: 0 auto 4px auto; display: block; }
    .receipt-title { font-size: 16px; font-weight: bold; margin-bottom: 2px; }
    .receipt-sub { font-size: 11px; }
    .receipt-row { display: flex; justify-content: space-between; font-size: 11px; margin-bottom: 3px; }
    .receipt-table { width: 100%; border-collapse: collapse; margin: 6px 0; font-size: 11px; }
    .receipt-table th, .receipt-table td { border-bottom: 1px solid #000; padding: 4px 2px; text-align: right; }
    .receipt-total { border-top: 1px dashed #000; padding-top: 6px; font-size: 13px; font-weight: bold; display: flex; justify-content: space-between; }
    .receipt-footer { font-size: 10px; margin-top: 10px; border-top: 1px dashed #000; padding-top: 6px; }

    /* A4 Statement Print */
    body.printing-statement #statementPrintArea, body.printing-statement #statementPrintArea * { visibility: visible; }
    body.printing-statement #statementPrintArea {
        display: block !important; position: absolute; top: 0; left: 0; right: 0;
        width: 100%; padding: 15mm; font-family: Tahoma, system-ui, sans-serif;
        direction: rtl; color: #000; background: #FFF;
    }
    .stmt-header { border-bottom: 2px solid #283618; padding-bottom: 10px; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; }
    .stmt-table { width: 100%; border-collapse: collapse; margin-bottom: 14px; font-size: 11px; }
    .stmt-table th { background: #E9EDC9; color: #000; border: 1px solid #999; padding: 6px; text-align: right; }
    .stmt-table td { border: 1px solid #CCC; padding: 5px 6px; text-align: right; }
    .stmt-summary { border: 1.5px solid #283618; padding: 10px; border-radius: 8px; background: #FDFBF7; font-size: 12px; }
}