:root {
  --bg: #f4f7fb;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-strong: #ffffff;
  --surface-muted: #eef3fa;
  --text: #14213d;
  --muted: #70809c;
  --border: #dfe7f2;
  --primary: #2864ee;
  --primary-2: #7558f5;
  --success: #11a36a;
  --warning: #e19a24;
  --danger: #d95363;
  --sidebar: #f9fbff;
  --shadow: 0 18px 50px rgba(31, 63, 114, .10);
  --radius: 18px;
  font-family: Inter, "Segoe UI", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--text); background: var(--bg); min-width: 1120px; }
button, input, select { font: inherit; }
button { cursor: pointer; }

body.dark-theme {
  --bg: #081126;
  --surface: rgba(15, 31, 62, .92);
  --surface-strong: #102144;
  --surface-muted: #142952;
  --text: #eef4ff;
  --muted: #98a9c8;
  --border: #263e6b;
  --sidebar: #0b1834;
  --shadow: 0 18px 50px rgba(0, 0, 0, .25);
}

body.has-background::before {
  content: ""; position: fixed; inset: 0; z-index: -2;
  background-image: var(--custom-bg); background-size: cover; background-position: center;
  opacity: var(--bg-opacity, .22); filter: saturate(.85);
}
body.has-background::after {
  content: ""; position: fixed; inset: 0; z-index: -1; background: var(--bg-overlay, rgba(244,247,251,.74));
}
body.dark-theme.has-background::after { background: rgba(5, 13, 31, .78); }

