:root {
    --bg: #f5f7fa;
    --surface: #ffffff;
    --border: #e8ecf1;
    --text: #1f2937;
    --text-muted: #6b7280;
    --primary: #00a1d6;
    --primary-hover: #0090c0;
    --danger: #ef4444;
    --success: #10b981;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --radius: 12px;
    --sidebar-width: 240px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform .25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.logo {
    width: 40px; height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, #00a1d6, #fb7299);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
}

.sidebar-brand strong { display: block; font-size: 15px; }
.sidebar-brand small { color: var(--text-muted); font-size: 12px; }

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

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    border-radius: 10px;
    color: var(--text);
    margin-bottom: 4px;
    transition: background .15s;
}

.nav-item:hover { background: #f3f4f6; text-decoration: none; }
.nav-item.active { background: #e6f7fc; color: var(--primary); font-weight: 600; }

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.user-info span { display: block; font-size: 14px; font-weight: 600; }
.user-info small { color: var(--text-muted); font-size: 12px; }

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
}

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.menu-toggle {
    display: none;
    border: none;
    background: none;
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
}

.page-title { font-size: 20px; font-weight: 600; }

.page-content { padding: 24px; max-width: 1200px; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.stat-label { color: var(--text-muted); font-size: 13px; margin-bottom: 8px; }
.stat-value { font-size: 32px; font-weight: 700; line-height: 1.2; }
.stat-value.accent { color: var(--primary); }
.stat-sub { color: var(--text-muted); font-size: 12px; margin-top: 8px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h2 { font-size: 16px; font-weight: 600; }
.card-body { padding: 20px; }
.card-footer { padding: 16px 20px; border-top: 1px solid var(--border); }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}

.filters select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    font-size: 14px;
}

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: #fafbfc; color: var(--text-muted); font-weight: 600; font-size: 13px; }
tr:hover td { background: #fafbfc; }
.empty { text-align: center; color: var(--text-muted); padding: 40px !important; }
.truncate { max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.account-cell { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0; background: #e8ecf1; }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
}
.badge-green { background: #d1fae5; color: #065f46; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-gray { background: #f3f4f6; color: #6b7280; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s;
    background: none;
    color: var(--text);
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn-ghost { border-color: var(--border); background: var(--surface); }
.btn-ghost:hover { background: #f9fafb; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }

.actions { white-space: nowrap; }

.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
    position: absolute; inset: 0;
    background: #d1d5db; border-radius: 999px; cursor: pointer; transition: .2s;
}
.switch span:before {
    content: ""; position: absolute; width: 18px; height: 18px;
    left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span:before { transform: translateX(20px); }

.input-sm {
    width: 100%; min-width: 80px;
    padding: 6px 8px; border: 1px solid var(--border);
    border-radius: 6px; font-size: 13px;
}

.form label { display: block; margin-bottom: 16px; }
.form label span { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 500; }
.form input, .form select, .form-card input, .form-card select {
    width: 100%; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: 8px;
    font-size: 14px; background: var(--surface);
}
.form input:focus, .form select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,161,214,.12); }
.form small { display: block; margin-top: 4px; color: var(--text-muted); font-size: 12px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 8px 20px; }
.form-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.form-row span { margin-bottom: 0 !important; }

.code-block {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    font-size: 13px;
    word-break: break-all;
}

.text-muted { color: var(--text-muted); font-size: 14px; }
.link { font-size: 14px; }

.pagination { display: flex; gap: 6px; padding: 16px; flex-wrap: wrap; }
.page-link {
    padding: 6px 12px; border: 1px solid var(--border);
    border-radius: 6px; color: var(--text); font-size: 13px;
}
.page-link.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.modal {
    display: none; position: fixed; inset: 0;
    background: rgba(15,23,42,.4); z-index: 200;
    align-items: center; justify-content: center; padding: 20px;
}
.modal.show { display: flex; }

.modal-content {
    background: var(--surface); border-radius: var(--radius);
    width: 100%; max-width: 420px; box-shadow: 0 20px 50px rgba(0,0,0,.15);
}
.modal-sm { max-width: 360px; }
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; }
.modal-close { border: none; background: none; font-size: 24px; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 24px 20px; }

.qr-body { text-align: center; }
#qrCanvas { min-height: 200px; display: flex; align-items: center; justify-content: center; }
#qrCanvas img { border: 1px solid var(--border); border-radius: 8px; }
.qr-status { margin-top: 16px; color: var(--text-muted); font-size: 14px; }
.qr-loading { padding: 40px; color: var(--text-muted); }

.login-page {
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
}

.login-card {
    width: 100%; max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px;
    box-shadow: var(--shadow);
}

.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand h1 { font-size: 22px; margin: 12px 0 4px; }
.login-brand p { color: var(--text-muted); font-size: 14px; }
.install-card { max-width: 440px; }
.form-section-title { font-size: 14px; font-weight: 600; margin: 20px 0 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.form-section-title:first-of-type { border-top: none; margin-top: 0; padding-top: 0; }
.section-tip { font-size: 12px; margin-bottom: 12px; }

.alert {
    padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px;
}
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }

.toast {
    position: fixed; bottom: 24px; right: 24px;
    background: #1f2937; color: #fff;
    padding: 12px 20px; border-radius: 8px;
    font-size: 14px; opacity: 0; transform: translateY(10px);
    transition: all .25s; pointer-events: none; z-index: 300;
    max-width: 360px;
}
.toast.show { opacity: 1; transform: translateY(0); }

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

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.show { display: block; }
    .main-content { margin-left: 0; }
    .menu-toggle { display: block; }
    .page-content { padding: 16px; }
    .topbar { padding: 12px 16px; }
    th, td { padding: 10px 12px; font-size: 13px; }
}
