:root {
    --primary: #c0392b;
    --primary-dark: #96281b;
    --secondary: #8B6914;
    --gold: #d4af37;
    --bg: #f5f5f5;
    --surface: #ffffff;
    --text: #212121;
    --text-secondary: #757575;
    --border: #e0e0e0;
    --success: #27ae60;
    --warning: #f39c12;
    --danger: #e74c3c;
    --shadow: 0 2px 8px rgba(0,0,0,0.15);
    --header-height: 56px;
    --nav-height: 60px;
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

/* Status Bar */
.status-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--warning);
    color: white;
    text-align: center;
    padding: 4px;
    font-size: 12px;
}
.status-bar.online { background: var(--success); }
.status-bar.hidden { display: none; }

/* Header */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    padding: 0 16px;
    z-index: 100;
    box-shadow: var(--shadow);
}
.header-logo {
    height: 36px;
    width: auto;
    border-radius: 4px;
}
.header-title {
    flex: 1;
    text-align: center;
    font-size: 18px;
    font-weight: 600;
}
.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}
/* Printer Button */
.printer-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    padding: 4px 6px;
    border-radius: 6px;
    transition: background 0.2s, opacity 0.2s;
    color: white;
    position: relative;
}
.printer-btn:active { background: rgba(255,255,255,0.2); }
.printer-disconnected { opacity: 0.6; }
.printer-connected { opacity: 1; }
.printer-connecting { opacity: 0.8; animation: printer-pulse 1s infinite; }
@keyframes printer-pulse {
    0%, 100% { opacity: 0.8; }
    50%       { opacity: 0.4; }
}

.online-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4caf50;
    border: 2px solid rgba(255,255,255,0.5);
    transition: background 0.3s;
}
.online-dot.offline { background: #f44336; }
.sync-badge {
    background: var(--gold);
    color: #000;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: bold;
}

/* Main */
.app-main {
    position: fixed;
    top: var(--header-height);
    bottom: var(--nav-height);
    left: 0;
    right: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Pages */
.page {
    display: none;
    padding: 12px;
    min-height: 100%;
}
.page.active { display: block; }

/* Bottom Nav */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 100;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
}
.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    gap: 2px;
    transition: color 0.2s;
}
.nav-item.active { color: var(--primary); }
.nav-icon { font-size: 22px; }
.nav-label { font-size: 10px; font-weight: 500; }

/* Dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}
.stat-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.1s;
}
.stat-card:active { transform: scale(0.97); }
.stat-icon { font-size: 28px; margin-bottom: 8px; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.section-title { font-size: 16px; font-weight: 600; margin: 8px 0; color: var(--text); }

/* List */
.list-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: 80px;
}
.list-item {
    background: var(--surface);
    border-radius: 10px;
    padding: 12px 16px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}
.list-item:active { background: #f5f5f5; }
.list-item-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(192,57,43,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.list-item-body {
    flex: 1;
    min-width: 0;
}
.list-item-title {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.list-item-sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}
.list-item-right {
    text-align: right;
    flex-shrink: 0;
}
.list-item-price {
    font-weight: 700;
    color: var(--primary);
    font-size: 15px;
}
.list-item-meta {
    font-size: 11px;
    color: var(--text-secondary);
}

/* Search */
.search-bar { margin-bottom: 12px; }
.search-bar input {
    width: 100%;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 25px;
    font-size: 14px;
    background: var(--surface);
    outline: none;
}
.search-bar input:focus { border-color: var(--primary); }

/* FAB */
.fab {
    position: fixed;
    bottom: calc(var(--nav-height) + 16px);
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(192,57,43,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    transition: transform 0.1s, box-shadow 0.1s;
    line-height: 1;
}
.fab:active {
    transform: scale(0.93);
    box-shadow: 0 2px 6px rgba(192,57,43,0.3);
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
}
.modal {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    z-index: 201;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}
.modal.hidden { display: none; }
.modal-overlay.hidden { display: none; }
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 18px; }
.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-secondary);
}
.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}
.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}

