:root {
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-size-base: 13px;
    --color-bg: #f4f5f6;
    --color-surface: #ffffff;
    --color-border: #e2e8f0;
    --color-text: #1c1c1c;
    --color-text-secondary: #6c7680;
    --color-primary: #2490ef;
    --color-primary-dark: #1a7fd4;
    --color-primary-bg: #e8f3fd;
    --color-success: #28a745;
    --color-success-bg: #e8f5e9;
    --color-warning: #f8a100;
    --color-warning-bg: #fff8e1;
    --color-danger: #e03636;
    --color-danger-bg: #fdecea;
    --color-info: #0ea5e9;
    --color-info-bg: #e0f2fe;
    --sidebar-width: 220px;
    --topbar-height: 48px;
    --border-radius: 6px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
}

.app-layout { display: flex; height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}

.main-wrap { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

.sidebar-header { padding: 14px 16px; border-bottom: 1px solid var(--color-border); flex-shrink: 0; }

.sidebar-logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--color-text); }

.sidebar-logo-icon {
    width: 28px; height: 28px; background: var(--color-primary);
    border-radius: 6px; display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: 11px; flex-shrink: 0;
}

.sidebar-logo-name { font-size: 13px; font-weight: 600; line-height: 1.2; }
.sidebar-logo-sub  { font-size: 11px; color: var(--color-text-secondary); font-weight: 400; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 0; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 2px; }

.nav-section-label {
    font-size: 10px; font-weight: 600; letter-spacing: .7px; text-transform: uppercase;
    color: var(--color-text-secondary); padding: 12px 16px 4px;
}

.nav-item {
    display: flex; align-items: center; gap: 8px; padding: 7px 16px;
    cursor: pointer; font-size: 13px; color: var(--color-text);
    text-decoration: none; transition: background .1s;
    border: 0; background: none; width: 100%; text-align: left; line-height: 1;
}
.nav-item:hover { background: var(--color-bg); }
.nav-item.active { background: var(--color-primary-bg); color: var(--color-primary); font-weight: 500; }
.nav-item svg { flex-shrink: 0; opacity: .6; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer { padding: 10px 16px; border-top: 1px solid var(--color-border); flex-shrink: 0; }
.user-row { display: flex; align-items: center; gap: 8px; }
.user-avatar {
    width: 28px; height: 28px; border-radius: 50%; background: var(--color-primary);
    color: #fff; font-size: 10px; font-weight: 700; display: flex;
    align-items: center; justify-content: center; flex-shrink: 0;
}
.user-name { font-size: 12px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 11px; color: var(--color-text-secondary); }

.tenant-pill {
    display: flex; align-items: center; gap: 6px; margin: 6px 8px;
    padding: 5px 10px; background: var(--color-bg);
    border: 1px solid var(--color-border); border-radius: var(--border-radius);
    font-size: 11.5px; color: var(--color-text-secondary); text-decoration: none; cursor: pointer;
}
.tenant-pill:hover { border-color: var(--color-primary); color: var(--color-text); }
.tenant-pill svg { flex-shrink: 0; }

.topbar {
    height: var(--topbar-height); background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex; align-items: center; padding: 0 20px; gap: 12px; flex-shrink: 0;
}
.topbar-title { font-weight: 600; font-size: 14px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.page-content { flex: 1; overflow-y: auto; padding: 20px; }
.page-content::-webkit-scrollbar { width: 6px; }
.page-content::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }

.stats-grid   { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; margin-bottom: 20px; }
.stats-grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; margin-bottom: 20px; }
.stats-grid-2 { display: grid; grid-template-columns: repeat(2,1fr); gap: 12px; margin-bottom: 20px; }

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: 14px 16px;
}
.stat-label { font-size: 11.5px; color: var(--color-text-secondary); margin-bottom: 5px; }
.stat-value { font-size: 22px; font-weight: 700; line-height: 1; }
.stat-delta { font-size: 11px; color: var(--color-text-secondary); margin-top: 4px; }
.stat-delta.up   { color: var(--color-success); }
.stat-delta.down { color: var(--color-danger); }

