:root {
  --ink: #162726;
  --muted: #687b79;
  --line: #dce7e4;
  --paper: #ffffff;
  --canvas: #f3f7f5;
  --deep: #123b3a;
  --deep-2: #1a4d4a;
  --teal: #187d72;
  --teal-soft: #e1f2ee;
  --mint: #bbded4;
  --coral: #e66d56;
  --coral-soft: #fff0ec;
  --amber: #b97722;
  --amber-soft: #fff6df;
  --danger: #c43d3d;
  --danger-soft: #ffeded;
  --shadow: 0 15px 45px rgba(27, 68, 64, .09);
  --radius: 18px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; color: var(--ink); background: var(--canvas); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-screen { min-height: 100vh; padding: 42px; display: grid; place-items: center; background: var(--deep); position: relative; overflow: hidden; }
.login-screen::before, .login-screen::after { content: ""; position: absolute; border-radius: 999px; background: rgba(187, 222, 212, .08); }
.login-screen::before { width: 560px; height: 560px; left: -180px; bottom: -260px; }
.login-screen::after { width: 420px; height: 420px; right: -150px; top: -180px; }
.login-shell { width: min(980px, 100%); display: grid; grid-template-columns: 1.12fr .88fr; background: var(--paper); border-radius: 28px; overflow: hidden; box-shadow: 0 30px 90px rgba(0,0,0,.3); position: relative; z-index: 1; }
.login-brand { min-height: 580px; padding: 68px; color: white; background: var(--deep-2); display: flex; flex-direction: column; justify-content: center; position: relative; }
.login-brand::after { content: ""; width: 190px; height: 190px; border: 1px solid rgba(255,255,255,.14); position: absolute; right: -50px; bottom: -50px; transform: rotate(18deg); }
.login-brand h1 { font-size: clamp(36px, 5vw, 58px); letter-spacing: -.05em; margin: 12px 0 20px; }
.login-brand > p:not(.eyebrow) { max-width: 450px; line-height: 1.85; color: #d9ebe7; }
.login-points { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 34px; }
.login-points span { padding: 8px 13px; border: 1px solid rgba(255,255,255,.18); border-radius: 999px; font-size: 13px; color: #e8f4f1; }
.login-card { padding: 58px 48px; display: flex; flex-direction: column; justify-content: center; gap: 22px; }
.login-card h2 { font-size: 30px; margin: 8px 0; }
.login-card label, .form-grid label, .field { display: grid; gap: 8px; color: #425754; font-weight: 650; font-size: 14px; }
.login-card input, .form-grid input, .form-grid select, .form-grid textarea, .toolbar input, .toolbar select, .rule-input, .search-input { width: 100%; border: 1px solid #cedbd8; border-radius: 11px; background: white; color: var(--ink); padding: 12px 13px; outline: none; transition: .18s ease; }
input:focus, textarea:focus, select:focus { border-color: var(--teal) !important; box-shadow: 0 0 0 3px rgba(24,125,114,.12); }
textarea { resize: vertical; min-height: 112px; }
.login-foot { text-align: center; color: var(--muted); font-size: 12px; }
.form-error { min-height: 20px; margin: -8px 0; color: var(--danger); font-size: 13px; }

.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; background: var(--mint); color: var(--deep); border-radius: 13px; font-weight: 900; font-family: Georgia, serif; font-size: 22px; }
.brand-mark.large { width: 60px; height: 60px; border-radius: 18px; font-size: 31px; }
.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: .14em; font-size: 11px; font-weight: 800; color: var(--teal); }
.muted { color: var(--muted); }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 28px 18px 22px; background: var(--deep); color: #e6f1ee; display: flex; flex-direction: column; z-index: 20; }
.sidebar-brand { display: flex; gap: 12px; align-items: center; padding: 0 10px 28px; border-bottom: 1px solid rgba(255,255,255,.09); }
.sidebar-brand div:last-child { display: grid; gap: 3px; }
.sidebar-brand strong { font-size: 16px; }
.sidebar-brand span { font-size: 11px; color: #9cb9b4; letter-spacing: .12em; }
.nav-list { display: grid; gap: 6px; padding-top: 24px; }
.nav-item { border: 0; border-radius: 11px; padding: 12px 14px; color: #bcd0cc; background: transparent; display: flex; gap: 13px; align-items: center; text-align: left; transition: .16s ease; }
.nav-item span { width: 22px; text-align: center; color: #88aaa4; font-size: 18px; }
.nav-item:hover { color: white; background: rgba(255,255,255,.06); }
.nav-item.active { color: #102d2c; background: var(--mint); font-weight: 800; }
.nav-item.active span { color: var(--deep); }
.sidebar-foot { margin-top: auto; padding: 18px 10px 2px; border-top: 1px solid rgba(255,255,255,.09); display: grid; gap: 8px; color: #9cb9b4; font-size: 12px; }
.health-line { display: flex; gap: 8px; align-items: center; color: #dbe9e6; }
.health-line i, .status-chip i { width: 8px; height: 8px; border-radius: 50%; background: #9aa9a7; box-shadow: 0 0 0 4px rgba(154,169,167,.12); }
.health-line.online i, .status-chip.online i { background: #48c79b; box-shadow: 0 0 0 4px rgba(72,199,155,.14); }
.health-line.warning i, .status-chip.warning i { background: #e2a442; box-shadow: 0 0 0 4px rgba(226,164,66,.14); }
.health-line.offline i, .status-chip.offline i { background: #ec6d6d; box-shadow: 0 0 0 4px rgba(236,109,109,.14); }

.main { min-width: 0; }
.topbar { min-height: 105px; padding: 24px 38px; display: flex; align-items: center; gap: 16px; background: rgba(243,247,245,.92); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 15; backdrop-filter: blur(12px); }
.topbar h1 { font-size: 24px; margin: 5px 0 0; letter-spacing: -.02em; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.status-chip { display: inline-flex; align-items: center; gap: 9px; padding: 8px 12px; border-radius: 999px; background: white; border: 1px solid var(--line); font-size: 12px; font-weight: 700; }
.view-root { padding: 32px 38px 60px; max-width: 1540px; margin: 0 auto; }
.loading-state { min-height: 55vh; display: grid; place-content: center; justify-items: center; color: var(--muted); }
.loading-state span { width: 36px; height: 36px; border: 3px solid var(--mint); border-top-color: var(--teal); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.button, .icon-button { border: 0; border-radius: 10px; min-height: 39px; padding: 0 15px; font-weight: 750; transition: transform .14s ease, background .14s ease, border-color .14s ease; }
.button:hover, .icon-button:hover { transform: translateY(-1px); }
.button:disabled, .icon-button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.button.primary { background: var(--teal); color: white; }
.button.secondary { background: var(--teal-soft); color: var(--teal); }
.button.danger { background: var(--danger-soft); color: var(--danger); }
.button.ghost { background: white; color: var(--ink); border: 1px solid var(--line); }
.button.wide { width: 100%; min-height: 46px; }
.button.small { min-height: 32px; padding: 0 11px; font-size: 12px; }
.icon-button { width: 40px; padding: 0; background: white; color: var(--ink); border: 1px solid var(--line); font-size: 18px; }
.mobile-menu { display: none; }

.hero-strip { background: var(--deep); color: white; padding: 25px 28px; border-radius: var(--radius); display: flex; justify-content: space-between; align-items: center; gap: 22px; box-shadow: var(--shadow); margin-bottom: 22px; position: relative; overflow: hidden; }
.hero-strip::after { content: ""; width: 170px; height: 170px; border: 28px solid rgba(187,222,212,.09); border-radius: 50%; position: absolute; right: 24%; top: -80px; }
.hero-strip h2 { margin: 5px 0 6px; font-size: 24px; }
.hero-strip p { margin: 0; color: #bfd4d0; font-size: 13px; }
.hero-actions { display: flex; gap: 10px; position: relative; z-index: 1; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card, .panel, .group-card, .rule-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(27,68,64,.045); }
.stat-card { padding: 20px; display: grid; gap: 12px; min-height: 128px; }
.stat-head { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 13px; }
.stat-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: var(--teal-soft); color: var(--teal); font-size: 17px; }
.stat-value { font-size: 32px; font-weight: 850; letter-spacing: -.04em; }
.stat-note { color: var(--muted); font-size: 12px; }
.content-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr); gap: 20px; }
.panel { overflow: hidden; }
.panel-header { min-height: 66px; padding: 17px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 14px; }
.panel-header h2, .panel-header h3 { margin: 0; font-size: 16px; }
.panel-header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.panel-header .push { margin-left: auto; }
.panel-body { padding: 20px; }
.panel-body.flush { padding: 0; }

.group-progress { display: grid; gap: 18px; }
.progress-row { display: grid; grid-template-columns: 72px minmax(0,1fr) 80px; gap: 15px; align-items: center; }
.progress-label { font-weight: 800; }
.progress-track { width: 100%; height: 9px; border: 0; border-radius: 999px; overflow: hidden; appearance: none; background: #e8efed; }
.progress-track::-webkit-progress-bar { background: #e8efed; border-radius: 999px; }
.progress-track::-webkit-progress-value { background: var(--teal); border-radius: 999px; }
.progress-track::-moz-progress-bar { background: var(--teal); border-radius: 999px; }
.progress-count { text-align: right; font-weight: 800; }
.progress-count small { display: block; color: var(--muted); font-weight: 500; }
.event-list { display: grid; }
.event-item { padding: 13px 0; display: grid; grid-template-columns: 10px minmax(0,1fr); gap: 10px; border-bottom: 1px solid #edf2f0; }
.event-item:last-child { border-bottom: 0; }
.event-dot { width: 8px; height: 8px; margin-top: 5px; border-radius: 50%; background: var(--teal); }
.event-dot.warning { background: var(--amber); }
.event-dot.error { background: var(--danger); }
.event-title { font-weight: 700; font-size: 13px; overflow-wrap: anywhere; }
.event-time { color: var(--muted); font-size: 11px; margin-top: 4px; }

.section-stack { display: grid; gap: 20px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar .search-input { flex: 1 1 260px; }
.toolbar select { width: auto; min-width: 145px; }
.toolbar .spacer { flex: 1; }
.report-layout { display: grid; grid-template-columns: minmax(320px,.8fr) minmax(0,1.2fr); gap: 20px; }
.report-preview { background: #102f2e; color: #eef8f5; border-radius: 13px; padding: 18px; white-space: pre-wrap; line-height: 1.75; max-height: 580px; overflow: auto; font-family: "SFMono-Regular", Consolas, monospace; font-size: 13px; }
.inline-actions { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }
.report-send-actions { margin-top: 14px; }
.panel-body-tight-top { padding-top: 0; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); background: #f8faf9; padding: 12px 15px; font-size: 11px; letter-spacing: .05em; white-space: nowrap; }
td { padding: 13px 15px; border-top: 1px solid #e9efed; vertical-align: middle; }
tr:hover td { background: #fbfdfc; }
.book-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.book-tag { border: 0; padding: 5px 8px; border-radius: 8px; background: var(--teal-soft); color: var(--teal); font-size: 11px; font-weight: 800; }
.book-tag:hover { background: var(--danger-soft); color: var(--danger); }
.source-badge, .group-type, .log-level { display: inline-flex; padding: 5px 8px; border-radius: 999px; font-size: 10px; font-weight: 800; white-space: nowrap; }
.source-badge { background: #eef3f2; color: #56706c; }
.source-badge.admin { background: var(--amber-soft); color: var(--amber); }
.empty-state { padding: 50px 24px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; color: var(--ink); margin-bottom: 5px; }

.blacklist-cloud { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 9px; }
.name-pill { border: 1px solid var(--line); border-radius: 10px; padding: 10px 11px; display: flex; align-items: center; gap: 9px; background: #fbfdfc; }
.name-pill input { accent-color: var(--teal); }
.name-pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 12px; padding-top: 18px; color: var(--muted); font-size: 12px; }

.group-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.group-card { padding: 20px; display: grid; gap: 18px; }
.group-card-head { display: flex; align-items: center; gap: 12px; }
.group-avatar { width: 44px; height: 44px; display: grid; place-items: center; background: var(--teal-soft); color: var(--teal); font-weight: 900; border-radius: 13px; }
.group-card-head h3 { margin: 0 0 4px; font-size: 17px; }
.group-type { background: #eef3f2; color: var(--muted); }
.connection { margin-left: auto; color: var(--muted); font-size: 11px; }
.connection.online { color: var(--teal); }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.setting-row strong { display: block; font-size: 13px; }
.setting-row small { color: var(--muted); }
.switch { width: 44px; height: 24px; position: relative; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: #cdd8d5; transition: .18s; }
.switch span::after { content: ""; width: 18px; height: 18px; background: white; border-radius: 50%; position: absolute; top: 3px; left: 3px; box-shadow: 0 2px 5px rgba(0,0,0,.2); transition: .18s; }
.switch input:checked + span { background: var(--teal); }
.switch input:checked + span::after { transform: translateX(20px); }

.rules-grid { display: grid; grid-template-columns: minmax(0,1.2fr) minmax(300px,.8fr); gap: 20px; align-items: start; }
.rule-list { display: grid; gap: 0; }
.rule-row { display: grid; grid-template-columns: minmax(180px, .8fr) minmax(200px, 1.2fr); gap: 22px; align-items: center; padding: 17px 0; border-bottom: 1px solid var(--line); }
.rule-row:last-child { border-bottom: 0; }
.rule-row h4 { margin: 0 0 4px; font-size: 14px; }
.rule-row p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.rule-control { min-width: 0; }
.two-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.test-result { margin-top: 14px; display: grid; gap: 9px; }
.result-box { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: #fafcfb; font-size: 12px; }
.result-box strong { display: block; margin-bottom: 5px; }
.result-box.hit { border-color: #e9c29f; background: var(--amber-soft); }

.log-list { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }
.log-row { display: grid; grid-template-columns: 150px 170px minmax(0,1fr); gap: 14px; padding: 11px 16px; border-top: 1px solid #edf2f0; align-items: start; }
.log-row time { color: var(--muted); }
.log-event { font-weight: 800; overflow-wrap: anywhere; }
.log-detail { color: #49615e; white-space: pre-wrap; overflow-wrap: anywhere; }
.log-level.info { background: var(--teal-soft); color: var(--teal); }
.log-level.warning { background: var(--amber-soft); color: var(--amber); }
.log-level.error { background: var(--danger-soft); color: var(--danger); }

.danger-zone { border-color: #f0c4bc; }
.danger-zone .panel-header { background: #fff9f7; }
.backup-list { display: grid; gap: 9px; }
.backup-row { display: flex; align-items: center; gap: 15px; padding: 12px 13px; background: #fafcfb; border: 1px solid var(--line); border-radius: 11px; }
.backup-row > div { min-width: 0; flex: 1; }
.backup-row strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.backup-row span { color: var(--muted); font-size: 11px; }
.form-grid { display: grid; gap: 15px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.form-grid .full { grid-column: 1 / -1; }
.help-text { padding: 11px 13px; background: var(--teal-soft); color: #35635e; border-radius: 10px; font-size: 12px; line-height: 1.55; }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(10,32,31,.64); display: grid; place-items: center; padding: 24px; }
.modal { width: min(560px, 100%); max-height: 90vh; overflow: auto; background: white; border-radius: 20px; box-shadow: 0 25px 80px rgba(0,0,0,.28); padding: 28px; position: relative; }
.modal h2 { margin: 4px 0 10px; font-size: 22px; }
.modal-close { position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; border: 0; border-radius: 9px; background: #f0f4f3; font-size: 22px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

.toast-region { position: fixed; right: 20px; top: 18px; z-index: 200; display: grid; gap: 9px; width: min(380px, calc(100vw - 40px)); }
.toast { padding: 13px 15px; border-radius: 12px; background: var(--deep); color: white; box-shadow: 0 10px 30px rgba(0,0,0,.2); animation: toast-in .2s ease; font-size: 13px; }
.toast.error { background: #8f2f2f; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .content-grid, .report-layout, .rules-grid { grid-template-columns: 1fr; }
}

@media (max-width: 780px) {
  .login-screen { padding: 18px; }
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { min-height: 230px; padding: 36px; }
  .login-brand h1 { font-size: 36px; margin: 8px 0 10px; }
  .login-points { margin-top: 16px; }
  .login-card { padding: 36px 28px; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; transform: translateX(-105%); transition: transform .2s ease; width: 248px; box-shadow: 20px 0 50px rgba(0,0,0,.18); }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu { display: block; }
  .topbar { min-height: 82px; padding: 17px 18px; }
  .topbar h1 { font-size: 19px; }
  .topbar-actions .status-chip { display: none; }
  .view-root { padding: 20px 16px 45px; }
  .hero-strip { align-items: flex-start; flex-direction: column; }
  .stat-grid { gap: 11px; }
  .stat-card { padding: 16px; min-height: 110px; }
  .stat-value { font-size: 27px; }
  .panel-header { align-items: flex-start; flex-wrap: wrap; }
  .panel-header .push { margin-left: 0; width: 100%; }
  .progress-row { grid-template-columns: 55px minmax(0,1fr) 56px; gap: 9px; }
  .rule-row { grid-template-columns: 1fr; gap: 10px; }
  .log-row { grid-template-columns: 1fr; gap: 5px; }
  .form-grid.two { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat-head span:first-child { font-size: 11px; }
  .topbar-actions .button { display: none; }
  .hero-actions { width: 100%; }
  .hero-actions .button { flex: 1; }
  .blacklist-cloud { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .modal { padding: 23px 18px; }
}