/* Bottom Sheet */
.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    z-index: 201;
    max-height: 95vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
}
.bottom-sheet.hidden { display: none; }
.sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 12px auto 0;
}
.sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
}
.sheet-header h3 { font-size: 16px; font-weight: 600; }
.sheet-header button {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
}
.sheet-body {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
    padding-bottom: 30px;
}

/* Forms */
.form-group { margin-bottom: 14px; }
.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}
.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    background: white;
    transition: border-color 0.2s;
    font-family: inherit;
}
.form-control:focus { border-color: var(--primary); }
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.1s, transform 0.1s;
    font-family: inherit;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline {
    background: none;
    border: 1.5px solid var(--primary);
    color: var(--primary);
}
.btn-danger { background: var(--danger); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* Location button */
.location-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1.5px dashed var(--primary);
    border-radius: 8px;
    background: rgba(192,57,43,0.05);
    color: var(--primary);
    font-size: 13px;
    cursor: pointer;
    width: 100%;
    justify-content: center;
    margin-top: 4px;
    font-family: inherit;
}
.location-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* Bill Builder */
.bill-shop-header {
    background: rgba(192,57,43,0.08);
    border: 1px solid rgba(192,57,43,0.2);
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 10px;
    font-size: 13px;
    font-weight: 600;
    color: var(--primary-dark);
}

