/* ============================================
   PERTAMINA SPBU RECEIPT PRINTER
   Modern UI Stylesheet
   ============================================ */

/* === CSS Variables === */
:root {
    --primary: #D32F2F;
    --primary-dark: #B71C1C;
    --primary-light: #FFCDD2;
    --secondary: #1565C0;
    --secondary-dark: #0D47A1;
    --success: #2E7D32;
    --info: #0288D1;
    --warning: #F9A825;
    --danger: #C62828;
    --dark: #212121;
    --gray-900: #263238;
    --gray-800: #37474F;
    --gray-700: #455A64;
    --gray-600: #546E7A;
    --gray-500: #78909C;
    --gray-400: #90A4AE;
    --gray-300: #B0BEC5;
    --gray-200: #CFD8DC;
    --gray-100: #ECEFF1;
    --white: #FFFFFF;
    --bg: #F5F7FA;
    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Courier New', monospace;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --shadow-xl: 0 12px 48px rgba(0,0,0,0.15);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --transition: all 0.2s ease;
}

/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-main);
    background: var(--bg);
    color: var(--dark);
    line-height: 1.6;
    min-height: 100vh;
}

/* === Header === */
.app-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-lg);
}

.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-icon {
    width: 48px;
    height: 48px;
    background: rgba(255,255,255,0.2);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    backdrop-filter: blur(10px);
}

.logo-text h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.logo-text p {
    font-size: 12px;
    opacity: 0.85;
    font-weight: 400;
}

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

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-main);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 12px rgba(211,47,47,0.35);
}

.btn-success {
    background: var(--success);
    color: white;
}
.btn-success:hover {
    background: #1B5E20;
    box-shadow: 0 4px 12px rgba(46,125,50,0.35);
}

.btn-info {
    background: var(--info);
    color: white;
}
.btn-info:hover {
    background: #01579B;
    box-shadow: 0 4px 12px rgba(2,136,209,0.35);
}

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover {
    background: #B71C1C;
}

.btn-ghost {
    background: rgba(255,255,255,0.15);
    color: white;
    backdrop-filter: blur(10px);
}
.btn-ghost:hover {
    background: rgba(255,255,255,0.25);
}

.btn-outline {
    background: transparent;
    color: var(--gray-600);
    border: 1.5px solid var(--gray-300);
}
.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-lg {
    padding: 12px 24px;
    font-size: 15px;
}

/* === Main Container === */
.main-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

/* === Tabs === */
.tab-content {
    display: none;
}
.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === Layout Grid === */
.layout-grid {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 24px;
    align-items: start;
}

/* === Panel Card === */
.panel-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.panel-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.panel-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-800);
    display: flex;
    align-items: center;
    gap: 10px;
}

.panel-header h2 i {
    color: var(--primary);
    font-size: 18px;
}

/* === Form Styles === */
form {
    padding: 20px 24px;
}

.form-section {
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: 18px;
    margin-bottom: 20px;
    background: var(--white);
    transition: var(--transition);
}

.form-section:hover {
    border-color: var(--gray-300);
    box-shadow: var(--shadow-sm);
}

