:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg: #f4f6f9;
    --card-bg: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --surface-sunken: #f8fafc;
    --surface-hover: #f1f5f9;
    --border-strong: #cbd5e1;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.05);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --focus-ring: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
    --sidebar-bg: #ffffff;
    --sidebar-border: #eef1f6;
    --sidebar-width: 240px;
    --gradient-primary: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--primary) 65%, #7c3aed));
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 12px; font-weight: 700; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }

.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 20px; box-shadow: var(--shadow-sm); margin-bottom: 20px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid transparent; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { text-decoration: none; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

label { display: block; font-weight: 600; font-size: 13px; margin: 14px 0 6px; }
label:first-child { margin-top: 0; }
.form-row > label { margin-top: 14px; }
.form-row:first-child > label { margin-top: 0; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=tel], select, textarea {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus-ring); }
.hint { color: var(--text-muted); font-size: 13px; }
.form-row { display: flex; gap: 14px; }
.form-row > * { flex: 1; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { color: var(--text-muted); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-active, .badge-paid, .badge-signed { background: #dcfce7; color: #166534; }
.badge-suspended, .badge-draft { background: #f1f5f9; color: #475569; }
.badge-expired, .badge-overdue, .badge-cancelled { background: #fee2e2; color: #991b1b; }
.badge-sent { background: #dbeafe; color: #1e40af; }
.badge-expiring { background: #fef3c7; color: #92400e; }

.flash { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; }
.flash-success { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: #991b1b; }

/* ---- Staff app-shell (сайдбар) ---- */
.app-shell { display: flex; min-height: 100vh; }
.app-sidebar { width: var(--sidebar-width); flex-shrink: 0; background: var(--sidebar-bg); border-right: 1px solid var(--sidebar-border); display: flex; flex-direction: column; padding: 20px 0; }
.app-sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 0 20px 20px; font-weight: 800; font-size: 16px; }
.app-sidebar-brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--gradient-primary); flex-shrink: 0; }
.app-sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 0 12px; }
.app-sidebar-nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm); color: var(--text); font-weight: 500; font-size: 14px; }
.app-sidebar-nav a:hover { background: var(--surface-hover); text-decoration: none; }
.app-sidebar-nav a.active { background: color-mix(in srgb, var(--primary) 10%, transparent); color: var(--primary); font-weight: 700; }
.app-sidebar-nav svg { width: 18px; height: 18px; flex-shrink: 0; }
.app-sidebar-footer { padding: 12px 20px 0; border-top: 1px solid var(--sidebar-border); margin-top: 12px; }
.app-sidebar-footer svg { width: 18px; height: 18px; flex-shrink: 0; }
.app-main { flex: 1; min-width: 0; }
.app-topbar { display: flex; align-items: center; justify-content: flex-end; gap: 14px; padding: 14px 28px; background: #fff; border-bottom: 1px solid var(--border); }
.app-topbar-user { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }
.app-content { padding: 28px; max-width: 1100px; }

/* ---- Client topbar ---- */
.topbar { background: #fff; border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 60px; }
.topbar-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 16px; flex-shrink: 0; }
.topbar-brand-mark { width: 26px; height: 26px; border-radius: 8px; background: var(--gradient-primary); flex-shrink: 0; }
.topbar-nav { display: flex; gap: 4px; flex: 1; }
.topbar-nav a { padding: 8px 14px; border-radius: var(--radius-sm); font-weight: 600; font-size: 14px; color: var(--text-muted); }
.topbar-nav a:hover { background: var(--surface-hover); text-decoration: none; }
.topbar-nav a.active { color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, transparent); }
.topbar-user { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.topbar-lang { display: flex; gap: 2px; flex-shrink: 0; }
.topbar-lang a { padding: 4px 8px; border-radius: var(--radius-sm); font-size: 12px; font-weight: 700; color: var(--text-muted); }
.topbar-lang a:hover { background: var(--surface-hover); text-decoration: none; }
.topbar-lang a.active { color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, transparent); }
.client-content { max-width: 1100px; margin: 0 auto; padding: 28px 24px; }

/* ---- Auth pages ---- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.auth-card { width: 100%; max-width: 380px; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 24px; font-weight: 800; font-size: 18px; }
.auth-brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--gradient-primary); }

/* ---- Друковані види (рахунок/акт) ---- */
.print-page { max-width: 800px; margin: 0 auto; padding: 32px; background: #fff; }
.print-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; }
.print-actions { text-align: right; margin-bottom: 16px; }
.print-totals { text-align: right; font-size: 16px; font-weight: 700; margin-top: 12px; }
@media print {
    .print-actions { display: none !important; }
    body { background: #fff; }
}

/* ---- Класичний бланк "Рахунок на оплату" ---- */
.invoice-classic { font-size: 13px; color: #111; }
.invoice-notice { border: 1px solid #111; padding: 8px 12px; margin-bottom: 14px; font-size: 12px; }
.invoice-sample-box { border: 1px solid #111; margin-bottom: 18px; }
.invoice-sample-caption { text-align: center; font-weight: 700; padding: 6px; border-bottom: 1px solid #111; }
.invoice-sample-table { width: 100%; border-collapse: collapse; }
.invoice-sample-table td { border: 1px solid #111; padding: 4px 8px; vertical-align: top; font-size: 12px; }
.invoice-sample-table td.label { font-weight: 600; white-space: nowrap; }
.invoice-title { text-align: center; font-size: 18px; font-weight: 700; margin: 18px 0 14px; }
.invoice-parties p { margin: 2px 0 10px; line-height: 1.5; }
.invoice-items-table { width: 100%; border-collapse: collapse; margin-top: 10px; table-layout: fixed; }
.invoice-items-table th, .invoice-items-table td { border: 1px solid #111; padding: 6px 8px; font-size: 12px; word-wrap: break-word; }
.invoice-items-table th { text-align: center; font-weight: 700; }
.invoice-items-table td.num { text-align: center; }
.invoice-items-table td.amt { text-align: right; }
.invoice-items-table tfoot td { border: none; padding: 6px 8px; font-weight: 700; }
.invoice-items-table tfoot tr.vat-row td { font-weight: 400; }
.invoice-summary-line { margin-top: 6px; font-size: 12px; }
.invoice-amount-words { font-weight: 700; margin-top: 6px; }
.invoice-footer-note { margin-top: 20px; font-size: 12px; line-height: 1.5; }
.invoice-signature { margin-top: 28px; display: flex; align-items: flex-end; gap: 10px; }
.invoice-signature .sig-label { font-weight: 600; white-space: nowrap; }
.invoice-signature .sig-line { flex: 1; border-bottom: 1px solid #111; min-width: 200px; text-align: center; padding-bottom: 2px; }

/* ---- Dashboard stat cards ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 4px; }
.stat-card { margin-bottom: 0; }
.stat-card-label { color: var(--text-muted); font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.stat-card-value { font-size: 28px; font-weight: 800; }
.stat-card-sub { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ---- Вкладки (client_view.php, settings.php) ---- */
.tab-nav { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tab-nav button, .tab-nav a { background: none; border: none; padding: 10px 16px; font-size: 14px; font-weight: 600; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; font-family: inherit; text-decoration: none; display: inline-block; }
.tab-nav button:hover, .tab-nav a:hover { color: var(--text); text-decoration: none; }
.tab-nav button.active, .tab-nav a.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
