/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f4f1eb; color: #2c2c2c; line-height: 1.6; min-height: 100vh; }
a { color: #1a5276; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== APP LAYOUT ===== */
.app-layout { display: flex; min-height: 100vh; }
.main-content { flex: 1; padding: 2rem; padding-left: calc(240px + 2rem); max-width: 1440px; overflow-x: auto; }
.main-content h1 { font-family: Georgia, 'Times New Roman', serif; font-size: 1.6rem; margin-bottom: 1rem; }

/* ===== SIDEBAR ===== */
.sidebar {
    width: 240px; min-height: 100vh; background: #1e2a38; color: #cfd8dc;
    padding: 0; display: flex; flex-direction: column; position: fixed; top: 0; left: 0; z-index: 100;
}
.sidebar-brand {
    padding: 1.2rem 1rem; font-family: Georgia, serif; font-size: 1.1rem; font-weight: bold;
    color: #fff; border-bottom: 1px solid rgba(255,255,255,.1);
}
.sidebar-nav { flex: 1; padding: .5rem 0; display: flex; flex-direction: column; overflow-y: auto; }
.sidebar-section-label { padding: .6rem 1rem .2rem; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #78909c; }
.sidebar-link {
    display: flex; align-items: center; gap: .5rem; padding: .5rem 1rem; font-size: .88rem;
    color: #b0bec5; transition: background .15s, color .15s; white-space: nowrap;
}
.sidebar-link:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.sidebar-link.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; }
.sidebar-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ===== HAMBURGER (mobile) ===== */
.hamburger {
    display: none; position: fixed; top: 1rem; left: 1rem; z-index: 200;
    background: #1e2a38; border: none; border-radius: 6px; padding: .5rem .6rem; cursor: pointer;
}
.hamburger span { display: block; width: 20px; height: 2px; background: #fff; margin: 4px 0; transition: .3s; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 90; }

/* ===== CARDS & BOXES ===== */
.card { background: #fff; border-radius: 8px; padding: 1.5rem; margin-bottom: 1.5rem; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.card h2 { font-family: Georgia, serif; font-size: 1.15rem; margin-bottom: 1rem; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: .25rem; color: #555; }
.form-group input, .form-group textarea, .form-group select {
    width: 100%; padding: .55rem .75rem; border: 1px solid #ccc; border-radius: 6px;
    font-size: .95rem; font-family: inherit; background: #fff;
}
.form-group textarea { resize: vertical; min-height: 60px; }
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
    outline: none; border-color: #1a5276; box-shadow: 0 0 0 3px rgba(26,82,118,.15);
}
.form-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.form-row > .form-group { flex: 1; min-width: 140px; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-block; padding: .5rem 1.2rem; border-radius: 6px; font-size: .88rem;
    font-weight: 600; border: none; cursor: pointer; text-align: center; transition: .2s;
}
.btn-primary { background: #1a5276; color: #fff; }
.btn-primary:hover { background: #154360; text-decoration: none; }
.btn-success { background: #27ae60; color: #fff; }
.btn-success:hover { background: #1e8449; text-decoration: none; }
.btn-danger { background: #c0392b; color: #fff; }
.btn-danger:hover { background: #a93226; text-decoration: none; }
.btn-outline { background: transparent; border: 1px solid #ccc; color: #555; }
.btn-outline:hover { background: #f5f5f5; text-decoration: none; }
.btn-sm { padding: .3rem .7rem; font-size: .78rem; }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
thead { background: #f7f5f0; }
th { padding: .6rem .75rem; text-align: left; font-weight: 600; color: #555; border-bottom: 2px solid #ddd; white-space: nowrap; }
td { padding: .55rem .75rem; border-bottom: 1px solid #eee; }
tr:hover td { background: #fafaf7; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mono { font-family: 'Courier New', Courier, monospace; }
.nowrap { white-space: nowrap; }

/* ===== STATUS BADGES ===== */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 10px; font-size: .75rem; font-weight: 600; }
.badge-draft { background: #f0e68c; color: #7d6608; }
.badge-sent { background: #d4efdf; color: #1e8449; }
.badge-paid { background: #d5f5e3; color: #0e6655; }
.status-select { font-size: .78rem; padding: .2rem .4rem; border-radius: 4px; border: 1px solid #ccc; }

/* ===== FLASH MESSAGES ===== */
.flash { padding: .75rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: .88rem; }
.flash-success { background: #d5f5e3; color: #0e6655; border: 1px solid #82e0aa; }
.flash-error { background: #fadbd8; color: #922b21; border: 1px solid #f1948a; }

/* ===== ITEM ROWS (dynamic) ===== */
.item-row { display: flex; gap: .5rem; align-items: flex-end; margin-bottom: .5rem; flex-wrap: wrap; }
.item-row input { padding: .45rem .6rem; border: 1px solid #ccc; border-radius: 5px; font-size: .88rem; }
.item-row .desc { flex: 3; min-width: 180px; }
.item-row .num { flex: 1; min-width: 70px; max-width: 120px; }
.item-row .subtotal-cell { min-width: 110px; text-align: right; font-family: 'Courier New', monospace; font-weight: 600; font-size: .88rem; padding-top: .45rem; }
.item-row .btn-remove { background: none; border: none; color: #c0392b; font-size: 1.2rem; cursor: pointer; padding: .2rem .4rem; }

/* ===== INVOICE PREVIEW (A4) ===== */
.invoice-page { background: #fff; max-width: 210mm; margin: 0 auto; padding: 15mm; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.invoice-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1.5rem; border-bottom: 3px solid var(--accent); padding-bottom: 1rem; }
.invoice-company-name { font-family: Georgia, serif; font-size: 1.4rem; font-weight: bold; }
.invoice-company-info { font-size: .8rem; color: #666; line-height: 1.5; }
.invoice-meta { text-align: right; }
.invoice-number { font-family: 'Courier New', monospace; font-size: 1.1rem; font-weight: bold; color: var(--accent); }
.invoice-label { font-size: .8rem; color: #888; text-transform: uppercase; letter-spacing: .05em; }
.invoice-parties { display: flex; justify-content: space-between; margin-bottom: 1.5rem; gap: 2rem; }
.invoice-parties > div { flex: 1; }
.invoice-parties h4 { font-size: .75rem; text-transform: uppercase; color: #999; letter-spacing: .05em; margin-bottom: .25rem; }
.invoice-parties p { font-size: .88rem; line-height: 1.5; }

/* Invoice Table */
.invoice-table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: .85rem; }
.invoice-table thead { border-bottom: 2px solid var(--accent); }
.invoice-table th { padding: .5rem .6rem; font-size: .75rem; text-transform: uppercase; color: #666; letter-spacing: .03em; }
.invoice-table td { padding: .5rem .6rem; border-bottom: 1px solid #eee; }
.invoice-table .col-num { width: 40px; text-align: center; }
.invoice-table .col-qty { width: 60px; text-align: center; }
.invoice-table .col-price, .invoice-table .col-total { width: 110px; text-align: right; font-family: 'Courier New', monospace; }

/* Invoice Totals */
.invoice-totals { display: flex; justify-content: flex-end; margin: 1rem 0; }
.invoice-totals-box { width: 280px; }
.invoice-totals-row { display: flex; justify-content: space-between; padding: .3rem 0; font-size: .88rem; }
.invoice-totals-row.total { border-top: 2px solid var(--accent); font-weight: bold; font-size: 1.05rem; padding-top: .5rem; margin-top: .3rem; }
.invoice-totals-row .label { color: #666; }
.invoice-totals-row .amount { font-family: 'Courier New', monospace; }

/* Stamp / Stempel */
.invoice-stamp {
    display: inline-flex; align-items: center; justify-content: center;
    width: 90px; height: 90px; border: 3px solid var(--accent); border-radius: 50%;
    font-size: .65rem; font-weight: bold; text-align: center; color: var(--accent);
    transform: rotate(-12deg); opacity: .7; line-height: 1.2; padding: .5rem;
}

/* Bank info & notes */
.invoice-footer-section { display: flex; gap: 2rem; margin-top: 1.5rem; font-size: .82rem; color: #555; }
.invoice-footer-section > div { flex: 1; }
.invoice-footer-section h4 { font-size: .75rem; text-transform: uppercase; color: #999; margin-bottom: .25rem; }

/* ===== INVOICE RECEIPT (thermal) ===== */
.invoice-receipt { width: 72mm; margin: 0 auto; padding: 4mm; font-family: 'Courier New', Courier, monospace; font-size: 9pt; }
.invoice-receipt .receipt-header { text-align: center; margin-bottom: 3mm; }
.invoice-receipt .receipt-company { font-size: 11pt; font-weight: bold; }
.invoice-receipt .receipt-address { font-size: 7pt; color: #555; }
.invoice-receipt .receipt-divider { border: none; border-top: 1px dashed #999; margin: 2mm 0; }
.invoice-receipt .receipt-row { display: flex; justify-content: space-between; font-size: 8pt; }
.invoice-receipt .receipt-item-desc { font-size: 8pt; margin-top: 1mm; }
.invoice-receipt .receipt-total-line { border-top: 1px dashed #999; margin: 2mm 0; }
.invoice-receipt .receipt-total { font-weight: bold; font-size: 10pt; }
.invoice-receipt .receipt-footer { text-align: center; font-size: 7pt; color: #777; margin-top: 3mm; }
.invoice-receipt .receipt-stamp { text-align: center; margin-top: 3mm; font-size: 8pt; font-weight: bold; color: var(--accent); }

/* ===== LOGIN PAGE ===== */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #f4f1eb; }
.login-box { background: #fff; padding: 2rem; border-radius: 10px; box-shadow: 0 2px 12px rgba(0,0,0,.1); width: 100%; max-width: 360px; }
.login-box h1 { font-family: Georgia, serif; text-align: center; margin-bottom: 1.5rem; font-size: 1.3rem; }

/* ===== SHARE BUTTONS ===== */
.share-bar { display: flex; gap: .5rem; flex-wrap: wrap; margin: 1rem 0; }
.btn-wa { background: #25D366; color: #fff; }
.btn-wa:hover { background: #1da851; text-decoration: none; }

/* ===== TOGGLE SIZE ===== */
.size-toggle { display: inline-flex; border: 1px solid #ccc; border-radius: 6px; overflow: hidden; margin-bottom: 1rem; }
.size-toggle button { padding: .4rem 1rem; border: none; background: #f5f5f5; cursor: pointer; font-size: .82rem; }
.size-toggle button.active { background: var(--accent); color: #fff; font-weight: 600; }

/* ===== RESPONSIVE — MOBILE ===== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%); transition: transform .3s;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar.open ~ .sidebar-overlay { display: block; }
    .hamburger { display: block; }
    .main-content { padding: 1rem; padding-top: 4rem; padding-left: 1rem; }
    .form-row { flex-direction: column; }
    .item-row { flex-direction: column; }
    .item-row input { width: 100%; }
    .item-row .num { max-width: none; }
    .invoice-parties { flex-direction: column; gap: 1rem; }
    .invoice-footer-section { flex-direction: column; gap: 1rem; }
    .hide-mobile { display: none; }
    .show-mobile-only { display: block !important; }
}

/* ===== PRINT ===== */
@media print {
    body { background: #fff; }
    .no-print, .hamburger, .sidebar, .sidebar-overlay, .flash, .share-bar, .size-toggle { display: none !important; }
    .app-layout { display: block; }
    .main-content { padding: 0; padding-left: 0; max-width: none; }
    .card { box-shadow: none; border: none; }
    .invoice-page { box-shadow: none; padding: 10mm; max-width: none; }
}

/* A4 print */
@media print and (min-width: 210mm) {
    @page { size: A4; margin: 12mm; }
}

/* Thermal / receipt print */
@media print and (max-width: 85mm) {
    @page { size: 80mm auto; margin: 2mm; }
    .invoice-receipt { width: 72mm; padding: 2mm; font-size: 8pt; }
}
