/* ==========================================================
   E-Billing Dashboard — Design System v3
   ========================================================== */

/* --- CSS Custom Properties --- */
:root {
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --sidebar-width: 260px;
    --sidebar-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-hover: #1e293b;
    --sidebar-active-text: #fff;
    --sidebar-active-bg: rgba(99, 102, 241, 0.15);
    --sidebar-active-border: #6366f1;
    --accent-start: #6366f1;
    --accent-end: #8b5cf6;
    --accent: #6366f1;
    --accent-light: rgba(99, 102, 241, 0.1);
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-hover: #f8fafc;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.1);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.1);
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.1);
    --header-height: 70px;
    --content-padding: 32px;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.06);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body { font-family: var(--font-family); background: var(--bg); color: var(--text-primary); display: flex; min-height: 100vh; overflow-x: hidden; }
a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: 0.9rem; }
table { border-collapse: collapse; width: 100%; }

/* --- Sidebar --- */
.sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-width); background: var(--sidebar-bg); display: flex; flex-direction: column; z-index: 100; transition: transform var(--transition-slow); }
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 24px 24px 32px; }
.brand-text { font-size: 1.25rem; font-weight: 700; color: #fff; letter-spacing: -0.02em; }
.sidebar-nav { flex: 1; padding: 0 12px; display: flex; flex-direction: column; gap: 4px; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-radius: var(--radius-sm); color: var(--sidebar-text); font-size: 0.9rem; font-weight: 500; transition: all var(--transition); border-left: 3px solid transparent; }
.nav-link:hover { background: var(--sidebar-hover); color: #cbd5e1; }
.nav-link.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); border-left-color: var(--sidebar-active-border); }
.nav-icon { width: 20px; height: 20px; flex-shrink: 0; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,0.06); display: flex; align-items: center; justify-content: space-between; }
.sidebar-user { display: flex; align-items: center; gap: 10px; }
.sidebar-user-avatar { width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, var(--accent-start), var(--accent-end)); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 0.8rem; flex-shrink: 0; }
.sidebar-user-name { font-size: 0.82rem; font-weight: 600; color: #e2e8f0; }
.sidebar-user-role { font-size: 0.7rem; color: var(--sidebar-text); text-transform: capitalize; }
.btn-logout { padding: 6px; border-radius: var(--radius-xs); color: var(--sidebar-text); transition: all var(--transition); cursor: pointer; background: none; border: none; }
.btn-logout:hover { color: var(--danger); background: rgba(239, 68, 68, 0.1); }

/* --- Hamburger --- */
.hamburger { display: none; position: fixed; top: 18px; left: 16px; z-index: 200; width: 36px; height: 36px; flex-direction: column; justify-content: center; align-items: center; gap: 5px; }
.hamburger span { display: block; width: 22px; height: 2px; background: var(--text-primary); border-radius: 2px; transition: var(--transition); }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 90; opacity: 0; transition: opacity var(--transition-slow); }
.sidebar-overlay.show { display: block; opacity: 1; }

/* --- Main --- */
.main-wrapper { margin-left: var(--sidebar-width); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.top-header { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; justify-content: space-between; height: var(--header-height); padding: 0 var(--content-padding); background: rgba(255,255,255,0.8); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); }
.page-title { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; }
.header-right { display: flex; align-items: center; gap: 16px; }
.header-date { font-size: 0.85rem; color: var(--text-secondary); font-weight: 500; }
.avatar-circle { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, var(--accent-start), var(--accent-end)); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 0.85rem; }
.content-area { flex: 1; padding: var(--content-padding); animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* --- Cards --- */
.card { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); transition: all var(--transition); }
.card:hover { box-shadow: var(--shadow-md); }
.metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; margin-bottom: 32px; }
.metric-card { padding: 24px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); position: relative; overflow: hidden; transition: all var(--transition); }
.metric-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, var(--accent-start), var(--accent-end)); opacity: 0; transition: opacity var(--transition); }
.metric-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg), var(--shadow-glow); }
.metric-card:hover::before { opacity: 1; }
.metric-card .metric-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.metric-card .metric-value { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.03em; }
.metric-card .metric-icon { position: absolute; top: 20px; right: 20px; width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.metric-card .metric-icon svg { width: 22px; height: 22px; }
.metric-card.revenue .metric-value { color: var(--success); }
.metric-card.revenue .metric-icon { background: var(--success-bg); color: var(--success); }
.metric-card.paid .metric-value { color: var(--accent); }
.metric-card.paid .metric-icon { background: var(--accent-light); color: var(--accent); }
.metric-card.clients .metric-value { color: var(--text-primary); }
.metric-card.clients .metric-icon { background: var(--accent-light); color: var(--accent); }

/* --- Section headers --- */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-title { font-size: 1.05rem; font-weight: 700; }
.form-section-label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 12px; }

/* --- Data Table --- */
.table-wrapper { overflow-x: auto; }
.data-table { width: 100%; }
.data-table th { text-align: left; padding: 12px 16px; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); border-bottom: 2px solid var(--border); }
.data-table td { padding: 14px 16px; font-size: 0.88rem; border-bottom: 1px solid var(--border-light); color: var(--text-secondary); }
.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: var(--surface-hover); }