/* Bill sections - clearly separated */
.bill-section {
    border-radius: 10px;
    margin-bottom: 10px;
    overflow: visible;
}
.bill-search-section {
    background: #e8f4fd;
    border: 1.5px solid #90caf9;
    padding: 10px;
}
.bill-added-section {
    background: #f1f8e9;
    border: 1.5px solid #a5d6a7;
    padding: 10px;
}
.bill-section-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    color: var(--text-secondary);
}
.bill-search-section .bill-section-label { color: #1565c0; }
.bill-added-section  .bill-section-label { color: #2e7d32; }
.cost-type-select {
    font-size: 11px;
    padding: 2px 6px;
    border: 1px solid #90caf9;
    border-radius: 6px;
    background: white;
    color: #1565c0;
    font-weight: 600;
    cursor: pointer;
    outline: none;
}
.bill-count-badge {
    background: var(--primary);
    color: white;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 700;
    min-width: 24px;
    text-align: center;
}

/* Search input inside blue section */
.bill-search-section .form-control {
    border-color: #90caf9;
    background: white;
}
.bill-search-section .form-control:focus { border-color: #1565c0; }

.item-search-container,
.shop-search-wrap {
    position: relative;
}
.suggestions-list.hidden { display: none; }
.suggestions-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: white;
    border: 2px solid #1565c0;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(21,101,192,0.2);
    z-index: 50;
    max-height: 200px;
    overflow-y: auto;
}
.suggestion-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover,
.suggestion-item:active { background: #e3f2fd; }
.suggestion-item-name  { font-weight: 600; }
.suggestion-item-price { color: var(--primary); font-weight: 700; font-size: 12px; }

/* Added items table inside green section */
.bill-items-table {
    border: 1px solid #a5d6a7;
    border-radius: 8px;
    overflow: hidden;
    background: white;
}
.bill-items-header {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 28px;
    background: #2e7d32;
    color: white;
    padding: 7px 10px;
    font-size: 11px;
    font-weight: 700;
    gap: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.bill-item-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 28px;
    padding: 7px 10px;
    border-bottom: 1px solid #e8f5e9;
    font-size: 12px;
    align-items: center;
    gap: 4px;
    background: white;
}
.bill-item-row:nth-child(even) { background: #f9fbe7; }
.bill-item-row:last-child { border-bottom: none; }
.bill-item-row input {
    width: 100%;
    padding: 3px 4px;
    border: 1px solid #a5d6a7;
    border-radius: 4px;
    text-align: right;
    font-size: 12px;
    font-family: inherit;
    background: white;
}
.bill-item-row input:focus { border-color: #2e7d32; outline: none; }
.batch-input {
    width: 100%;
    margin-top: 3px;
    padding: 2px 4px;
    border: 1px dashed #a5d6a7;
    border-radius: 4px;
    font-size: 10px;
    color: var(--text-secondary);
    background: white;
    font-family: inherit;
}
.batch-input:focus { border-color: #2e7d32; outline: none; color: var(--text); }
.batch-tag {
    display: inline-block;
    font-size: 10px;
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #a5d6a7;
    border-radius: 4px;
    padding: 1px 5px;
    margin-left: 4px;
    font-weight: 600;
}
.bill-remove-btn {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    padding: 2px;
}
.bill-total-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #212121;
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 15px;
}

/* Status badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}
.badge-pending { background: #fff3cd; color: #856404; }
.badge-paid { background: #d4edda; color: #155724; }
.badge-cancelled { background: #f8d7da; color: #721c24; }

/* Shop info card */
.shop-info-card {
    background: rgba(192,57,43,0.05);
    border: 1px solid rgba(192,57,43,0.2);
    border-radius: 8px;
    padding: 10px 12px;
    margin-top: 8px;
    font-size: 13px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: calc(var(--nav-height) + 80px);
    left: 50%;
    transform: translateX(-50%);
    background: #323232;
    color: white;
    padding: 10px 20px;
    border-radius: 24px;
    font-size: 13px;
    z-index: 300;
    white-space: nowrap;
    box-shadow: var(--shadow);
    pointer-events: none;
}
.toast.hidden { display: none; }

/* Sync indicator */
.sync-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 12px;
    font-size: 13px;
    box-shadow: var(--shadow);
}
.sync-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--warning);
    animation: pulse 1.5s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; line-height: 1.6; }

/* Loading */
.loading {
    text-align: center;
    padding: 24px;
    color: var(--text-secondary);
    font-size: 14px;
}

/* Bill detail */
.bill-detail-shop { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.bill-detail-meta { font-size: 12px; color: var(--text-secondary); }
.bill-items-list { margin-top: 12px; }
.bill-detail-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.bill-detail-total {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    font-weight: 700;
    font-size: 15px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.page.active { animation: fadeIn 0.2s ease; }

/* Select */
select.form-control {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23757575' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* Textarea */
textarea.form-control { resize: vertical; min-height: 60px; }

/* ── Reports ── */
.report-filter-bar {
    background: var(--surface);
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.report-quick-btns {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}
.report-quick-btn {
    flex: 1;
    padding: 6px 4px;
    font-size: 12px;
    font-weight: 600;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: white;
    color: var(--text-secondary);
    cursor: pointer;
}
.report-quick-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.report-date-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.report-date-input {
    flex: 1;
    padding: 6px 10px;
    font-size: 13px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: white;
    color: var(--text);
}
.report-print-btn {
    background: var(--primary);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 18px;
    padding: 4px 10px;
    cursor: pointer;
    line-height: 1;
}
.report-print-btn:active { opacity: 0.8; }
.report-summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    background: var(--border);
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}
.report-stat {
    background: var(--surface);
    padding: 12px 8px;
    text-align: center;
}
.report-stat-val {
    font-size: 13px;
    font-weight: 700;
    word-break: break-all;
}
.report-stat-lbl {
    font-size: 10px;
    color: var(--text-secondary);
    margin-top: 2px;
}
.report-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    padding: 10px 16px 4px;
}
.report-shop-list {
    background: var(--surface);
    margin: 0 0 8px;
}
.report-shop-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    gap: 8px;
}
.report-shop-name {
    font-size: 13px;
    font-weight: 600;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.report-shop-stats {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    font-size: 11px;
}
.report-shop-count    { color: var(--text-secondary); }
.report-shop-total    { font-weight: 700; color: var(--primary); }
.report-shop-collected{ color: var(--success); }
.report-bill-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    gap: 8px;
}
.report-bill-row:active { background: var(--bg); }

/* Responsive */
@media (min-width: 480px) {
    .app-main, .app-header, .bottom-nav {
        max-width: 480px;
        left: 50%;
        transform: translateX(-50%);
    }
    .modal, .bottom-sheet {
        max-width: 480px;
        left: 50%;
        transform: translateX(-50%);
        right: auto;
        width: 100%;
    }
    .fab {
        right: calc(50% - 240px + 16px);
    }
}
