:root {
    --bg: #f4f7fb;
    --card-bg: #ffffff;
    --primary: #2f6fed;
    --primary-dark: #1e4fb8;
    --accent: #eaf1ff;
    --text: #2b2f38;
    --text-muted: #7a8291;
    --border: #e3e8ef;
    --success: #2fb380;
    --danger: #e5484d;
    --header-text: #ffffff; /* screen-name label rendered low-contrast/white per spec */
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', 'Segoe UI', Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-weight: 600; margin-top: 0; }
h2 { font-size: 20px; }
h3 { font-size: 16px; color: var(--text); }

a { color: var(--primary); }

.marquee-bar {
    background: var(--primary);
    color: #fff;
    padding: 6px 0;
    font-size: 14px;
    font-weight: 500;
}

.topbar {
    background: var(--primary-dark);
    color: var(--header-text);
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.topbar-title {
    font-size: 15px;
    font-weight: 500;
    color: var(--header-text); /* white / low-contrast, de-emphasized */
    opacity: 0.85;
}

.topbar-left {
    display: flex;
    align-items: center;
}

.topbar-actions a {
    color: #fff;
    margin-left: 16px;
    text-decoration: none;
}

.subnav {
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    gap: 4px;
}
.subnav a {
    display: inline-block;
    padding: 12px 14px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    border-bottom: 2px solid transparent;
}
.subnav a:hover { color: var(--primary); border-bottom-color: var(--accent); }

/* ===== Sidebar layout (tenant pages) ===== */

.layout {
    display: flex;
    align-items: stretch;
    min-height: calc(100vh - 46px);
}

.sidebar {
    width: 230px;
    flex-shrink: 0;
    background: #fff;
    border-right: 1px solid var(--border);
    padding: 18px 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px 18px 20px;
    font-weight: 700;
    font-size: 14px;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    margin-bottom: 10px;
}
.sidebar-brand .dot {
    display: inline-block;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3a3f47, #1a1d22);
    border: 1px solid #4caf50;
    color: #4caf50;
    font-weight: 700;
    font-size: 11px;
    line-height: 26px;
    text-align: center;
}
.sidebar-logo-img {
    max-height: 32px;
    max-width: 40px;
    object-fit: contain;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    border-left: 3px solid transparent;
}
.sidebar nav a .icon { font-size: 16px; width: 18px; text-align: center; }
.sidebar nav a:hover { background: var(--accent); color: var(--primary-dark); }
.sidebar nav a.active {
    background: var(--accent);
    color: var(--primary-dark);
    border-left-color: var(--primary);
}

.main-content { flex: 1; min-width: 0; }
.main-content .app-body { max-width: 1100px; margin: 0; padding: 24px; }

.sidebar-backdrop { display: none; }

.menu-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 34px;
    height: 34px;
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    margin-right: 12px;
}
.menu-toggle span {
    display: block;
    height: 2px;
    width: 20px;
    margin: 0 auto;
    background: #fff;
}

@media (max-width: 900px) {
    .menu-toggle { display: flex; }
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 4px 0 16px rgba(0,0,0,0.1);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-backdrop {
        display: none;
        position: fixed; inset: 0;
        background: rgba(0,0,0,0.35);
        z-index: 40;
    }
    .sidebar-backdrop.open { display: block; }
    .main-content .app-body { padding: 16px; }
}

.app-body {
    padding: 24px;
    max-width: 1200px;
    margin: 0 auto;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}

label {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

input, select, textarea {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.btn {
    display: inline-block;
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
}

.btn:hover { background: var(--primary-dark); }
.btn-secondary { background: #eef1f6; color: var(--text); }
.btn-danger { background: var(--danger); }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th, td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

th {
    background: var(--accent);
    color: var(--primary-dark);
    font-weight: 600;
}

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.badge-active { background: #e3f7ee; color: var(--success); }
.badge-blocked { background: #fdeaea; color: var(--danger); }
.badge-trial { background: #fff6e0; color: #b8860b; }

.alert {
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
}
.alert-error { background: #fdeaea; color: var(--danger); }
.alert-success { background: #e3f7ee; color: var(--success); }

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #eaf1ff 0%, #f4f7fb 60%);
    padding: 24px;
}

.auth-wrap {
    max-width: 420px;
    width: 100%;
}

.auth-wrap .card {
    box-shadow: 0 10px 30px rgba(47,111,237,0.12);
    border: none;
    padding: 32px;
}

.auth-logo {
    text-align: center;
    margin-bottom: 18px;
}

.auth-logo .dot {
    display: inline-block;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3a3f47, #1a1d22);
    border: 2px solid #4caf50;
    color: #4caf50;
    font-weight: 700;
    font-size: 17px;
    line-height: 44px;
}

.auth-wrap .btn {
    width: 100%;
    padding: 11px;
    font-weight: 600;
    margin-top: 6px;
}

.auth-wrap form label { margin-top: 10px; }
.auth-wrap p a { font-size: 13px; }

.nav-links {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.nav-links .btn { padding: 9px 16px; }

.stat-value { font-size: 28px; font-weight: 700; color: var(--primary); margin: 4px 0; }
.stat-label { color: var(--text-muted); font-size: 13px; }

/* ===== Transactional screens (Purchase / Sales / POS) ===== */

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

@media (max-width: 900px) {
    .txn-layout { grid-template-columns: 1fr; }
}

.txn-header-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.txn-header-grid label { margin-bottom: 3px; }

.add-item-row {
    display: grid;
    grid-template-columns: 110px 1fr 90px 100px 90px 90px 90px;
    gap: 8px;
    align-items: end;
    background: var(--accent);
    padding: 14px;
    border-radius: 8px;
    margin-bottom: 16px;
}

.add-item-row label { font-size: 11px; margin-bottom: 3px; white-space: nowrap; }
.add-item-row input { padding: 7px 8px; font-size: 13px; }

@media (max-width: 900px) {
    .add-item-row { grid-template-columns: repeat(2, 1fr); }
}

.scan-row {
    display: flex !important;
    flex-wrap: wrap;
    align-items: end;
}
.scan-row > div { flex: 1 1 90px; }
.scan-row > .scan-col { flex: 2 1 200px; }

/* Discount fields/columns are hidden from cashiers by default; JS toggles the
   [hidden] attribute after a successful admin unlock. !important guarantees
   this wins even over elements that set their own display type (flex/table-cell). */
[hidden] { display: none !important; }
.scan-input {
    font-size: 18px !important;
    font-weight: 700;
    padding: 12px 10px !important;
    border: 2px solid var(--primary) !important;
    background: #fff !important;
}
.scan-input:focus { box-shadow: 0 0 0 3px rgba(47,111,237,0.15); }
@media (max-width: 900px) {
    .scan-row { grid-template-columns: repeat(2, 1fr); }
}

.purchase-item-row { grid-template-columns: 100px minmax(150px, 1.5fr) 60px 85px 85px 85px 70px 70px 85px 85px; }
@media (max-width: 1100px) {
    .purchase-item-row { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 600px) {
    .purchase-item-row { grid-template-columns: repeat(2, 1fr); }
}

.line-table-wrap { overflow-x: auto; }

.line-table { min-width: 100%; }
.line-table th { font-size: 12px; white-space: nowrap; }
.line-table td { font-size: 13px; white-space: nowrap; }
.line-table .row-remove {
    color: var(--danger); cursor: pointer; font-weight: 700; background: #fdeaea;
    border: 1px solid var(--danger); border-radius: 5px; font-size: 15px;
    width: 26px; height: 26px; line-height: 1; padding: 0;
}
.line-table .row-remove:hover { background: var(--danger); color: #fff; }
.inline-qty { padding: 4px 6px !important; font-size: 13px !important; }

.totals-panel {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    position: sticky;
    top: 20px;
}

.totals-panel .row {
    display: flex;
    justify-content: space-between;
    padding: 7px 0;
    font-size: 14px;
    border-bottom: 1px dashed var(--border);
}
.totals-panel .row:last-of-type { border-bottom: none; }
.totals-panel .row.grand {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary-dark);
    border-top: 2px solid var(--border);
    margin-top: 6px;
    padding-top: 12px;
}

.bill-type-row {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    flex-wrap: wrap;
}
.bill-type-btn {
    flex: 1;
    min-width: 90px;
    padding: 10px;
    border-radius: 6px;
    border: 2px solid var(--border);
    background: #fff;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    text-align: center;
}
.bill-type-btn.active {
    border-color: var(--primary);
    background: var(--accent);
    color: var(--primary-dark);
}

.empty-row td {
    text-align: center;
    color: var(--text-muted);
    padding: 24px;
    font-style: italic;
}

.item-picker-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 100;
    align-items: center;
    justify-content: center;
}
.item-picker-modal .picker-box {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    width: 100%;
    max-width: 420px;
    max-height: 80vh;
    overflow-y: auto;
}
.picker-option {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    text-align: left;
    padding: 12px 14px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
}
.picker-option:hover { border-color: var(--primary); background: var(--accent); }
.picker-option span { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

/* Global print styling - hides app chrome on any page, not just invoices */
@media print {
    .no-print, .topbar, .marquee-bar, .sidebar, .menu-toggle, .sidebar-backdrop, .subnav { display: none !important; }
    .main-content .app-body, .app-body { padding: 0; max-width: none; margin: 0; }
    body { background: #fff; }
    .card { box-shadow: none; border: 1px solid #ccc; }
}

/* Reusable report action toolbar (Print / Export / WhatsApp) */
.report-toolbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.report-toolbar .btn { font-size: 13px; }
