/* ============ Variables & Reset ============ */
:root {
    --accent: #1a56db;
    --bg: #f5f6f8;
    --card-bg: #ffffff;
    --border: #e2e5eb;
    --text: #1f2430;
    --text-muted: #6b7280;
    --danger: #dc2626;
    --success: #16a34a;
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }

/* ============ Auth Pages (login/install) ============ */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--accent), #0f2a6b);
}

.auth-card {
    background: var(--card-bg);
    padding: 32px;
    border-radius: var(--radius);
    width: 100%;
    max-width: 400px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.auth-card h1 { margin-bottom: 20px; }

/* ============ App Shell ============ */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 220px;
    background: #14181f;
    color: #fff;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-brand {
    padding: 20px 16px;
    font-weight: 600;
    font-size: 15px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-logo { max-height: 32px; max-width: 100%; }

.sidebar-nav { display: flex; flex-direction: column; padding: 12px 0; flex: 1; }

.sidebar-nav a {
    color: rgba(255,255,255,0.75);
    padding: 10px 16px;
    text-decoration: none;
}

.sidebar-nav a:hover, .sidebar-nav a.active {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,0.1);
    font-size: 13px;
}

.sidebar-user { color: rgba(255,255,255,0.6); margin-bottom: 6px; }
.sidebar-logout { color: #fff; }

.main-content {
    flex: 1;
    padding: 24px 32px;
    max-width: 1100px;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

/* ============ Cards & Grid ============ */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}

.stat-label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-value { font-size: 22px; font-weight: 700; margin-top: 6px; }
.stat-success .stat-value { color: var(--success); }
.stat-danger .stat-value { color: var(--danger); }

/* ============ Forms ============ */
label { display: block; font-weight: 600; margin: 12px 0 4px; font-size: 13px; }
label:first-child { margin-top: 0; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=color], input[type=file], select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}

textarea { resize: vertical; }

input[type=color] { padding: 2px; height: 38px; }

.narrow-form { max-width: 400px; }

.filter-bar { display: flex; gap: 10px; margin-bottom: 16px; }
.filter-bar input, .filter-bar select { width: auto; flex: 1; }

.form-actions { margin-top: 16px; display: flex; gap: 10px; }

/* ============ Buttons ============ */
.btn {
    display: inline-block;
    padding: 9px 16px;
    border-radius: 6px;
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

.btn:hover { text-decoration: none; opacity: 0.92; }
.btn-block { width: 100%; margin-top: 16px; }
.btn-sm { padding: 6px 10px; font-size: 13px; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: #eef0f3; color: var(--text); }

.link-plain, .link-danger {
    background: none;
    border: none;
    padding: 0;
    font-size: 13px;
    cursor: pointer;
    text-decoration: underline;
}

.link-plain { color: var(--accent); }
.link-danger { color: var(--danger); }

.row-actions { display: flex; gap: 10px; align-items: center; white-space: nowrap; }

/* ============ Table ============ */
.table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 13px; }
.table th { color: var(--text-muted); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: 0.03em; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }

/* ============ Badges & Alerts ============ */
.badge { padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-success { background: #dcfce7; color: #15803d; }
.badge-danger { background: #fee2e2; color: #b91c1c; }

.alert { padding: 12px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 13px; }
.alert ul { margin: 0; padding-left: 18px; }
.alert-success { background: #dcfce7; color: #15803d; }
.alert-error { background: #fee2e2; color: #b91c1c; }
.alert-info { background: #dbeafe; color: #1e40af; }

/* ============ Invoice line items form ============ */
.row-amount { display: inline-block; padding: 8px 0; font-weight: 600; }

.totals-box { max-width: 320px; margin-left: auto; margin-top: 16px; }
.totals-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; }
.totals-grand { font-weight: 700; font-size: 16px; border-top: 2px solid var(--border); margin-top: 4px; padding-top: 10px; }

.current-logo { margin-top: 8px; }
.current-logo img { max-height: 60px; }

/* ============ Printable Invoice ============ */
.invoice-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 24px;
    background: #fff;
    border-bottom: 1px solid var(--border);
}

.invoice-body { background: #eceef1; }

.invoice-sheet {
    background: #fff;
    max-width: 800px;
    margin: 24px auto;
    padding: 40px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

.invoice-head { display: flex; justify-content: space-between; margin-bottom: 24px; }
.invoice-company { max-width: 50%; }
.invoice-company h2 { margin-bottom: 6px; }
.invoice-logo { max-height: 60px; margin-bottom: 10px; }

.invoice-meta { text-align: right; }
.invoice-meta h1 { color: var(--accent); letter-spacing: 0.05em; margin-bottom: 12px; }

.meta-table { border-collapse: collapse; margin-left: auto; }
.meta-table td { padding: 3px 0 3px 16px; font-size: 13px; text-align: right; }
.meta-table td:first-child { color: var(--text-muted); }

.invoice-bill-to { margin-bottom: 24px; }
.invoice-bill-to .label { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 4px; }
.invoice-bill-to .client-name { font-weight: 700; font-size: 15px; }

.invoice-items-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.invoice-items-table th {
    background: var(--accent);
    color: #fff;
    padding: 8px 10px;
    font-size: 12px;
    text-transform: uppercase;
    text-align: left;
}
.invoice-items-table th.text-right, .invoice-items-table td.text-right { text-align: right; }
.invoice-items-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }

.invoice-totals { max-width: 280px; margin-left: auto; margin-bottom: 24px; }

.invoice-notes { margin-bottom: 16px; font-size: 13px; }
.invoice-notes .label { color: var(--text-muted); font-size: 11px; text-transform: uppercase; margin-bottom: 4px; }

.invoice-footer-note {
    border-top: 1px solid var(--border);
    padding-top: 14px;
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}

/* ============ Print ============ */
@media print {
    .no-print { display: none !important; }
    body.invoice-body { background: #fff; }
    .invoice-sheet { box-shadow: none; margin: 0; padding: 0; max-width: 100%; }
}

@page {
    size: A4;
    /* 0.3 inch margin on all sides for printing/PDF export */
    margin: 0.3in;
}

/* ============ Responsive ============ */
@media (max-width: 800px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; }
    .grid-2, .stat-grid { grid-template-columns: 1fr; }
    .main-content { padding: 16px; }
    .invoice-sheet { padding: 20px; }
    .invoice-head { flex-direction: column; gap: 16px; }
    .invoice-meta { text-align: left; }
    .meta-table { margin-left: 0; }
    .meta-table td { text-align: left; }
}
