:root {
    --bg: #f3f5fa;
    --surface: #ffffff;
    --border: #e7eaf2;
    --border-soft: #eef1f7;
    --text: #171b2b;
    --text-muted: #6b7280;
    --sidebar-bg: #10142a;
    --sidebar-text: #9aa1ba;
    --sidebar-active-bg: #1b2036;
    --accent: #4f5fff;
    --accent-dark: #3d4bdb;
    --accent-soft: #eef0ff;
    --good: #17945a;
    --good-soft: #e6f8ef;
    --warn: #b07c07;
    --warn-soft: #fff3d6;
    --danger: #d1453b;
    --danger-soft: #fdecea;
    --radius: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(20, 24, 40, 0.04);
    --shadow: 0 1px 2px rgba(20, 24, 40, 0.04), 0 8px 20px -10px rgba(20, 24, 40, 0.10);
    --shadow-lg: 0 1px 2px rgba(20, 24, 40, 0.04), 0 20px 40px -18px rgba(20, 24, 40, 0.20);
    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

h1, h2, h3 { font-family: var(--font); letter-spacing: -0.015em; }

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

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 22px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    margin-bottom: 6px;
}

.brand-mark {
    background: linear-gradient(135deg, #6a78ff 0%, #4f5fff 60%, #3d4bdb 100%);
    color: #fff;
    font-weight: 800;
    font-size: 12.5px;
    padding: 7px 9px;
    border-radius: 8px;
    letter-spacing: 0.4px;
    box-shadow: 0 4px 10px -4px rgba(79, 95, 255, 0.6);
}

.brand-name {
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.01em;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    padding: 8px 12px 16px;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--sidebar-text);
    font-size: 13.3px;
    font-weight: 500;
    transition: background-color 0.12s ease, color 0.12s ease;
}

.nav-item:hover {
    background: rgba(255,255,255,0.055);
    color: #fff;
}

.nav-item.active {
    background: var(--sidebar-active-bg);
    color: #fff;
    font-weight: 600;
    box-shadow: inset 2.5px 0 0 var(--accent);
}

.nav-icon {
    font-size: 15px;
    width: 18px;
    text-align: center;
}

.main-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 13px 28px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: saturate(180%) blur(10px);
    -webkit-backdrop-filter: saturate(180%) blur(10px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 5;
}

.hamburger {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text);
}

.search-box { flex: 1; max-width: 440px; position: relative; display: flex; align-items: center; }

.search-icon {
    position: absolute;
    left: 13px;
    color: var(--text-muted);
    font-size: 15px;
    pointer-events: none;
}

