/* ============================================================
   SA Electronics POS — Complete Stylesheet
   ============================================================ */

/* --- Design Tokens --- */
:root {
    --primary: #2d6a4f;
    --primary-light: #40916c;
    --primary-dark: #1b4332;
    --gold: #d4a017;
    --gold-light: #f0d060;
    --bg: #f5f3ef;
    --card: #ffffff;
    --text: #2c3e50;
    --text-muted: #7f8c8d;
    --border: #ddd;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #ea580c;
    --warning-light: #fff7ed;
    --info: #0891b2;
    --sidebar-w: 250px;
    --topbar-h: 64px;
    --radius: 10px;
    --shadow: 0 2px 12px rgba(0,0,0,.06);
    --shadow-lg: 0 8px 30px rgba(0,0,0,.1);
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body { font-family: 'IBM Plex Sans', sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* --- Layout --- */
.app-layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--primary-dark);
    color: #fff;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform .3s ease;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 12px;
    padding: 20px 22px;
    border-bottom: 1px solid rgba(255,255,255,.1);
}
.brand-icon {
    width: 40px; height: 40px; border-radius: 10px;
    background: var(--gold); color: var(--primary-dark);
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
}
.brand-text { font-family: 'DM Serif Display', serif; font-size: 18px; }

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 22px; color: rgba(255,255,255,.7);
    transition: .2s; font-size: 14px; font-weight: 500;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.nav-item.active { background: rgba(255,255,255,.12); color: var(--gold); border-right: 3px solid var(--gold); }
.nav-item i { width: 20px; text-align: center; font-size: 16px; }

.sidebar-footer { border-top: 1px solid rgba(255,255,255,.1); padding: 8px 0; }

/* Main wrapper */
.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Topbar */
.topbar {
    height: var(--topbar-h);
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 24px; gap: 16px;
    position: sticky; top: 0; z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.menu-toggle {
    display: none;
    background: none; border: none; font-size: 20px;
    color: var(--text); cursor: pointer;
}
.topbar-title { font-weight: 600; font-size: 18px; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 14px; }

.content-area { flex: 1; padding: 24px; }

/* --- Cards --- */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 { font-size: 16px; font-weight: 600; }
.card-body { padding: 20px; }
.card-body.p-0 { padding: 0; }

/* --- Stats Grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    display: flex; align-items: center; gap: 16px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}
.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 4px; height: 100%;
}
.stat-green::before { background: var(--success); }
.stat-amber::before { background: var(--warning); }
.stat-teal::before { background: var(--primary); }
.stat-red::before { background: var(--danger); }
.stat-blue::before { background: var(--info); }
.stat-purple::before { background: #7c3aed; }
.stat-icon {
    width: 48px; height: 48px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
}
.stat-green .stat-icon { background: var(--success-light); color: var(--success); }
.stat-amber .stat-icon { background: var(--warning-light); color: var(--warning); }
.stat-teal .stat-icon { background: #d1fae5; color: var(--primary); }
.stat-red .stat-icon { background: var(--danger-light); color: var(--danger); }
.stat-blue .stat-icon { background: #cffafe; color: var(--info); }
.stat-purple .stat-icon { background: #ede9fe; color: #7c3aed; }
.stat-value { font-size: 24px; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 13px; color: var(--text-muted); }

/* --- Dashboard Grid --- */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 20px;
}

