:root {
    --primary: #1890ff;
    --primary-hover: #40a9ff;
    --primary-active: #096dd9;
    --bg: #f0f2f5;
    --card: #ffffff;
    --text: #262626;
    --text-secondary: #8c8c8c;
    --border: #f0f0f0;
    --sidebar-bg: #ffffff;
    --sidebar-width: 220px;
    --header-height: 56px;
    --danger: #ff4d4f;
    --danger-hover: #ff7875;
    --success: #52c41a;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.03), 0 2px 8px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }

.icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    vertical-align: -3px;
}

/* --- Auth pages --- */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 24px;
}

.auth-card {
    background: var(--card);
    padding: 40px 36px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 400px;
}

.auth-card h1 {
    margin: 0 0 8px;
    font-size: 24px;
    font-weight: 600;
    text-align: center;
}

.auth-card .subtitle {
    margin: 0 0 28px;
    color: var(--text-secondary);
    text-align: center;
    font-size: 14px;
}

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

.auth-card input[type="text"],
.auth-card input[type="password"],
.auth-card input[type="email"],
.auth-card input[type="number"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d9d9d9;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.auth-card input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
}

.auth-switch {
    margin-top: 20px;
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
}

.auth-switch a {
    color: var(--primary);
    text-decoration: none;
}

.auth-switch a:hover { text-decoration: underline; }

.error {
    color: var(--danger);
    font-size: 13px;
    margin-top: 4px;
}

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

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

.sidebar-brand {
    height: var(--header-height);
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 20px;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    color: var(--text);
    text-decoration: none;
    border: none;
    background: none;
    width: 100%;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    border-left: 3px solid transparent;
    transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
    color: var(--primary);
    background: #e6f7ff;
}

.nav-item.active {
    color: var(--primary);
    background: #e6f7ff;
    border-left-color: var(--primary);
    font-weight: 500;
}

.sidebar-footer {
    padding: 12px 20px;
    font-size: 12px;
    color: var(--text-secondary);
    border-top: 1px solid var(--border);
}

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

.top-header {
    height: var(--header-height);
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex-shrink: 0;
}

.top-header .page-title {
    margin: 0;
    font-size: 16px;
    font-weight: 500;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    opacity: 0.95;
}

.page-content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

/* --- Cards --- */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}

.card:last-child { margin-bottom: 0; }

.card-title {
    margin: 0 0 16px;
    font-size: 16px;
    font-weight: 600;
}

.card-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.hint {
    margin: 0 0 12px;
    color: var(--text-secondary);
    font-size: 13px;
}

.warning-hint {
    margin: 12px 0 0;
    padding: 10px 12px;
    background: #fff7e6;
    border: 1px solid #ffd591;
    border-radius: 6px;
    color: #ad6800;
    font-size: 12px;
    line-height: 1.5;
}

/* --- Buttons --- */
button, .btn {
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 400;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

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

.btn-secondary {
    background: #fff;
    color: var(--text);
    border: 1px solid #d9d9d9;
}

.btn-secondary:hover {
    color: var(--primary);
    border-color: var(--primary);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover { background: var(--danger-hover); }

.btn-icon {
    padding: 4px 10px;
    font-size: 13px;
}

.header-btn {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.35);
    padding: 6px 14px;
    font-size: 13px;
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
}

.header-btn-danger {
    background: rgba(255, 77, 79, 0.85);
    border-color: transparent;
}

.header-btn-danger:hover {
    background: var(--danger);
}

/* --- Tables --- */
.table-wrap {
    overflow-x: auto;
}

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

table.data-table th,
table.data-table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

table.data-table th {
    background: #fafafa;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

table.data-table tbody tr:hover {
    background: #e6f7ff;
}

table.data-table tbody tr:last-child td {
    border-bottom: none;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.stats-table th,
.stats-table td {
    padding: 12px 0;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.stats-table th {
    color: var(--text-secondary);
    font-weight: 500;
    width: 38%;
}

.stats-table tr:last-child th,
.stats-table tr:last-child td { border-bottom: none; }

.status {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
}

.status.enabled, .status-enabled {
    background: #f6ffed;
    color: #389e0d;
}

.status.disabled, .status-disabled {
    background: #fff2f0;
    color: #cf1322;
}

.empty {
    padding: 48px 24px;
    text-align: center;
    color: var(--text-secondary);
}

/* --- Progress bar --- */
.quota-bar-wrap { margin-top: 16px; }

.quota-bar-labels {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.quota-bar-track {
    height: 8px;
    background: #f5f5f5;
    border-radius: 4px;
    overflow: hidden;
}

.quota-bar-fill {
    height: 100%;
    background: var(--success);
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0;
}

/* --- Modal --- */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.modal-card {
    position: relative;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
    width: 100%;
    max-width: 440px;
    padding: 28px;
    z-index: 1001;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-card.small { max-width: 360px; }

.modal-card h2 {
    margin: 0 0 20px;
    font-size: 18px;
    font-weight: 600;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
}

label {
    display: block;
    margin-bottom: 16px;
    font-size: 14px;
    font-weight: 500;
}

label input,
label select {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 10px 12px;
    border: 1px solid #d9d9d9;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}

label input:focus,
label select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
}

label.checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 400;
}

label.checkbox input {
    width: auto;
    margin: 0;
}

.muted { color: var(--text-secondary); }

/* --- Responsive --- */
@media (max-width: 768px) {
    .app-shell { flex-direction: column; }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .sidebar-nav {
        display: flex;
        flex-wrap: wrap;
        padding: 8px;
        gap: 4px;
    }

    .nav-item {
        width: auto;
        padding: 8px 14px;
        border-left: none;
        border-radius: 6px;
    }

    .nav-item.active {
        border-left: none;
    }

    .sidebar-footer { display: none; }

    .page-content { padding: 16px; }

    .top-header {
        padding: 0 16px;
        flex-wrap: wrap;
        height: auto;
        min-height: var(--header-height);
        padding-top: 10px;
        padding-bottom: 10px;
        gap: 8px;
    }

    .header-actions {
        flex-wrap: wrap;
        gap: 8px;
    }
}
