:root {
  --bg: #f4f6f9; --panel: #fff; --text: #1f2933; --muted: #616e7c; --border: #d9e2ec;
  --primary: #1565c0; --primary-dark: #0d47a1; --danger: #c62828; --ok: #2e7d32; --warn: #ef6c00;
  --radius: 8px; --shadow: 0 1px 3px rgba(15, 23, 42, .08);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--text); background: var(--bg); font-size: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
a { color: var(--primary); }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 12px; }
.hidden { display: none !important; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: #102a43; color: #d9e2ec; padding: 16px 0; }
.sidebar .brand { font-weight: 600; font-size: 16px; padding: 0 20px 16px; color: #fff; }
.sidebar a { display: block; padding: 10px 20px; color: #bcccdc; text-decoration: none; }
.sidebar a.active, .sidebar a:hover { background: #243b53; color: #fff; }
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 24px;
  background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.topbar .who { display: flex; gap: 12px; align-items: center; }
.content { padding: 24px; min-width: 0; }
.menu-toggle { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .sidebar.open { display: block; }
  .menu-toggle { display: inline-block; }
  .content { padding: 12px; }
}

/* components */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.stat .value { font-size: 24px; font-weight: 600; margin-top: 4px; }
.stat .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }

button, .btn { font: inherit; border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 6px 12px; border-radius: 6px; cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .btn:hover { border-color: var(--primary); }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-dark); }
button.danger { color: var(--danger); border-color: #f4c7c7; }
button.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.link { border: none; background: none; color: var(--primary); padding: 0 4px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.toolbar { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 12px; color: var(--muted); }
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; min-width: 0; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #90caf9; border-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.check { display: flex; align-items: center; gap: 6px; }
.checks { display: flex; flex-wrap: wrap; gap: 12px; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; background: var(--panel); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; background: #f8fafc; }
th.sortable { cursor: pointer; }
td.num, th.num { text-align: right; }
tr:hover td { background: #fafcff; }
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding-top: 10px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600;
  background: #e4e7eb; color: #3e4c59; white-space: nowrap; }
.badge.ok { background: #e3f4e5; color: var(--ok); }
.badge.bad { background: #fde7e7; color: var(--danger); }
.badge.warn { background: #fff1e0; color: var(--warn); }
.badge.info { background: #e3eefc; color: var(--primary); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; }
.tabs button.active { border-bottom-color: var(--primary); color: var(--primary); font-weight: 600; }

.notice { padding: 10px 12px; border-radius: 6px; background: #e3eefc; color: #0d3c78; margin-bottom: 12px; }
.notice.warn { background: #fff4e5; color: #8a4b00; }
.error-text { color: var(--danger); margin-top: 8px; }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start;
  justify-content: center; padding: 40px 12px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 720px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.modal.narrow { max-width: 440px; }
.modal header, .modal footer { padding: 14px 18px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.modal header { border-bottom: 1px solid var(--border); font-weight: 600; }
.modal footer { border-top: 1px solid var(--border); justify-content: flex-end; }
.modal .body { padding: 18px; }
.secret-box { font-family: Consolas, monospace; font-size: 18px; padding: 10px; background: #fff8e1;
  border: 1px dashed var(--warn); border-radius: 6px; text-align: center; user-select: all; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #243b53; color: #fff; padding: 10px 14px; border-radius: 6px; max-width: 380px; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }

/* chart */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding: 8px 0 0; border-bottom: 1px solid var(--border); }
.chart .bar { flex: 1; display: flex; flex-direction: column-reverse; min-width: 4px; }
.chart .seg-sent { background: #64b5f6; }
.chart .seg-failed { background: #e57373; }
.chart .seg-unknown { background: #cfd8dc; }
.chart-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 4px; vertical-align: -1px; }
.legend .l-sent::before { background: #64b5f6; }
.legend .l-failed::before { background: #e57373; }
.legend .l-unknown::before { background: #cfd8dc; }
.logo-preview { max-width: 160px; max-height: 80px; border: 1px solid var(--border); border-radius: 6px; padding: 6px; background: #fff; }
dl.props { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.props dt { color: var(--muted); }
dl.props dd { margin: 0; word-break: break-word; }