.form-section legend {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-section legend i {
    font-size: 14px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-family: var(--font-main);
    font-size: 14px;
    color: var(--dark);
    background: var(--white);
    transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(211,47,47,0.1);
}

.form-group input[readonly] {
    background: var(--gray-100);
    font-weight: 600;
    color: var(--primary);
}

.total-display {
    font-size: 18px !important;
    font-weight: 700 !important;
    color: var(--primary) !important;
    background: #FFF3F3 !important;
    border-color: var(--primary-light) !important;
}

.change-display {
    font-size: 16px !important;
    font-weight: 600 !important;
    color: var(--success) !important;
    background: #E8F5E9 !important;
}

.form-actions {
    display: flex;
    gap: 12px;
    padding: 20px 0 0;
    flex-wrap: wrap;
}

/* === Sticky Preview === */
.sticky-preview {
    position: sticky;
    top: 90px;
}

/* === Receipt Wrapper === */
.receipt-wrapper {
    padding: 24px;
    display: flex;
    justify-content: center;
    background: var(--gray-100);
    min-height: 300px;
}

.receipt-container {
    width: 100%;
    max-width: 320px;
}

/* === Receipt Thermal Style === */
.receipt {
    background: #FFFFF5;
    font-family: var(--font-mono);
    font-size: 11.5px;
    line-height: 1.5;
    color: #1a1a1a;
    padding: 20px 16px;
    position: relative;
    box-shadow: var(--shadow-lg);
}

/* Top tear effect */
.receipt::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 0;
    right: 0;
    height: 6px;
    background: linear-gradient(135deg, transparent 33.33%, #FFFFF5 33.33%, #FFFFF5 66.66%, transparent 66.66%),
                linear-gradient(225deg, transparent 33.33%, #FFFFF5 33.33%, #FFFFF5 66.66%, transparent 66.66%);
    background-size: 12px 6px;
}

/* Bottom tear effect */
.receipt::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 0;
    right: 0;
    height: 6px;
    background: linear-gradient(45deg, transparent 33.33%, #FFFFF5 33.33%, #FFFFF5 66.66%, transparent 66.66%),
                linear-gradient(315deg, transparent 33.33%, #FFFFF5 33.33%, #FFFFF5 66.66%, transparent 66.66%);
    background-size: 12px 6px;
}

.receipt-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-400);
}

.receipt-empty i {
    font-size: 48px;
    margin-bottom: 16px;
    display: block;
}

.receipt-empty p {
    font-family: var(--font-main);
    font-size: 13px;
    line-height: 1.6;
}

/* Receipt inner elements (Matching Photo) */
.r-center { text-align: center; }
.r-left { text-align: left; }
.r-right { text-align: right; }
.r-bold { font-weight: 700; }

.r-logo {
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 2px;
}

.r-text-small {
    font-size: 10.5px;
    line-height: 1.4;
}

.r-divider {
    border: none;
    border-top: 1px dashed #333;
    margin: 6px 0;
}

.r-row {
    display: flex;
    justify-content: space-between;
    line-height: 1.4;
}

.r-row-fixed {
    display: flex;
    line-height: 1.4;
}

.r-row-fixed .r-label {
    width: 90px;
    flex-shrink: 0;
}

.r-row-fixed .r-colon {
    width: 15px;
    text-align: center;
    flex-shrink: 0;
}

.r-row-fixed .r-value {
    flex-grow: 1;
}

.r-row-price {
    display: flex;
    line-height: 1.4;
}
.r-row-price .r-label { width: 130px; flex-shrink: 0; }
.r-row-price .r-colon { width: 15px; text-align: center; flex-shrink: 0; }
.r-row-price .r-value { flex-grow: 1; text-align: right; }

.r-payment-block {
    margin: 4px 0;
}
.r-payment-line {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2px;
}

.r-disclaimer {
    text-align: left;
    font-size: 10.5px;
    line-height: 1.4;
    padding: 4px 0;
}

/* === SPBU Profile Selection === */
.spbu-profile-header {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.spbu-profile-header select {
    flex-grow: 1;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--gray-300);
    font-family: var(--font-main);
}

/* === Login Overlay === */
.login-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--gray-900);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
}

.login-box {
    background: var(--white);
    padding: 30px;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}

.login-box h2 {
    color: var(--primary);
    margin-bottom: 10px;
}

.login-box p {
    color: var(--gray-600);
    margin-bottom: 20px;
    font-size: 14px;
}

.login-box input {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 18px;
    text-align: center;
    letter-spacing: 2px;
    margin-bottom: 20px;
    font-family: var(--font-mono);
}

.login-box input:focus {
    border-color: var(--primary);
    outline: none;
}

/* === Layout Responsive === */
.layout-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
}

@media (max-width: 992px) {
    .layout-grid {
        grid-template-columns: 1fr;
    }
    
    .sticky-preview {
        position: static;
        margin-top: 20px;
    }
    
    .printer-toolbar {
        top: 0;
        position: relative;
    }
}

.r-barcode-area {
    text-align: center;
    margin: 8px 0 4px;
}

.r-barcode-lines {
    font-size: 24px;
    letter-spacing: -1.5px;
    color: #333;
    line-height: 1;
    font-weight: 400;
    overflow: hidden;
    max-height: 30px;
}

.r-barcode-text {
    text-align: center;
    font-size: 9px;
    color: #888;
    letter-spacing: 1.5px;
    margin-top: 2px;
}

.r-footer {
    text-align: center;
    font-size: 10px;
    color: #666;
    margin-top: 6px;
    line-height: 1.6;
}

.r-spacing {
    height: 4px;
}

/* === History === */
.history-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.search-input {
    padding: 8px 14px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-family: var(--font-main);
    font-size: 13px;
    width: 220px;
    transition: var(--transition);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(211,47,47,0.1);
}

.history-list {
    padding: 16px 24px;
    max-height: 75vh;
    overflow-y: auto;
}

.history-empty {
    text-align: center;
    padding: 80px 20px;
    color: var(--gray-400);
}

.history-empty i {
    font-size: 48px;
    margin-bottom: 16px;
    display: block;
}

.history-empty p {
    font-size: 14px;
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-md);
    margin-bottom: 10px;
    transition: var(--transition);
    background: var(--white);
    gap: 16px;
}

.history-item:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow-sm);
    background: #FFFAFB;
}

.history-info {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
    min-width: 0;
}