/* --- Tables --- */
.table-responsive { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
    padding: 10px 14px; text-align: left;
    background: #f8f7f4; font-weight: 600; font-size: 12px;
    text-transform: uppercase; letter-spacing: .5px;
    color: var(--text-muted); border-bottom: 2px solid var(--border);
}
.table td {
    padding: 10px 14px; border-bottom: 1px solid #f0f0f0;
    vertical-align: middle;
}
.table tr:hover td { background: #faf9f6; }
.link { color: var(--primary); font-weight: 600; }
.link:hover { text-decoration: underline; }

/* --- Badges --- */
.badge {
    display: inline-block; padding: 3px 10px; border-radius: 20px;
    font-size: 11px; font-weight: 600; text-transform: uppercase;
}
.badge-active, .badge-paid { background: var(--success-light); color: var(--success); }
.badge-inactive, .badge-pending { background: #fef3c7; color: #b45309; }
.badge-closed { background: #e5e7eb; color: #4b5563; }
.badge-defaulted, .badge-overdue { background: var(--danger-light); color: var(--danger); }

/* --- Buttons --- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 18px; border-radius: 8px; border: none;
    font-size: 14px; font-weight: 600; cursor: pointer;
    transition: all .2s; font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-outline { background: transparent; color: var(--text); border: 2px solid var(--border); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-lg { padding: 12px 28px; font-size: 15px; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }

/* --- Forms --- */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block; font-weight: 600; font-size: 13px;
    color: var(--text); margin-bottom: 5px;
}
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 10px 12px;
    border: 2px solid var(--border); border-radius: 8px;
    font-size: 14px; font-family: inherit;
    transition: border-color .2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--primary);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* --- Page Header --- */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}
