/* ===== Base ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --dark: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --bg: #f3f5f9;
    --white: #ffffff;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --radius: 12px;
    --sidebar-width: 250px;
    --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
}

body {
    font-family: "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--dark);
    font-size: 14px;
    line-height: 1.45;
}

a { color: inherit; text-decoration: none; }

/* ===== Buttons and inputs ===== */
.btn {
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: inline-block;
    text-align: center;
    font-family: inherit;
    transition: background 0.15s;
}
.btn-primary { background: var(--brand-primary); color: var(--white); }
.btn-primary:hover { background: var(--brand-primary-dark); }
.btn-success { background: var(--success); color: var(--white); }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-light { background: var(--bg); color: var(--dark); }
.btn-outline { background: var(--white); color: var(--dark); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg); }
.btn-small { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; margin-top: 16px; }

input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: var(--white);
    color: var(--dark);
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--brand-primary);
    border-color: transparent;
}
input[readonly] { background: var(--bg); color: var(--muted); }

/* ===== App shell ===== */
.app { display: flex; height: 100vh; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.content { flex: 1; overflow-y: auto; padding: 24px; }

.page-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap;
    margin-bottom: 20px;
}
.page-header h2 { font-size: 22px; }
.page-header p { color: var(--muted); margin-top: 2px; }

/* ===== Sidebar (control bar) ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--brand-sidebar);
    color: #cfd8f3;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.brand-mark {
    width: 36px; height: 36px;
    background: var(--brand-primary);
    color: var(--white);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 20px;
}
.brand-name { font-size: 19px; font-weight: 700; color: var(--white); }
.brand-name small { color: var(--brand-accent); font-weight: 600; }

.sidebar-nav { padding: 14px 10px; flex: 1; }
.nav-link, .nav-group-toggle {
    display: flex; align-items: center; gap: 12px;
    width: 100%;
    padding: 11px 12px;
    border-radius: 8px;
    color: inherit;
    background: none;
    border: none;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    margin-bottom: 4px;
}
.nav-link:hover, .nav-group-toggle:hover { background: var(--brand-sidebar-hover); color: var(--white); }
.nav-link.active { background: var(--brand-primary); color: var(--white); }
.nav-icon { font-size: 18px; width: 22px; text-align: center; }
.nav-arrow { margin-left: auto; font-size: 11px; transition: transform 0.2s; }
.nav-group.open .nav-arrow { transform: rotate(90deg); }
.nav-group.has-active > .nav-group-toggle { color: var(--white); }
.nav-group-toggle .nav-badge + .nav-arrow { margin-left: 8px; }

.nav-sub { display: none; margin: 2px 0 6px 22px; padding-left: 12px; border-left: 1px solid rgba(255, 255, 255, 0.12); }
.nav-group.open .nav-sub { display: block; }
.nav-sub .nav-link { font-weight: 500; padding: 9px 12px; font-size: 13.5px; }

.nav-badge {
    margin-left: auto;
    background: var(--danger);
    color: var(--white);
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    padding: 1px 6px;
    border-radius: 10px;
    text-align: center;
}
.sidebar-footer { padding: 12px 10px; border-top: 1px solid rgba(255, 255, 255, 0.08); }

.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 40;
}

/* ===== Top bar ===== */
.topbar {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    height: 60px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
}
.menu-toggle { display: none; background: none; border: none; font-size: 22px; cursor: pointer; }
.page-title { font-size: 18px; font-weight: 700; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.clock { color: var(--muted); font-size: 13px; }
.user-chip { display: flex; align-items: center; gap: 10px; font-weight: 600; }

.avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--brand-primary-light);
    color: var(--brand-primary);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    overflow: hidden;
    flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ===== Panels and stat cards ===== */
.panel {
    background: var(--white);
    border-radius: var(--radius);
    padding: 20px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.panel + .panel { margin-top: 20px; }
.panel-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap;
    margin-bottom: 16px;
}
.section-title { font-weight: 700; font-size: 16px; }
.section-sub { color: var(--muted); font-size: 13px; font-weight: 400; margin-top: 2px; }
.panel-tools { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.panel-tools input, .panel-tools select { width: 220px; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.stat-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    position: relative;
}
.stat-card::before {
    content: "";
    position: absolute; left: 0; top: 14px; bottom: 14px;
    width: 4px; border-radius: 0 4px 4px 0;
    background: var(--brand-primary);
}
.stat-card.success::before { background: var(--success); }
.stat-card.warning::before { background: var(--warning); }
.stat-card.danger::before { background: var(--danger); }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.stat-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 640px; }
.data-table th {
    text-align: left;
    background: var(--bg);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--muted);
    padding: 11px 12px;
    white-space: nowrap;
}
.data-table th:first-child { border-radius: 8px 0 0 8px; }
.data-table th:last-child { border-radius: 0 8px 8px 0; }
.data-table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:hover td { background: #fafbff; }
.data-table .num { text-align: right; }
.table-empty { text-align: center; color: var(--muted); padding: 36px 12px !important; }
.cell-sub { color: var(--muted); font-size: 12px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.badge-ok, .badge-paid { background: var(--success-light); color: var(--success); }
.badge-low, .badge-partial { background: var(--warning-light); color: var(--warning); }
.badge-out, .badge-expired, .badge-due { background: var(--danger-light); color: var(--danger); }

/* ===== Forms ===== */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.form-group .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.form-group.full { grid-column: 1 / -1; }
.form-group + .form-group { margin-top: 12px; }
.form-grid .form-group + .form-group { margin-top: 0; }
.required { color: var(--danger); }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }

.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert-success { background: var(--success-light); color: #166534; }
.alert-error { background: var(--danger-light); color: #991b1b; }
.form-message { margin-top: 14px; display: none; }
.form-message.show { display: block; margin-bottom: 0; }

/* ===== Segmented control ===== */
.segmented {
    display: inline-flex;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px;
    gap: 4px;
}
.segmented button {
    border: none; background: none;
    padding: 8px 16px;
    border-radius: 7px;
    font-weight: 600;
    cursor: pointer;
    color: var(--muted);
    font-family: inherit;
    font-size: 13px;
}
.segmented button.active { background: var(--brand-primary); color: var(--white); }

/* ===== Modal ===== */
.modal {
    position: fixed; inset: 0;
    background: rgba(15, 27, 61, 0.55);
    display: none;
    align-items: center; justify-content: center;
    z-index: 60;
    padding: 16px;
}
.modal.open { display: flex; }
.modal-box {
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%; max-width: 420px;
    max-height: 92vh; overflow-y: auto;
}
.modal-box.modal-wide { max-width: 780px; }
.modal-box h3 { margin-bottom: 14px; font-size: 18px; }
.modal-box label { display: block; font-size: 13px; color: var(--dark); font-weight: 600; margin-bottom: 4px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }

/* ===== Responsive shell ===== */
@media (max-width: 900px) {
    .sidebar {
        position: fixed; top: 0; bottom: 0; left: 0;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.25s;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.show { display: block; }
    .menu-toggle { display: block; }
    .clock, .user-name { display: none; }
    .content { padding: 14px; }
    .topbar { padding: 0 14px; }
    .form-grid { grid-template-columns: 1fr; }
    .panel-tools input, .panel-tools select { width: 100%; }
    .panel-tools { width: 100%; }
}