.app-shell { min-height: 100vh; display: flex; }
.sidebar { width: 292px; flex: 0 0 292px; min-height: 100vh; background: var(--sidebar); border-right: 1px solid var(--border); padding: 25px 18px; position: sticky; top: 0; align-self: flex-start; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 12px 28px; border-bottom: 1px solid var(--border); }
.brand-mark { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; color: white; font-weight: 800; background: linear-gradient(135deg, var(--primary), var(--primary-2)); box-shadow: 0 8px 18px rgba(40,100,238,.25); }
.brand-name { font-size: 19px; font-weight: 800; letter-spacing: -.4px; }
.brand-name span { color: var(--primary); }
.nav { margin-top: 24px; display: grid; gap: 7px; }
.nav-link { position: relative; border: 1px solid transparent; background: transparent; color: var(--muted); text-decoration: none; display: flex; align-items: center; gap: 13px; min-height: 48px; padding: 0 14px; border-radius: 12px; font-size: 16px; font-weight: 700; transition: .2s; }
.nav-link:hover { color: var(--primary); background: var(--surface-muted); }
.nav-link.active { color: var(--text); background: linear-gradient(110deg, rgba(218, 229, 255, .68), rgba(239, 228, 255, .48)); border-color: rgba(123, 142, 225, .20); box-shadow: inset 0 1px 0 rgba(255,255,255,.68), 0 8px 22px rgba(102, 112, 190, .10); backdrop-filter: blur(14px); }
.nav-link.active::before { content: ""; position: absolute; left: -1px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 4px 4px 0; background: linear-gradient(180deg, #7d73ee, #6da7fa); }
.dark-theme .nav-link.active { color: var(--text); background: linear-gradient(110deg, rgba(65, 91, 155, .50), rgba(100, 76, 159, .36)); border-color: rgba(145, 164, 235, .22); box-shadow: inset 0 1px 0 rgba(255,255,255,.10), 0 8px 22px rgba(0, 0, 0, .14); }
.nav-icon { width: 20px; text-align: center; font-size: 18px; }
.sidebar-footer { position: absolute; bottom: 22px; left: 28px; right: 28px; color: var(--muted); font-size: 11px; }

.app-main { min-width: 0; flex: 1; }
.topbar { height: 82px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 38px; backdrop-filter: blur(18px); }
.search { width: 420px; position: relative; }
.search input { width: 100%; border: 1px solid var(--border); background: var(--surface-strong); border-radius: 12px; padding: 13px 16px 13px 42px; outline: none; color: var(--text); }
.search-icon { position: absolute; left: 15px; top: 11px; color: var(--muted); font-size: 18px; }
.top-actions { display: flex; align-items: center; gap: 22px; }
.icon-button { border: 0; background: transparent; color: var(--muted); font-size: 20px; }
.user { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 700; }
.avatar { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; color: white; background: linear-gradient(135deg, #386ff4, #7856ee); }
.page-content { padding: 34px 38px 52px; max-width: 1540px; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 28px; }
.eyebrow { color: var(--primary); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; }
h1 { margin: 7px 0 8px; font-size: 32px; letter-spacing: -.8px; }
.subtitle { color: var(--muted); margin: 0; font-size: 14px; }
.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; backdrop-filter: blur(18px); }
.card h2, .card h3 { margin: 0 0 8px; font-size: 16px; }
.card p { color: var(--muted); font-size: 13px; line-height: 1.6; }
.metric { display: flex; justify-content: space-between; align-items: flex-start; }
.metric-label { color: var(--muted); font-size: 12px; }
.metric-value { margin-top: 8px; font-size: 28px; font-weight: 800; }
.metric-icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; color: var(--primary); background: #e8efff; font-size: 19px; }
.dark-theme .metric-icon { background: #1a356e; }
.trend { color: var(--success); font-size: 12px; font-weight: 700; margin-top: 8px; }
.btn { border: 0; border-radius: 10px; min-height: 42px; padding: 0 17px; font-weight: 750; color: white; background: linear-gradient(115deg, var(--primary), var(--primary-2)); box-shadow: 0 8px 18px rgba(40,100,238,.18); }
.btn.secondary { color: var(--text); background: var(--surface-muted); box-shadow: none; border: 1px solid var(--border); }
.btn.danger { background: #fff0f1; color: var(--danger); box-shadow: none; }
.toolbar { display: flex; gap: 10px; align-items: center; }
.field { display: grid; gap: 8px; margin-top: 16px; }
.field label { color: var(--muted); font-size: 12px; font-weight: 700; }
.field input, .field select, .field textarea { width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; color: var(--text); background: var(--surface-strong); outline: none; }
.field textarea { min-height: 100px; resize: vertical; }
.table-wrap { overflow: hidden; border: 1px solid var(--border); border-radius: 14px; margin-top: 18px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 15px 16px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; background: var(--surface-muted); }
tr:last-child td { border-bottom: 0; }
.badge { display: inline-flex; padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 750; background: #eaf2ff; color: var(--primary); }
.badge.green { color: var(--success); background: #e5f8f0; }
.badge.orange { color: var(--warning); background: #fff5dc; }
.empty-chart { height: 190px; display: grid; place-items: center; border-radius: 13px; background: linear-gradient(150deg, var(--surface-muted), transparent); color: var(--muted); font-size: 13px; }
.bars { height: 170px; display: flex; align-items: end; gap: 13px; padding: 18px; border-radius: 13px; background: var(--surface-muted); }
.bar { flex: 1; min-height: 24px; border-radius: 7px 7px 2px 2px; background: linear-gradient(180deg, #6a65f6, #2f75ed); }
.notice { padding: 13px 15px; border-radius: 11px; font-size: 13px; background: #eaf2ff; color: var(--primary); }
.notice.warning { background: #fff5df; color: #986819; }
.split { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; }
.theme-preview { min-height: 175px; border-radius: 14px; border: 1px solid var(--border); background: linear-gradient(145deg, #d8e8ff, #edf5ff); background-size: cover; background-position: center; display: grid; place-items: center; overflow: hidden; }
.theme-preview span { color: #50698f; font-weight: 700; background: rgba(255,255,255,.72); padding: 8px 12px; border-radius: 9px; }
.upload-zone { min-height: 175px; display: grid; place-items: center; text-align: center; border: 2px dashed #80a5f4; border-radius: 14px; color: var(--muted); padding: 20px; }
.upload-zone strong { display: block; color: var(--text); margin-bottom: 10px; }
.upload-icon { font-size: 34px; color: var(--primary); margin-bottom: 6px; }
.range { width: 100%; accent-color: var(--primary); }
.toast { position: fixed; right: 30px; bottom: 25px; display: none; padding: 14px 18px; border: 1px solid #9be0c3; border-radius: 12px; background: #e9fbf2; color: #137246; box-shadow: var(--shadow); font-size: 13px; font-weight: 700; z-index: 10; }
.toast.show { display: block; }
.build-state { min-height: calc(100vh - 150px); display: grid; place-content: center; justify-items: center; text-align: center; color: var(--muted); }
.build-state h1 { color: var(--text); margin: 14px 0 8px; }
.build-state p { margin: 0; font-size: 14px; }
.build-orbit { width: 74px; height: 74px; display: grid; place-items: center; margin-bottom: 12px; border: 1px solid #9cbaff; border-radius: 24px; color: white; font-size: 30px; font-weight: 850; background: linear-gradient(135deg, var(--primary), var(--primary-2)); box-shadow: 0 14px 30px rgba(40,100,238,.22); }
.permission-safety { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; padding: 15px 18px; border: 1px solid #bfe9d5; border-radius: 13px; background: #effcf5; color: #176c49; font-size: 13px; }
.permission-safety strong { white-space: nowrap; }
.permission-layout { display: grid; grid-template-columns: 340px 1fr; gap: 18px; }
.section-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.section-title h2 { margin: 0; }
.card-caption { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.group-list { display: grid; gap: 8px; margin-top: 18px; }
.group-row { display: flex; align-items: center; justify-content: space-between; width: 100%; border: 1px solid transparent; border-radius: 12px; padding: 13px; text-align: left; color: var(--text); background: transparent; }
.group-row:hover, .group-row.selected { border-color: #b8c9f4; background: var(--surface-muted); }
.group-row-main { display: grid; gap: 4px; }
.group-row small, .member-chip small { color: var(--muted); font-size: 11px; }
.member-list { display: grid; gap: 8px; }
.member-chip { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.member-chip span:first-child { display: grid; gap: 3px; }
.remove-member { border: 0; background: transparent; color: var(--danger); font-size: 20px; }
.permission-grid { display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr)); gap: 9px; }
.action-grid { grid-template-columns: repeat(4, 1fr); }
.permission-check { display: flex; align-items: center; gap: 8px; padding: 10px; border: 1px solid var(--border); border-radius: 9px; font-size: 13px; }
.permission-check input { accent-color: var(--primary); }
.notice.warning { margin-top: 20px; }
.toast.error { border-color: #efb2b9; background: #fff0f1; color: #a92e3d; }

@media (max-width: 1200px) { .sidebar { width: 250px; flex-basis: 250px; } .grid-4 { grid-template-columns: repeat(2, 1fr); } .split { grid-template-columns: 1fr; } }
