:root {
  color-scheme: light;
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-muted: #f6f6f5;
  --surface-hover: #f0f0ee;
  --ink: #20201e;
  --muted: #777773;
  --line: #e6e6e2;
  --accent: #242422;
  --success: #24734a;
  --success-bg: #edf8f0;
  --danger: #b53e35;
  --danger-bg: #fdf0ee;
  font-family: "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", Inter, ui-sans-serif, system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button { height: 32px; border: 1px solid transparent; border-radius: 6px; background: var(--surface-muted); color: var(--ink); padding: 0 10px; font-size: 13px; font-weight: 550; cursor: pointer; }
button:hover { background: var(--surface-hover); }
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: #3a3a36; }
button.weak { background: transparent; color: var(--muted); }
button.weak:hover { background: var(--surface-muted); color: var(--ink); }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select { width: 100%; height: 36px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); padding: 0 10px; font-size: 14px; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(32,32,30,.16); outline-offset: 1px; }
textarea { width: 100%; min-height: 540px; resize: vertical; border: 0; background: #1e1e1c; color: #e9e9e5; padding: 16px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; line-height: 1.65; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.loginShell { display: grid; min-height: 100vh; place-items: center; padding: 20px; }
.login { width: min(360px, 100%); border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding: 26px; box-shadow: 0 14px 36px rgba(20,20,18,.05); }
.login h1 { margin: 0 0 22px; font-size: 20px; font-weight: 680; }
.login label, .modal label { display: grid; gap: 6px; margin-bottom: 14px; }
.login label span, .modal label span { color: var(--muted); font-size: 12px; }
.login button { width: 100%; }

.appShell { display: grid; grid-template-columns: 208px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; display: flex; height: 100vh; flex-direction: column; border-right: 1px solid var(--line); background: var(--surface); padding: 16px 10px; }
.brand { display: flex; height: 36px; align-items: center; gap: 9px; padding: 0 6px; font-size: 15px; font-weight: 680; }
.brandMark { display: grid; width: 26px; height: 26px; place-items: center; border-radius: 6px; background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; }
.navLabel { margin: 26px 8px 7px; color: #999994; font-size: 11px; font-weight: 600; }
.sidebar nav { display: grid; gap: 2px; }
.sidebar a { display: flex; height: 34px; align-items: center; border-radius: 6px; color: var(--muted); padding: 0 9px; text-decoration: none; font-size: 13px; font-weight: 560; }
.sidebar a:hover { background: var(--surface-muted); color: var(--ink); }
.sidebar a.active { background: #ededeb; color: var(--ink); font-weight: 650; }
.mainPane { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 4; display: flex; min-height: 64px; align-items: center; border-bottom: 1px solid var(--line); background: rgba(250,250,250,.94); padding: 10px 28px; backdrop-filter: blur(12px); }
.titleBlock { display: grid; gap: 2px; }
.titleBlock > span { color: var(--muted); font-size: 11px; font-weight: 560; }
.titleBlock h1 { margin: 0; font-size: 17px; font-weight: 680; }
.content { width: min(1200px, calc(100vw - 56px)); margin: 22px auto 56px; }

.subTabs { display: inline-flex; gap: 2px; border-bottom: 1px solid var(--line); }
.subTabs button { height: 34px; border-radius: 0; background: transparent; color: var(--muted); padding: 0 11px; }
.subTabs button:hover { color: var(--ink); }
.subTabs button.active { border-bottom: 2px solid var(--accent); color: var(--ink); font-weight: 650; }
.outerTabs { margin-bottom: 24px; }
.moduleTabs { margin-bottom: 18px; }
.logTabs { margin-bottom: 12px; }
.toolbar { display: flex; min-height: 38px; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.toolbar > div:first-child { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.toolbar strong { font-size: 14px; font-weight: 680; }
.toolbar span { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.compactToolbar { margin-bottom: 10px; }
.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }

.tableWrap, .editorBlock { overflow: hidden; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.caddyRules { margin-bottom: 0; }
table { width: 100%; min-width: 700px; border-collapse: collapse; font-size: 13px; }
th, td { border-bottom: 1px solid var(--line); padding: 11px 13px; text-align: left; vertical-align: middle; }
th { background: #fafaf9; color: var(--muted); font-size: 11px; font-weight: 650; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcfcfb; }
.serviceName { width: 135px; }
.serviceName code { font-size: 12px; font-weight: 650; }
.badge { display: inline-flex; height: 22px; align-items: center; gap: 5px; border-radius: 4px; background: #f0f0ee; color: var(--muted); padding: 0 7px; font-size: 11px; white-space: nowrap; }
.badge i { width: 5px; height: 5px; border-radius: 50%; background: #a3a3a0; }
.badge.enabled { background: var(--success-bg); color: var(--success); }
.badge.enabled i { background: var(--success); }
.rowActions { width: 150px; text-align: right; white-space: nowrap; }
.rowActions button { height: 27px; background: transparent; padding: 0 5px; color: var(--muted); font-size: 12px; font-weight: 520; }
.rowActions button:hover { background: transparent; color: var(--ink); }
.rowActions .dangerText { color: var(--danger); }
.empty { height: 112px; color: var(--muted); text-align: center; }
.emptyPanel { display: grid; min-height: 180px; place-items: center; border: 1px dashed #d9d9d5; border-radius: 7px; color: var(--muted); font-size: 13px; }

.editorHead { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); padding: 10px 13px; }
.editorHead strong { font-size: 13px; }
.editorHead span { color: var(--muted); font-size: 12px; }
.notice, .error { margin-top: 12px; border-radius: 6px; padding: 10px 12px; font-size: 13px; }
.notice { background: var(--success-bg); color: var(--success); }
.error { background: var(--danger-bg); color: var(--danger); }
.error.compact { margin-top: 8px; }
.activity { margin-top: 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--muted); font-size: 12px; }
.activity summary { cursor: pointer; padding: 9px 12px; }
.activity pre { max-height: 300px; overflow: auto; margin: 0; border-top: 1px solid var(--line); padding: 12px; color: var(--ink); font-size: 12px; white-space: pre-wrap; }
.logViewer { min-height: 440px; max-height: 650px; overflow: auto; margin: 0; border: 1px solid #292927; border-radius: 7px; background: #1e1e1c; color: #e9e9e5; padding: 15px; font-size: 12px; line-height: 1.6; white-space: pre-wrap; }
.preview { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.preview section { overflow: hidden; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.preview h2 { margin: 0; border-bottom: 1px solid var(--line); padding: 10px 12px; font-size: 13px; }
.preview pre { min-height: 360px; max-height: 640px; overflow: auto; margin: 0; background: #1e1e1c; color: #e9e9e5; padding: 14px; font-size: 12px; line-height: 1.6; }

.modalBackdrop { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(20,20,18,.34); padding: 20px; }
.modal { width: min(560px, 100%); border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 20px 60px rgba(20,20,18,.18); }
.modal.caddyModal { width: min(820px, 100%); }
.modal header, .modal footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; }
.modal header { border-bottom: 1px solid var(--line); }
.modal footer { border-top: 1px solid var(--line); }
.modal h2 { margin: 0; font-size: 16px; }
.formGrid { display: grid; grid-template-columns: 1fr 130px; gap: 12px; padding: 16px 16px 4px; }
.caddyFormGrid { grid-template-columns: 1.3fr 1fr 1fr 120px; }
.modeTabs { display: flex; gap: 8px; padding: 14px 16px 0; }
.modeTabs label { display: inline-flex; height: 32px; align-items: center; gap: 7px; margin: 0; border-radius: 6px; background: var(--surface-muted); padding: 0 10px; color: var(--ink); font-size: 13px; font-weight: 600; }
.modeTabs input, .checkLine input { width: 16px; height: 16px; }
.rawFields { padding: 16px; }
.rawFields label { margin: 0; }
.rawTextarea { min-height: 300px; border-radius: 6px; }
.hidden { display: none; }
.modalLine { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px 14px; }
.checkLine { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
.generated { color: var(--muted); font-size: 12px; }
.generated code { margin-left: 6px; color: var(--ink); font-weight: 600; }

@media (max-width: 760px) {
  .appShell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; z-index: 5; display: flex; height: auto; flex-direction: row; align-items: center; gap: 10px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 9px 10px; }
  .brand { flex: 0 0 auto; padding: 0 2px; }
  .brand > span:last-child, .navLabel { display: none; }
  .sidebar nav { display: flex; gap: 2px; }
  .sidebar a { flex: 0 0 auto; }
  .topbar { min-height: 58px; padding: 9px 16px; }
  .content { width: min(100% - 28px, 1200px); margin-top: 16px; }
  .toolbar { align-items: flex-start; flex-direction: column; }
  .actions { justify-content: flex-start; }
  .preview, .formGrid, .caddyFormGrid { grid-template-columns: 1fr; }
  .subTabs { max-width: 100%; overflow-x: auto; }
}