.history-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.history-icon.pertalite { background: #E8F5E9; color: #2E7D32; }
.history-icon.pertamax { background: #E3F2FD; color: #1565C0; }
.history-icon.pertamax-turbo { background: #F3E5F5; color: #7B1FA2; }
.history-icon.bio-solar { background: #FFF3E0; color: #E65100; }
.history-icon.dexlite { background: #E0F7FA; color: #00838F; }
.history-icon.pertamina-dex { background: #FCE4EC; color: #AD1457; }

.history-details {
    min-width: 0;
}

.history-details h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 2px;
}

.history-details p {
    font-size: 12px;
    color: var(--gray-500);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-meta {
    text-align: right;
    flex-shrink: 0;
}

.history-price {
    font-size: 15px;
    font-weight: 700;
    color: var(--primary);
}

.history-date {
    font-size: 11px;
    color: var(--gray-500);
    margin-top: 2px;
}

.history-btns {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.history-btns .btn {
    padding: 6px 10px;
    font-size: 12px;
}

/* === Toast === */
.toast-container {
    position: fixed;
    top: 80px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: var(--white);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    font-weight: 500;
    animation: slideInRight 0.3s ease;
    border-left: 4px solid var(--success);
    min-width: 280px;
}

.toast.error {
    border-left-color: var(--danger);
}

.toast i {
    font-size: 18px;
    color: var(--success);
}

.toast.error i {
    color: var(--danger);
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(60px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes slideOutRight {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(60px); }
}

/* === Footer === */
.app-footer {
    text-align: center;
    padding: 24px;
    color: var(--gray-500);
    font-size: 12px;
    margin-top: 40px;
}

/* === Print Styles === */
@media print {
    body * {
        visibility: hidden !important;
    }

    #printArea,
    #printArea * {
        visibility: visible !important;
    }

    #printArea {
        position: absolute;
        left: 0;
        top: 0;
        width: 80mm;
        padding: 0;
        margin: 0;
    }

    #printArea .receipt {
        box-shadow: none;
        padding: 10px 8px;
        font-size: 11px;
        width: 80mm;
        background: white;
    }

    #printArea .receipt::before,
    #printArea .receipt::after {
        display: none;
    }

    @page {
        size: 80mm auto;
        margin: 0;
    }

    .app-header, .app-footer, .no-print {
        display: none !important;
    }
}

.print-only {
    display: none;
}

/* === Responsive === */
@media (max-width: 1024px) {
    .layout-grid {
        grid-template-columns: 1fr;
    }

    .sticky-preview {
        position: static;
    }

    .header-inner {
        flex-direction: column;
        text-align: center;
    }

    .logo-section {
        justify-content: center;
    }
}

@media (max-width: 640px) {
    .main-container {
        padding: 12px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
        justify-content: center;
    }

    .panel-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .history-actions {
        width: 100%;
    }

    .search-input {
        width: 100%;
    }

    .history-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .history-meta {
        text-align: left;
    }

    .history-btns {
        width: 100%;
    }

    .history-btns .btn {
        flex: 1;
        justify-content: center;
    }
}

/* === Printer Toolbar & Bluetooth UI === */
.printer-toolbar {
    background: var(--gray-900);
    color: var(--white);
    padding: 12px 24px;
    position: sticky;
    top: 80px; /* Below main header */
    z-index: 99;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.printer-toolbar-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.printer-connection {
    display: flex;
    align-items: center;
    gap: 12px;
}

.printer-settings-bar {
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.connected {
    background: #4CAF50;
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.6);
}

.status-dot.disconnected {
    background: #F44336;
}

.printer-status {
    font-size: 13px;
    font-weight: 600;
}

.printer-status.connected { color: #81C784; }
.printer-status.disconnected { color: #E57373; }

.printer-select {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--gray-600);
    background: var(--gray-800);
    color: var(--white);
    font-family: var(--font-main);
    font-size: 13px;
    outline: none;
}

.printer-select:focus {
    border-color: var(--primary);
}

.btn-bluetooth {
    background: #1E88E5;
    color: white;
}
.btn-bluetooth:hover {
    background: #1565C0;
}
.btn-bluetooth-print {
    background: #1E88E5;
    color: white;
}
.btn-bluetooth-print:hover {
    background: #1565C0;
}
.btn-bluetooth-print:disabled {
    background: var(--gray-400);
    cursor: not-allowed;
}

/* === Modal (Browser Info) === */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--white);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    animation: fadeIn 0.2s ease-out;
}

.modal-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 16px;
    color: var(--gray-900);
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-header h3 i {
    color: var(--info);
}

.modal-body {
    padding: 24px;
}

.browser-info-item {
    padding: 12px 16px;
    background: var(--gray-100);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--gray-800);
    border-left: 3px solid var(--gray-400);
}

.browser-info-item:contains("?") {
    border-left-color: var(--success);
}

.browser-info-notes {
    margin-top: 24px;
    font-size: 13px;
    color: var(--gray-700);
    background: #FFF3E0;
    padding: 16px;
    border-radius: var(--radius-sm);
    border: 1px solid #FFE0B2;
}

.browser-info-notes h4 {
    margin-bottom: 8px;
    color: #E65100;
}

.browser-info-notes ul {
    padding-left: 20px;
}

.browser-info-notes li {
    margin-bottom: 6px;
}

@media (max-width: 768px) {
    .printer-toolbar {
        top: 135px; /* Adjust for stacked header on mobile */
    }
    .printer-toolbar-inner {
        flex-direction: column;
        align-items: flex-start;
    }
    .printer-settings-bar {
        width: 100%;
        justify-content: space-between;
    }
}