/* --- Badges --- */
.badge { display: inline-flex; align-items: center; padding: 4px 12px; border-radius: 20px; font-size: 0.75rem; font-weight: 600; text-transform: capitalize; }
.badge.paid { background: var(--success-bg); color: var(--success); }
.badge.unpaid { background: var(--warning-bg); color: var(--warning); }

/* --- Buttons --- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 20px; border-radius: var(--radius-sm); font-size: 0.88rem; font-weight: 600; transition: all var(--transition); }
.btn-primary { background: linear-gradient(135deg, var(--accent-start), var(--accent-end)); color: #fff; box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4); }
.btn-secondary { background: var(--surface); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface-hover); border-color: var(--accent); }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-icon { padding: 8px; border-radius: var(--radius-xs); }

/* --- Forms --- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full-width { grid-column: 1 / -1; }
.form-label { font-size: 0.82rem; font-weight: 600; color: var(--text-secondary); }
.form-input, .form-select { padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-xs); background: var(--surface); color: var(--text-primary); transition: border-color var(--transition), box-shadow var(--transition); outline: none; }
.form-input:focus, .form-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.form-input::placeholder { color: var(--text-muted); }

/* --- Line Items Table (Form) --- */
.line-items-section { margin-top: 24px; }
.line-items-table { width: 100%; margin-bottom: 12px; }
.line-items-table th { text-align: left; padding: 8px 12px; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; color: var(--text-muted); border-bottom: 2px solid var(--border); }
.line-items-table td { padding: 8px 12px; }
.line-items-table .form-input { width: 100%; }
.line-items-table .price-input { width: 110px; }
.line-item-total { font-weight: 600; color: var(--text-primary); min-width: 100px; }

/* --- Totals section (bill form only — scoped to avoid conflicting with bill-table .total-row) --- */
.totals-section { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; padding: 20px 0; border-top: 2px solid var(--border); margin-top: 16px; }
.totals-section .total-row { display: flex; align-items: center; gap: 32px; font-size: 0.9rem; }
.total-label { color: var(--text-secondary); font-weight: 500; min-width: 140px; text-align: right; }
.total-value { font-weight: 700; min-width: 120px; text-align: right; }
.totals-section .total-row.grand { font-size: 1.15rem; padding-top: 8px; border-top: 2px solid var(--border); }
.totals-section .total-row.grand .total-value { color: var(--accent); }

/* --- Toolbar --- */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.search-box { flex: 1; min-width: 200px; position: relative; }
.search-box .form-input { width: 100%; padding-left: 40px; }
.search-box .search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); width: 18px; height: 18px; }

/* --- Profile Page --- */
.profile-grid { display: grid; grid-template-columns: 1fr; gap: 24px; }
.config-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.config-row .form-input, .config-row .form-select { min-width: 100px; flex: 1; padding: 8px 12px; font-size: 0.85rem; }

/* ============================================================
   TAX INVOICE PRINT LAYOUT
   ============================================================ */
.bill-page {
    max-width: 800px; margin: 0 auto;
    padding: 24px;
    background: #fff; font-family: 'Times New Roman', Times, serif;
    color: #000; font-size: 13px; line-height: 1.5;
}

/* Section spacing — each major block gets vertical margin */
.bill-section { margin-bottom: 16px; }
.bill-section:last-child { margin-bottom: 0; }