.mini-chart { display: flex; align-items: flex-end; gap: 3px; height: 32px; margin-top: 8px; }
.mini-bar { background: var(--color-primary); border-radius: 2px 2px 0 0; flex: 1; opacity: .7; min-height: 3px; }
.mini-bar.success { background: var(--color-success); }
.mini-bar.warning { background: var(--color-warning); }

.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--color-border); }
.section-head h1 { font-size: 15px; font-weight: 600; }
.section-head small { font-size: 11.5px; color: var(--color-text-secondary); }
.section-title { font-size: 12.5px; font-weight: 600; margin-bottom: 8px; }

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

.table-wrap { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--border-radius); overflow: hidden; margin-bottom: 16px; }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table-wrap th { background: var(--color-bg); padding: 8px 12px; text-align: left; font-size: 11px; font-weight: 600; color: var(--color-text-secondary); border-bottom: 1px solid var(--color-border); white-space: nowrap; }
.table-wrap td { padding: 8px 12px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
.table-wrap tr:last-child td { border-bottom: 0; }
.table-wrap tr:hover td { background: #fafbfc; }
.table-wrap .tfoot td { background: var(--color-bg); font-weight: 600; border-top: 1px solid var(--color-border); }

.tab-bar { display: flex; margin-bottom: 14px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--border-radius); overflow: hidden; width: fit-content; }
.tab-btn { padding: 7px 16px; font-size: 12.5px; cursor: pointer; border: 0; background: none; color: var(--color-text-secondary); font-weight: 500; font-family: var(--font-family); transition: background .1s; white-space: nowrap; }
.tab-btn.active { background: var(--color-primary-bg); color: var(--color-primary); }
.tab-btn:hover:not(.active) { background: var(--color-bg); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 500; line-height: 1.5; white-space: nowrap; }
.badge-success { background: var(--color-success-bg); color: #166534; }
.badge-danger  { background: var(--color-danger-bg);  color: #b91c1c; }
.badge-warning { background: var(--color-warning-bg); color: #92400e; }
.badge-info    { background: var(--color-info-bg);    color: #0369a1; }
.badge-gray    { background: var(--color-bg);         color: var(--color-text-secondary); border: 1px solid var(--color-border); }
.badge-primary { background: var(--color-primary-bg); color: var(--color-primary-dark); }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: var(--border-radius); font-size: 13px; font-weight: 500; font-family: var(--font-family); cursor: pointer; border: 1px solid transparent; text-decoration: none; transition: background .1s; line-height: 1; }
.btn-primary   { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn-primary:hover { background: var(--color-primary-dark); border-color: var(--color-primary-dark); }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-bg); }
.btn-danger    { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }
.btn-danger:hover { background: #c22020; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12.5px; font-weight: 500; margin-bottom: 5px; }
.form-control { width: 100%; padding: 7px 10px; border: 1px solid var(--color-border); border-radius: var(--border-radius); font-size: 13px; font-family: var(--font-family); color: var(--color-text); background: var(--color-surface); outline: none; transition: border-color .15s; }
.form-control:focus { border-color: var(--color-primary); }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236c7680'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; cursor: pointer; }

.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--border-radius); padding: 16px 20px; margin-bottom: 16px; }

.alert { padding: 10px 14px; border-radius: var(--border-radius); font-size: 13px; margin-bottom: 14px; border: 1px solid transparent; }
.alert-danger  { background: var(--color-danger-bg);  color: #b91c1c; border-color: #fca5a5; }
.alert-success { background: var(--color-success-bg); color: #166534; border-color: #86efac; }
.alert-warning { background: var(--color-warning-bg); color: #92400e; border-color: #fcd34d; }
.alert-info    { background: var(--color-info-bg);    color: #0369a1; border-color: #7dd3fc; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--color-bg); }
.login-box { width: 360px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 8px; padding: 32px 36px; }
.login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.login-logo-icon { width: 32px; height: 32px; background: var(--color-primary); border-radius: 7px; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 13px; }
.login-logo-name { font-size: 15px; font-weight: 600; }
.login-logo-sub  { font-size: 11.5px; color: var(--color-text-secondary); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--color-text-secondary); font-size: 13px; }
.empty-state svg { margin: 0 auto 10px; display: block; opacity: .4; }

.text-muted { color: var(--color-text-secondary); }
.text-sm    { font-size: 11.5px; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.w-full { width: 100%; }
