:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #202733;
  --muted: #657287;
  --line: #dce3ee;
  --blue: #2563eb;
  --green: #0f8f68;
  --amber: #b7791f;
  --red: #c24141;
  --ink: #172033;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.shell { min-height: 100vh; display: flex; align-items: flex-start; }
.sidebar {
  position: sticky;
  top: 0;
  flex: 0 0 250px;
  width: 250px;
  height: 100vh;
  overflow-y: auto;
  background: var(--ink);
  color: #f7fafc;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; }
.brand.large { color: var(--text); margin-bottom: 10px; font-size: 20px; }
.nav { display: grid; gap: 6px; }
.nav a {
  color: #d9e2ef;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 6px;
}
.nav a:hover { background: rgba(255,255,255,0.09); color: #fff; }
.logout-form { margin-top: auto; }

.content { flex: 1; padding: 32px; min-width: 0; }
.content.narrow { max-width: 850px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
h1 { margin: 0; font-size: 28px; line-height: 1.2; }
h2 { margin: 28px 0 12px; font-size: 18px; }
p { margin: 6px 0 0; color: var(--muted); }

.notice-dialog {
  width: min(440px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  margin: auto;
  padding: 0;
  color: var(--text);
  background: transparent;
  box-shadow: none;
}
.notice-dialog::backdrop { background: rgba(15,23,42,0.48); backdrop-filter: blur(2px); }
.dialog-shell {
  position: relative;
  overflow: hidden;
  background: #fff;
  border: 1px solid rgba(148,163,184,0.28);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(15,23,42,0.28);
}
.dialog-shell::before {
  content: '';
  display: block;
  height: 4px;
  background: var(--blue);
}
.notice-dialog.success .dialog-shell::before { background: var(--green); }
.notice-dialog.error .dialog-shell::before { background: var(--red); }
.dialog-header {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 15px;
  align-items: flex-start;
  padding: 22px 22px 0;
}
.dialog-icon {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
  border: 1px solid currentColor;
  box-shadow: inset 0 0 0 6px rgba(255,255,255,0.74);
}
.notice-dialog.info .dialog-icon { background: #eff6ff; color: var(--blue); }
.notice-dialog.success .dialog-icon { background: #ecfdf5; color: var(--green); }
.notice-dialog.error .dialog-icon { background: #fff1f2; color: var(--red); }
.notice-dialog h2 { margin: 1px 0 7px; font-size: 20px; line-height: 1.25; }
.notice-dialog p { margin: 0; color: #4b5563; line-height: 1.55; }
.notice-dialog p strong { color: var(--text); font-weight: 800; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; padding: 0 22px 22px; }
.dialog-button { min-width: 96px; }
.delete-confirm-actions .dialog-button { min-width: 118px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}
.stat span { color: var(--muted); font-size: 13px; }
.stat strong { display: block; font-size: 32px; margin-top: 8px; }
.stat-grid.compact { grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 10px; margin-bottom: 18px; }
.stat-grid.compact .stat { padding: 12px 14px; }
.stat-grid.compact .stat span { font-size: 12px; }
.stat-grid.compact .stat strong { font-size: 23px; margin-top: 4px; }

.toolbar { display: flex; gap: 10px; margin-bottom: 12px; }
.toolbar input[name='q'] { max-width: 420px; }
.status-segment {
  width: fit-content;
  max-width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin: 0 0 14px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e8eef6;
  box-shadow: inset 0 1px 2px rgba(15,23,42,0.05);
}
.segment-option {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 34px;
  min-width: 92px;
  padding: 8px 14px;
  border-radius: 6px;
  color: #4f5f73;
  text-decoration: none;
  font-weight: 800;
  font-size: 13px;
  transition: background 140ms ease, color 140ms ease, box-shadow 140ms ease;
}
.segment-option::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #64748b;
  box-shadow: 0 0 0 3px rgba(100,116,139,0.12);
  flex: 0 0 auto;
}
.segment-option[data-status='active']::before { background: var(--green); box-shadow: 0 0 0 3px rgba(15,143,104,0.12); }
.segment-option[data-status='expired']::before { background: var(--amber); box-shadow: 0 0 0 3px rgba(183,121,31,0.14); }
.segment-option[data-status='disabled']::before { background: #6d5bd0; box-shadow: 0 0 0 3px rgba(109,91,208,0.14); }
.segment-option:hover { color: var(--text); background: rgba(255,255,255,0.72); }
.segment-option.active {
  background: #fff;
  color: var(--blue);
  box-shadow: 0 1px 3px rgba(15,23,42,0.11), 0 0 0 1px rgba(37,99,235,0.13);
}
.segment-option.active[data-status='active'] { color: var(--green); box-shadow: 0 1px 3px rgba(15,23,42,0.11), 0 0 0 1px rgba(15,143,104,0.16); }
.segment-option.active[data-status='expired'] { color: var(--amber); box-shadow: 0 1px 3px rgba(15,23,42,0.11), 0 0 0 1px rgba(183,121,31,0.18); }
.segment-option.active[data-status='disabled'] { color: #4f46a5; box-shadow: 0 1px 3px rgba(15,23,42,0.11), 0 0 0 1px rgba(109,91,208,0.18); }
.segment-option:focus-visible, .button:focus-visible { outline: 3px solid rgba(37,99,235,0.28); outline-offset: 2px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
label { display: grid; gap: 7px; font-weight: 600; color: #334155; }

.table-wrap, .form-panel, .login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.table-wrap { overflow-x: auto; }
.table-wrap.compact { max-height: 360px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); background: #f8fafc; }
.note { max-width: 320px; color: var(--muted); }
.empty-state { text-align: center; color: var(--muted); font-weight: 700; padding: 24px 14px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions form { margin: 0; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 13px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.button.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.button.secondary { background: #eef6f2; border-color: #b7dfcf; color: var(--green); }
.button.warning { background: #fff7e6; border-color: #f4c46a; color: var(--amber); }
.button.lock { background: #eef2ff; border-color: #c7d2fe; color: #4338ca; }
.button.danger { background: #fff1f2; border-color: #f3a6a8; color: var(--red); }
.button.ghost { background: transparent; color: inherit; }
.button.tiny { min-height: 30px; padding: 5px 9px; font-size: 12px; }
.button.full { width: 100%; }

.badge { display: inline-flex; border-radius: 999px; padding: 4px 9px; font-size: 12px; font-weight: 700; }
.badge.active { background: #e7f7ef; color: var(--green); }
.badge.expired { background: #fff4de; color: var(--amber); }
.badge.disabled { background: #f4f6f8; color: var(--muted); }
.badge.online { background: #e7f7ef; color: var(--green); }
.badge.online::before { content: '\25CF'; margin-right: 5px; }
.badge.offline { background: #f4f6f8; color: var(--muted); }
.muted-small { font-size: 11px; color: var(--muted); margin-top: 3px; }

.form-panel { display: grid; gap: 16px; padding: 22px; }
.form-actions { display: flex; gap: 10px; }
.login-wrap { width: 100%; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(420px, 100%); padding: 28px; display: grid; gap: 16px; }
.login-panel h1 { font-size: 24px; }

@media (max-width: 820px) {
  .shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; min-height: auto; overflow: visible; }
  .content { padding: 20px; }
  .page-head { align-items: flex-start; flex-direction: column; }
  .toolbar { flex-direction: column; }
  .toolbar input[name='q'] { max-width: none; }
  .status-segment { width: 100%; }
  .segment-option { flex: 1 1 calc(50% - 4px); min-width: 0; }
}