.page-header h2 { font-size: 22px; font-weight: 700; }
.header-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.search-form {
    display: flex; gap: 0; border: 2px solid var(--border); border-radius: 8px; overflow: hidden;
}
.search-form input {
    border: none; padding: 8px 12px; font-size: 14px; min-width: 220px;
}
.search-form button {
    border: none; background: var(--primary); color: #fff; padding: 8px 14px; cursor: pointer; }
.search-form button:hover { background: var(--primary-dark); }

/* --- Utility --- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-muted { color: var(--text-muted); }
.py-4 { padding: 16px 0; }

/* --- Avatar --- */
.avatar-sm { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; border: 2px solid #eee; }
.avatar-placeholder {
    width: 36px; height: 36px; border-radius: 50%;
    background: #e2e8f0; color: #94a3b8;
    display: flex; align-items: center; justify-content: center; font-size: 14px;
}

/* --- Row Grid --- */
.row-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.col-8 { grid-column: span 1; }
.col-4 { grid-column: span 1; }

/* --- Summary List --- */
.summary-list { display: flex; flex-direction: column; gap: 10px; }
.summary-item { display: flex; justify-content: space-between; font-size: 14px; }
.summary-item span { color: var(--text-muted); }

/* --- Alerts --- */
.alert {
    padding: 14px 18px; border-radius: 8px; margin-bottom: 20px;
    font-size: 14px; font-weight: 500;
    display: flex; justify-content: space-between; align-items: center;
}
.alert-success { background: var(--success-light); color: #166534; border-left: 4px solid var(--success); }
.alert-error { background: var(--danger-light); color: #991b1b; border-left: 4px solid var(--danger); }
.alert-close { background: none; border: none; font-size: 20px; cursor: pointer; color: inherit; opacity: 0.6; }
.alert-close:hover { opacity: 1; }

/* ============================================================
   SA ELECTRONICS FORM STYLES (Create Installment)
   ============================================================ */
.installment-form-wrapper {
    background: #fff;
    border: 1px solid #ccc;
    box-shadow: var(--shadow-lg);
    border-radius: 4px;
    padding: 0;
    max-width: 900px;
    margin: 0 auto;
}

/* Form Header */
.sa-form-header {
    background: var(--primary-dark);
    color: #fff;
    padding: 20px 24px;
    border-bottom: 4px solid var(--gold);
}
.sa-form-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.sa-form-logo {
    width: 50px; height: 50px; background: var(--gold); color: var(--primary-dark);
    border-radius: 8px; display: flex; align-items: center; justify-content: center;
    font-size: 24px;
}
.sa-form-company { font-family: 'DM Serif Display', serif; font-size: 24px; letter-spacing: 1px; }
.sa-form-branch { font-size: 14px; opacity: 0.8; }
.sa-form-contact { font-size: 11px; opacity: 0.6; margin-top: 2px; }
.sa-form-title {
    text-align: center; font-size: 16px; font-weight: 700;
    letter-spacing: 3px; border: 2px solid rgba(255,255,255,.3);
    padding: 8px; margin-bottom: 12px;
}
.sa-form-meta { display: flex; gap: 24px; align-items: center; }
.sa-meta-field { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.sa-meta-field label { font-weight: 600; }
.sa-meta-value { font-weight: 700; color: var(--gold); }
.sa-input {
    width: 100%; padding: 9px 12px; border: 1px solid #ccc;
    border-radius: 4px; font-family: inherit; font-size: 14px;
    background: #fff;
}
.sa-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(45,106,79,.15); }
.sa-input-bold { font-weight: 700; font-size: 16px; background: #f8f9fa; }
.sa-input-readonly { background: #f1f3f5; color: var(--text); font-weight: 600; }

/* Form Sections */
.sa-section { padding: 20px 24px; border-bottom: 1px dashed #ddd; }
.sa-section:last-of-type { border-bottom: none; }
.sa-section-title {
    background: var(--primary); color: #fff; padding: 6px 14px;
    font-size: 13px; font-weight: 700; letter-spacing: 1.5px;
    margin-bottom: 16px; border-radius: 4px;
}

/* Customer Grid with Photo */
.sa-customer-grid { display: flex; gap: 24px; }
.sa-customer-fields { flex: 1; }
.sa-customer-photo {
    width: 140px; flex-shrink: 0; text-align: center;
    display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.sa-photo-box {
    width: 130px; height: 160px; border: 2px dashed #ccc;
    border-radius: 6px; overflow: hidden; display: flex;
    align-items: center; justify-content: center; background: #f8f9fa;
}
.sa-photo-box img { width: 100%; height: 100%; object-fit: cover; }
.sa-photo-placeholder {
    display: flex; flex-direction: column; align-items: center;
    gap: 6px; color: #aaa; font-size: 12px;
}
.sa-photo-placeholder i { font-size: 28px; }

/* Field Rows */
.sa-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 12px; }
.sa-field-row:last-child { margin-bottom: 0; }
.sa-field label { display: block; font-size: 12px; font-weight: 600; color: #555; margin-bottom: 4px; }
.sa-field.full { grid-column: span 2; }
.sa-4col { grid-template-columns: 1fr 1fr 1fr 1fr; }

.req { color: var(--danger); }
.sa-total-due { font-size: 16px; color: var(--danger); margin-top: 6px; }

.sa-form-actions {
    padding: 20px 24px; background: #f8f7f4;
    display: flex; justify-content: flex-end; gap: 12px;
    border-top: 3px solid var(--primary-dark);
}

/* ============================================================
   STRICT TABLE FORM LAYOUT (For Installment View & Print)
   ============================================================ */
.sa-document-view { display: flex; justify-content: center; padding: 10px 0; }
.sa-doc-page {
    background: #fff; border: 1px solid #bbb; box-shadow: 0 4px 20px rgba(0,0,0,.1);
    width: 100%; max-width: 850px; padding: 24px; position: relative;
}

.sa-closed-stamp {
    position: absolute; top: 45%; left: 50%;
    transform: translate(-50%, -50%) rotate(-35deg);
    font-size: 80px; font-weight: 900; color: rgba(220,38,38,.2);
    border: 8px double rgba(220,38,38,.2); padding: 10px 40px;
    letter-spacing: 15px; pointer-events: none; z-index: 10;
}

.sa-form-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    margin-bottom: 20px;
}
.sa-form-table td {
    border: 1px solid #bbb;
    padding: 8px 12px;
    vertical-align: middle;
    font-size: 13px;
}

.sa-tbl-header {
    text-align: center;
    background: var(--primary-dark) !important;
    color: #fff !important;
    font-size: 20px;
    font-weight: 700;
    padding: 15px !important;
    letter-spacing: 2px;
    border-color: var(--primary-dark) !important;
}
.sa-tbl-branch { font-size: 12px; font-weight: 400; opacity: 0.9; display: block; margin-top: 4px; }

.sa-tbl-photo-cell {
    border: 2px solid #000 !important;
    width: 160px;
    text-align: center;
    vertical-align: middle;
    background: #fff;
}
.sa-tbl-photo-box {
    width: 120px;
    height: 150px;
    margin: 0 auto;
    border: 1px solid #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #f9f9f9;
}
.sa-tbl-photo-box img { width: 100%; height: 100%; object-fit: cover; }
.sa-tbl-no-photo { font-size: 11px; color: #aaa; }

.sa-tbl-label {
    background: #f4f6f8;
    font-weight: 600;
    font-size: 11px;
    width: 140px;
    white-space: nowrap;
    color: #444;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.sa-tbl-value { color: #000; }

.sa-tbl-section-head {
    background: var(--primary) !important;
    color: #fff !important;
    font-weight: 700;
    font-size: 12px;
    padding: 6px 12px !important;
    letter-spacing: 2px;
    border-color: var(--primary) !important;
}

.sa-schedule-head td {
    background: #e2e8f0 !important;
    color: #1e293b !important;
    font-weight: 700;
    text-align: center;
    font-size: 11px;
    padding: 8px !important;
    border-color: #94a3b8 !important;
}
.sa-schedule-row td {
    text-align: center;
    padding: 6px !important;
}
.sa-schedule-row.status-paid td { background: #f0fff4; }
.sa-schedule-row.status-pending td { background: #fff; }
.sa-schedule-row.status-overdue td { background: #fff5f5; color: #b91c1c; font-weight: 600; }

.sa-signature-table { width: 100%; border-collapse: collapse; margin-top: 50px; }
.sa-signature-table td { border: none; text-align: center; width: 33%; font-size: 12px; padding-top: 50px; border-top: 1px solid #000; }

/* ============================================================
   MODAL STYLES
   ============================================================ */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.5);
    z-index: 2000; display: none; align-items: center; justify-content: center;
    padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal {
    background: #fff; border-radius: 12px; width: 500px;
    max-width: 100%; max-height: 90vh; overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    animation: modalIn .2s ease;
}
.modal-lg { width: 700px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }
.modal-header {
    padding: 18px 22px; border-bottom: 1px solid #eee;
    display: flex; justify-content: space-between; align-items: center;
}
.modal-header h3 { font-size: 18px; font-weight: 700; }
.modal-close {
    background: none; border: none; font-size: 24px;
    color: #aaa; cursor: pointer; line-height: 1;
}
.modal-close:hover { color: #333; }
.modal-body { padding: 22px; }
.modal-footer {
    padding: 14px 22px; border-top: 1px solid #eee;
    display: flex; justify-content: flex-end; gap: 10px;
}

/* ============================================================
   RESPONSIVE STYLES
   ============================================================ */
@media (max-width: 1024px) {
    .row-grid { grid-template-columns: 1fr; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .sa-4col { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-wrapper { margin-left: 0; }
    .menu-toggle { display: block; }
    .content-area { padding: 16px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .sa-field-row { grid-template-columns: 1fr; }
    .sa-4col { grid-template-columns: 1fr; }
    .sa-field.full { grid-column: span 1; }
    .sa-customer-grid { flex-direction: column-reverse; }
    .sa-customer-photo { width: 100%; flex-direction: row; align-items: center; }
    .sa-photo-box { width: 100px; height: 120px; }
    .sa-doc-page { padding: 10px; }
    .sa-form-meta { flex-direction: column; gap: 8px; }
    .page-header { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .sa-doc-signatures { flex-direction: column; gap: 30px; align-items: center; }
}

/* ============================================================
   PRINT STYLES (For View Page)
   ============================================================ */
@media print {
    .sidebar, .topbar, .page-header, .sa-form-actions, .btn, .modal-overlay { display: none !important; }
    .main-wrapper { margin-left: 0 !important; }
    .content-area { padding: 0 !important; }
    .sa-document-view { padding: 0; }
    .sa-doc-page {
        box-shadow: none; border: none; max-width: 100%; padding: 0;
    }
    body { background: #fff; }
}