.search-box input {
    width: 100%;
    padding: 9px 14px 9px 34px;
    border-radius: 9px;
    border: 1.5px solid var(--border);
    background: var(--bg);
    font-size: 13.3px;
    font-family: inherit;
    transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.search-box input:hover { border-color: #c7cce0; }

.search-box input:focus {
    outline: none;
    background: var(--surface);
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(79, 95, 255, 0.12);
}

.topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 18px;
}

.bell {
    font-size: 15px;
    cursor: default;
    opacity: 0.75;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    transition: background-color 0.12s ease;
}

.bell:hover { background: var(--bg); opacity: 1; }

.user-chip { display: flex; align-items: center; gap: 9px; }

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 999px;
    background: linear-gradient(135deg, #6a78ff, #3d4bdb);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-name { font-weight: 600; font-size: 13.3px; }

.logout-form { margin: 0; }

.btn-link {
    background: none;
    border: none;
    color: var(--danger);
    font-weight: 600;
    cursor: pointer;
    font-size: 13px;
    padding: 0;
}

.content {
    padding: 26px 30px 44px;
    max-width: 1280px;
}

/* ---------- Page header ---------- */
.page-header h1 {
    margin: 0 0 3px;
    font-size: 23px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.page-subtitle {
    margin: 0 0 20px;
    color: var(--text-muted);
    font-size: 13.5px;
}

/* ---------- Notices ---------- */
.notice-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
}

.notice {
    display: inline-flex;
    align-items: center;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid transparent;
    transition: border-color 0.12s ease, transform 0.1s ease;
    cursor: pointer;
}

.notice:hover { transform: translateY(-1px); }

.notice-warn { background: #fff6e0; color: #91660a; }
.notice-warn:hover { border-color: #f0d896; }
.notice-danger { background: var(--danger-soft); color: var(--danger); }
.notice-danger:hover { border-color: #f3c9c5; }

/* ---------- KPI cards ---------- */
.section-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin: 32px 0 13px;
}

.kpi-section:first-of-type .section-title { margin-top: 0; }

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 9px;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.kpi-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }

.kpi-label {
    font-size: 12.5px;
    color: var(--text-muted);
    font-weight: 600;
}

.kpi-value {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

.kpi-good { color: var(--good); }
.kpi-warn { color: var(--warn); }
.kpi-danger { color: var(--danger); }
.kpi-muted { color: var(--text-muted); }

/* ---------- Activity ---------- */
.activity-section { margin-top: 8px; }

.activity-list {
    list-style: none;
    margin: 0;
    padding: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.activity-list li {
    display: flex;
    gap: 14px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    align-items: baseline;
}

.activity-list li:last-child { border-bottom: none; }

.activity-date { color: var(--text-muted); flex-shrink: 0; width: 130px; }
.activity-user { font-weight: 600; flex-shrink: 0; }
.activity-desc { color: var(--text); }

.empty-state {
    color: var(--text-muted);
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    font-size: 13.5px;
}

/* ---------- Auth pages ---------- */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background:
        radial-gradient(circle at 15% 15%, rgba(107, 122, 255, 0.25), transparent 45%),
        radial-gradient(circle at 85% 85%, rgba(61, 75, 219, 0.3), transparent 50%),
        linear-gradient(160deg, #0e1220 0%, #171d38 55%, #232c58 100%);
}

.auth-wrap { width: 100%; max-width: 400px; padding: 20px; }

.auth-card {
    background: var(--surface);
    border-radius: 20px;
    padding: 38px 36px;
    box-shadow: 0 30px 70px -20px rgba(8, 10, 25, 0.55);
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 28px;
}

.auth-brand .brand-name { color: var(--text); }

.auth-title {
    font-size: 21px;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin: 0 0 4px;
}

.auth-subtitle {
    color: var(--text-muted);
    font-size: 13px;
    margin: 0 0 22px;
    line-height: 1.5;
}

.auth-form { display: flex; flex-direction: column; gap: 4px; }

.auth-form label {
    font-size: 12.5px;
    font-weight: 600;
    margin-top: 14px;
    color: var(--text-muted);
}

.auth-form input {
    padding: 11px 14px;
    border-radius: 10px;
    border: 1.5px solid var(--border);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.auth-form input:hover { border-color: #c7cce0; }

.auth-form input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(79,95,255,0.14);
}

.btn-primary {
    margin-top: 22px;
    background: linear-gradient(135deg, #5d6bff 0%, #4f5fff 55%, #3d4bdb 100%);
    color: #fff;
    border: none;
    padding: 12px 16px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    text-align: center;
    box-shadow: 0 10px 24px -10px rgba(79, 95, 255, 0.65);
    transition: transform 0.1s ease, box-shadow 0.15s ease;
}

.btn-primary:hover { box-shadow: 0 14px 28px -10px rgba(79, 95, 255, 0.75); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-primary:hover { background: var(--accent-dark); }

.alert {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 8px;
}

.alert-error { background: #fdecea; color: var(--danger); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        z-index: 20;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 0 0 40px rgba(0,0,0,0.3);
    }

    .sidebar.open { transform: translateX(0); }

    .hamburger { display: inline-flex; }

    .search-box { max-width: none; }

    .user-name { display: none; }

    .content { padding: 18px 16px 32px; }

    .activity-list li { flex-wrap: wrap; }
    .activity-date { width: auto; }
}

/* ---------- Toolbar / filters ---------- */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
}

.toolbar-spacer { flex: 1; }

.filter-tabs {
    display: flex;
    gap: 3px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 3px;
    box-shadow: var(--shadow-sm);
}

.filter-tabs a {
    padding: 6px 13px;
    border-radius: 7px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    transition: background-color 0.12s ease, color 0.12s ease;
}

.filter-tabs a:hover { color: var(--text); }

.filter-tabs a.active {
    background: var(--accent);
    color: #fff;
}

.search-input {
    padding: 8px 13px;
    border-radius: 9px;
    border: 1.5px solid var(--border);
    font-size: 13px;
    font-family: inherit;
    min-width: 220px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-input:hover { border-color: #c7cce0; }
.search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(79, 95, 255, 0.12); }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 15px;
    border-radius: 9px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    border: 1.5px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.12s ease, background-color 0.12s ease, box-shadow 0.12s ease, transform 0.1s ease;
}

.btn:hover { border-color: #c7cce0; background: var(--bg); }

.btn-accent {
    background: linear-gradient(135deg, #5d6bff 0%, #4f5fff 55%, #3d4bdb 100%);
    border-color: transparent;
    color: #fff;
    box-shadow: 0 8px 18px -8px rgba(79, 95, 255, 0.55);
}
.btn-accent:hover { box-shadow: 0 10px 22px -8px rgba(79, 95, 255, 0.65); transform: translateY(-1px); border-color: transparent; }
.btn-sm { padding: 5px 11px; font-size: 12px; border-radius: 7px; }
.btn-danger-outline { color: var(--danger); border-color: #f3c9c5; background: var(--surface); }
.btn-danger-outline:hover { background: var(--danger-soft); border-color: #f3c9c5; }

/* ---------- Table ---------- */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
}

table.data-table { width: 100%; border-collapse: collapse; font-size: 13.3px; }

.data-table th {
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 700;
    padding: 12px 16px;
    background: #fafbfd;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-soft);
    vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr { transition: background-color 0.1s ease; }
.data-table tr:hover td { background: #fafbfd; }
.data-table a.row-link { color: var(--text); text-decoration: none; font-weight: 700; }
.data-table a.row-link:hover { color: var(--accent); }

/* ---------- Badge ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3.5px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.badge-active, .badge-paid { background: var(--good-soft); color: var(--good); }
.badge-passive { background: #eef0f5; color: var(--text-muted); }
.badge-pending { background: var(--warn-soft); color: var(--warn); }
.badge-overdue, .badge-cancelled { background: var(--danger-soft); color: var(--danger); }

/* ---------- Pagination ---------- */
.pagination {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 16px;
    font-size: 13px;
    color: var(--text-muted);
}

.pagination a {
    padding: 5px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    color: var(--text);
    text-decoration: none;
}

.pagination a.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pagination-spacer { flex: 1; }

/* ---------- Form ---------- */
.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 1px 2px rgba(20, 24, 40, 0.04), 0 10px 28px -16px rgba(20, 24, 40, 0.16);
    padding: 30px 32px;
    margin-bottom: 22px;
}

.form-card h2 {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 0 0 22px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px 28px;
}

.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.field label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-muted);
    letter-spacing: 0.01em;
}

.field input, .field select, .field textarea {
    width: 100%;
    padding: 11px 14px;
    border-radius: 9px;
    border: 1.5px solid var(--border);
    font-size: 13.5px;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input::placeholder, .field textarea::placeholder { color: #b3b9c9; }

.field input:hover, .field select:hover, .field textarea:hover { border-color: #c7cce0; }

.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(79, 95, 255, 0.12);
}

.field select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
    cursor: pointer;
}

.field textarea { resize: vertical; min-height: 92px; line-height: 1.55; }
.field.full { grid-column: 1 / -1; }
.field + .field { margin-top: 0; }

@media (max-width: 720px) {
    .form-card { padding: 22px 20px; }
    .form-grid, .form-grid.cols-3 { grid-template-columns: 1fr; gap: 16px; }
}

/* ---------- Service flags (chip checkboxes) ---------- */
.service-flags {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 4px;
}

.service-flag {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 10px 16px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    font-size: 13.3px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface);
    transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
    user-select: none;
}

.service-flag .flag-icon { font-size: 15px; }
.service-flag input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; margin: 0; }
.service-flag:hover { border-color: #c7cce0; }
.service-flag:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }

/* ---------- Pending setup badge/row ---------- */
.badge-waiting { background: var(--accent-soft); color: var(--accent-dark); }
.pending-row td { color: var(--text-muted); }

/* ---------- Tabs (detail page) ---------- */
.detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}

.detail-header h1 { margin: 0 0 4px; font-size: 20px; }
.detail-meta { color: var(--text-muted); font-size: 13px; display: flex; gap: 14px; flex-wrap: wrap; }

.tab-nav {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 18px;
    overflow-x: auto;
}

.tab-nav a {
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}

.tab-nav a.active { color: var(--accent); border-bottom-color: var(--accent); }

.placeholder-box {
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 30px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13.5px;
}
