* { box-sizing: border-box; }
:root {
  --bg: #F6F4EF;
  --surface: #FFFFFF;
  --line: #E8E3D8;
  --text: #1D1B19;
  --muted: #8C8880;
  --gold: #8A6526;
  --gold-soft: #F4EFE3;
  --dark: #24211D;
  --red: #C94A3F;
  --green: #2E8B62;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}
.hidden { display: none !important; }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 380px; padding: 36px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 18px 50px rgba(29,27,25,.08); }
.login-mark { width: 54px; height: 54px; display: flex; align-items: center; justify-content: center; border-radius: 16px; background: linear-gradient(135deg,#C7A86A,#8A6526); color: #fff; font-size: 22px; font-weight: 700; }
.login-card h1 { margin: 22px 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 26px; color: var(--muted); font-size: 13px; }
.login-card label { display: block; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #FCFBF8; color: var(--text); font-size: 13px; font-family: inherit; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: #C7A86A; background: #fff; }
textarea { resize: vertical; min-height: 72px; line-height: 1.6; }
.btn { border: none; border-radius: 10px; padding: 11px 18px; font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit; }
.btn.primary { background: var(--dark); color: #F1E2C2; }
.btn.primary:hover { background: #3A342B; }
.btn.ghost { background: var(--gold-soft); color: var(--gold); }
.btn.small { padding: 8px 14px; font-size: 12px; }
.btn.danger { background: #FBEEEC; color: var(--red); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.form-error { margin-top: 14px; color: var(--red); font-size: 13px; min-height: 18px; }
#loginBtn { width: 100%; margin-top: 20px; }

/* layout */
.app { display: flex; min-height: 100vh; }
.side { width: 230px; flex-shrink: 0; background: #221F1B; color: #EDE6D6; display: flex; flex-direction: column; padding: 24px 16px; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 26px; }
.brand-mark { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg,#C7A86A,#8A6526); color: #fff; font-weight: 700; }
.brand-title { font-size: 15px; font-weight: 600; }
.brand-sub { font-size: 11px; color: #9E9686; margin-top: 3px; }
nav { display: flex; flex-direction: column; gap: 4px; }
nav a { padding: 11px 14px; border-radius: 10px; color: #B9AE98; font-size: 13px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
nav a:hover { background: rgba(255,255,255,.06); color: #F1E2C2; }
nav a.active { background: #C7A86A; color: #221F1B; font-weight: 600; }
.nav-badge { background: rgba(255,255,255,.14); padding: 1px 8px; border-radius: 999px; font-size: 11px; }
nav a.active .nav-badge { background: rgba(34,31,27,.16); }
.side-foot { margin-top: auto; padding: 16px 8px 0; border-top: 1px solid rgba(255,255,255,.08); }
.side-domain { font-size: 11px; color: #8B8374; word-break: break-all; margin-bottom: 12px; }
.side-foot .btn { width: 100%; }

.main { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 22px 32px; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar h2 { margin: 0; font-size: 20px; }
.view-sub { margin-top: 4px; color: var(--muted); font-size: 12px; }
.top-actions { display: flex; align-items: center; gap: 14px; }
.save-hint { font-size: 12px; color: var(--gold); }
.content { padding: 28px 32px 60px; max-width: 1180px; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 22px; }
.card h3 { margin: 0 0 4px; font-size: 15px; }
.card .hint { margin: 0 0 18px; color: var(--muted); font-size: 12px; line-height: 1.7; }
.stat { font-size: 30px; font-weight: 700; color: var(--gold); margin-top: 10px; }
.stat-label { font-size: 12px; color: var(--muted); }
.section { margin-bottom: 22px; }
.section-title { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
.row { display: flex; gap: 12px; align-items: center; }
.row > * { flex: 1; }
.row .tight { flex: 0 0 150px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.field-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; }

.ad-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; margin-bottom: 12px; }
.ad-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.ad-key { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; color: var(--gold); background: var(--gold-soft); padding: 4px 10px; border-radius: 6px; }
.ad-name { font-size: 13px; font-weight: 600; flex: 1; }
.ad-type { font-size: 11px; color: var(--muted); }
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; }
.switch input { width: auto; }
.ad-fields { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; }
.ad-fields .wide { grid-column: span 2; }
.ad-fields label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 5px; }
.unit-input { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.quick-add { background: #FBF7EC; border: 1px dashed #D8C9A8; }
.quick-add h3 { color: var(--gold); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 8px; text-align: left; border-bottom: 1px solid #F0ECE2; }
th { color: var(--muted); font-size: 11px; font-weight: 500; }
td input { padding: 7px 9px; }
.icon-btn { border: none; background: #F6F3EC; color: var(--red); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 12px; }

pre { background: #211F1B; color: #EDE3CD; padding: 16px 18px; border-radius: 12px; font-size: 12px; line-height: 1.7; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }
.note { background: #FBF7EC; border-left: 3px solid #C7A86A; padding: 14px 16px; border-radius: 8px; font-size: 12px; line-height: 1.8; color: #6E685E; margin-bottom: 16px; }
.note.warn { background: #FCEFED; border-left-color: #C94A3F; color: #8C423A; }
.tag-line { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.pill { padding: 5px 12px; border-radius: 999px; background: var(--gold-soft); color: var(--gold); font-size: 11px; }
.status-ok { color: var(--green); }
.status-bad { color: var(--red); }

.toast { position: fixed; right: 24px; bottom: 24px; padding: 12px 20px; border-radius: 10px; background: #24211D; color: #F1E2C2; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; }
.toast.show { opacity: 1; }

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .side { width: 100%; flex-direction: row; align-items: center; flex-wrap: wrap; }
  nav { flex-direction: row; flex-wrap: wrap; }
  .side-foot { margin: 0 0 0 auto; border: none; padding: 0; }
  .side-domain { display: none; }
  .grid-4, .grid-2, .ad-fields, .field-grid, .field-grid-3 { grid-template-columns: 1fr; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
  .ad-fields .wide { grid-column: span 1; }
}