/* Header */
.bill-top-header {
    text-align: center;
    padding-bottom: 16px; border-bottom: 2px solid #000;
}
.bill-center { text-align: center; }
.bill-type { font-size: 16px; font-weight: 700; letter-spacing: 2px; color: #c00; margin-bottom: 6px; }
.bill-company-name { font-size: 34px; font-weight: 900; letter-spacing: 1px; line-height: 1.2; }
.bill-subtitle { font-size: 13px; font-weight: 700; margin-top: 4px; }
.bill-address { font-size: 13px; font-weight: 700; margin-top: 4px; letter-spacing: 0.3px; }
.bill-phones-center { font-size: 12px; margin-top: 6px; font-weight: 600; }

/* Info Bar */
.bill-info-bar {
    display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px;
    padding: 10px 0; border-top: 1px solid #000; border-bottom: 1px solid #000;
    font-size: 12px; font-weight: 600; background: transparent;
}
.bill-info-bar span { margin-right: 16px; }

/* Recipient + Serial */
.bill-recipient-section {
    display: flex; border: 1px solid #000;
}
.bill-recipient {
    flex: 1; padding: 12px 16px; border-right: 1px solid #000;
}
.bill-serial-box {
    width: 180px; padding: 12px 16px;
}
.bill-field { font-size: 12px; margin-bottom: 4px; line-height: 1.5; }
.bill-field-label { font-weight: 700; }

/* Bill Items Table */
.bill-table {
    width: 100%; border-collapse: collapse; table-layout: fixed;
}
.bill-table th {
    border: 1px solid #000; padding: 8px 8px; font-size: 11px; font-weight: 700;
    text-align: left; background: #f5f5f5; text-transform: none;
    word-wrap: break-word; overflow-wrap: break-word;
}
.bill-table td {
    border: 1px solid #000; padding: 6px 8px; font-size: 12px;
    vertical-align: top; word-wrap: break-word; overflow-wrap: break-word;
}
.bill-table .text-center { text-align: center; }
.bill-table .text-right { text-align: right; }
.bill-table .font-bold { font-weight: 700; }
.bill-table .total-row td {
    border-top: 2px solid #000; border-bottom: 2px solid #000;
    padding: 8px 8px; font-weight: 700; font-size: 12px;
    background: #f5f5f5;
}

/* Bill Bottom Section — Bank + Calc side by side */
.bill-bottom {
    display: flex; border: 1px solid #000;
}
.bill-bank {
    flex: 1; padding: 12px 16px; border-right: 1px solid #000; font-size: 11px;
}
.bank-row { margin-bottom: 6px; line-height: 1.5; }
.bill-calculations {
    width: 260px; padding: 10px 14px;
}
.calc-row {
    display: flex; justify-content: space-between; font-size: 12px;
    padding: 4px 0; border-bottom: 1px dotted #ccc;
}
.calc-row.grand {
    font-weight: 900; font-size: 13px; border-top: 2px solid #000;
    border-bottom: 2px solid #000; padding: 8px 0; margin-top: 6px;
}

/* Bill Footer */
.bill-words {
    padding: 12px 0; border-top: 1px solid #000; border-bottom: 1px solid #000; font-size: 12px;
}
.bill-words .bill-field { margin-bottom: 5px; }
.bill-notes-line {
    padding: 8px 0; font-size: 11px;
}
.bill-signature {
    padding-top: 50px; text-align: right; font-size: 13px;
}
.sig-line { font-weight: 400; margin-bottom: 4px; }
.sig-company { font-weight: 700; font-size: 14px; }

.invoice-actions { display: flex; gap: 12px; margin-bottom: 20px; }

/* --- Toast --- */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 14px 20px; border-radius: var(--radius-sm); font-size: 0.88rem; font-weight: 500; color: #fff; box-shadow: var(--shadow-lg); animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s forwards; max-width: 360px; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

/* --- Loader --- */
.page-loader { display: flex; align-items: center; justify-content: center; min-height: 300px; }
.loader-spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state p { font-size: 0.95rem; }

/* --- Responsive --- */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .hamburger { display: flex; }
    .main-wrapper { margin-left: 0; }
    .content-area { padding: 20px 16px; }
    .top-header { padding: 0 16px 0 56px; }
    .form-grid { grid-template-columns: 1fr; }
    .metrics-grid { grid-template-columns: 1fr; }
    .bill-page { font-size: 11px; padding: 16px; }
    .bill-company-name { font-size: 28px; }
    .bill-recipient-section { flex-direction: column; }
    .bill-serial-box { width: 100%; border-right: none; border-top: 1px solid #000; }
    .bill-bottom { flex-direction: column; }
    .bill-calculations { width: 100%; border-top: 1px solid #000; }
}

/* --- Print --- */
@media print {
    body { background: #fff; }
    .sidebar, .hamburger, .top-header, .toast-container, .invoice-actions, .sidebar-overlay { display: none !important; }
    .main-wrapper { margin-left: 0; }
    .content-area { padding: 0; }
    .bill-page { max-width: 100%; box-shadow: none; padding: 20px; }
}

/* --- Login Page --- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #312e81 100%); }
.login-container { width: 100%; max-width: 420px; padding: 20px; }
.login-card { background: rgba(255,255,255,0.95); backdrop-filter: blur(20px); border-radius: var(--radius); padding: 40px; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.3); border: 1px solid rgba(255,255,255,0.2); }
.login-header { text-align: center; margin-bottom: 32px; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 12px; }
.login-brand h1 { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; background: linear-gradient(135deg, var(--accent-start), var(--accent-end)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.login-subtitle { font-size: 0.9rem; color: var(--text-muted); }
.login-card .form-group { margin-bottom: 16px; }
.login-error { padding: 10px 14px; border-radius: var(--radius-xs); margin-bottom: 16px; background: var(--danger-bg); color: var(--danger); font-size: 0.85rem; font-weight: 500; }
.login-btn { width: 100%; padding: 12px; font-size: 0.95rem; margin-top: 8px; }

/* --- Modal --- */
.modal-overlay { position: fixed; inset: 0; z-index: 500; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; padding: 20px; animation: fadeIn 0.2s ease; }
.modal-card { background: var(--surface); border-radius: var(--radius); padding: 28px; width: 100%; max-width: 460px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); animation: fadeIn 0.2s ease; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-header h3 { font-size: 1.1rem; font-weight: 700; }
.modal-header .btn-icon { font-size: 1.3rem; color: var(--text-muted); }
.modal-card .form-group { margin-bottom: 14px; }
