:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --line: #d9e0e7;
  --text: #17212b;
  --muted: #667585;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --accent: #7c3aed;
  --warn: #b45309;
  --danger: #b42318;
  --success: #1d4ed8;
  --shadow: 0 12px 28px rgba(24, 39, 55, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  background: #17212b;
  color: #e8edf2;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--brand);
  display: grid;
  place-items: center;
  font-weight: 800;
}

.brand strong { display: block; font-size: 15px; }
.brand span { color: #9aa7b5; font-size: 12px; }

.nav {
  display: grid;
  gap: 4px;
}

.nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 0 10px;
  border-radius: 7px;
  color: #cbd5df;
  text-decoration: none;
  font-size: 14px;
  transition: background .16s ease, color .16s ease, transform .16s ease;
}

.nav a.active,
.nav a:hover {
  background: rgba(255,255,255,0.1);
  color: #ffffff;
}

.nav-icon {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  display: grid;
  place-items: center;
  color: #ffffff;
}

.nav-icon svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-foot {
  margin-top: auto;
  padding: 12px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  color: #b9c4cf;
  font-size: 12px;
  line-height: 1.7;
  background: rgba(255,255,255,0.05);
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 64px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  gap: 16px;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search {
  width: 280px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  font-size: 13px;
  background: #fbfcfd;
}

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 13px;
  background: var(--panel);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: border-color .16s ease, background .16s ease, color .16s ease, box-shadow .16s ease, transform .16s ease;
}

.btn-primary {
  border-color: var(--brand);
  background: var(--brand);
  color: #ffffff;
}

.btn:hover {
  border-color: #b8c6d8;
  background: #f7f9fc;
  box-shadow: 0 8px 18px rgba(24, 39, 55, 0.1);
  transform: translateY(-1px);
}

.btn:active {
  box-shadow: 0 3px 8px rgba(24, 39, 55, 0.08);
  transform: translateY(0);
}

.btn-primary:hover {
  border-color: var(--brand-dark);
  background: var(--brand-dark);
  color: #ffffff;
}

.link-btn {
  position: relative;
  border: 0;
  background: transparent;
  color: var(--brand);
  font-weight: 700;
  padding: 0;
  cursor: pointer;
  transition: color .16s ease, transform .16s ease;
}

.link-btn.danger {
  color: var(--danger);
}

.link-btn:hover {
  color: var(--brand-dark);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-btn.danger:hover {
  color: #8f1d14;
}

.btn:focus-visible,
.link-btn:focus-visible,
.nav a:focus-visible,
.tab:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.22);
  outline-offset: 2px;
}

.content {
  padding: 22px 24px 28px;
  display: grid;
  gap: 16px;
}

.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid #dbe5ff;
  border-radius: 8px;
  background: #f4f7ff;
  padding: 12px 14px;
  color: #42526b;
  font-size: 13px;
}

.notice strong {
  color: var(--brand-dark);
  white-space: nowrap;
}

.notice-warn {
  border-color: #fde6b8;
  background: #fff8eb;
}

.notice-warn strong {
  color: var(--warn);
}

.flash-notice {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border: 1px solid #bfdbfe;
  border-left: 5px solid var(--brand);
  border-radius: 10px;
  background: #eff6ff;
  padding: 13px 14px;
  color: #1e3a8a;
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.12);
}

.flash-notice.error {
  border-color: #fecaca;
  border-left-color: var(--danger);
  background: #fff1f0;
  color: #991b1b;
  box-shadow: 0 12px 26px rgba(180, 35, 24, 0.1);
}

.flash-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #ffffff;
  font-weight: 900;
}

.flash-notice.error .flash-icon {
  background: var(--danger);
}

.flash-body {
  display: grid;
  gap: 2px;
}

.flash-body strong {
  color: inherit;
  font-size: 14px;
}

.flash-body span {
  color: inherit;
  font-size: 13px;
}

.notice-close {
  position: relative;
  border: 1px solid rgba(37, 99, 235, 0.24);
  border-radius: 7px;
  padding: 6px 10px;
  color: inherit;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  transition: background .16s ease, border-color .16s ease;
}

.notice-close:hover {
  background: rgba(255,255,255,0.65);
  border-color: rgba(37, 99, 235, 0.4);
}

.filter-bar,
.action-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.filter-bar input,
.filter-bar select {
  height: 36px;
  min-width: 160px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 11px;
  background: #ffffff;
  color: var(--text);
  font-size: 13px;
}

.action-strip {
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.action-strip strong,
.action-strip span {
  display: block;
}

.action-strip span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.quick-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.quick-form input:not([type="checkbox"]),
.quick-form select,
.plan-panel input:not([type="checkbox"]) {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  font-size: 13px;
}

.quick-form label,
.check-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.metric strong {
  font-size: 24px;
  line-height: 1.1;
}

.metric small {
  display: block;
  margin-top: 8px;
  color: var(--success);
  font-size: 12px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(360px, 0.8fr);
  gap: 16px;
  align-items: start;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
}

.dashboard-users {
  min-width: 0;
}

.dashboard-wide {
  grid-column: 1 / -1;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  min-height: 58px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 16px;
}

.panel-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  min-width: 920px;
}

th, td {
  padding: 13px 14px;
  border-bottom: 1px solid #edf1f4;
  text-align: left;
  white-space: nowrap;
}

th {
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.sticky-actions {
  position: sticky;
  right: 0;
  z-index: 1;
  background: #ffffff;
  box-shadow: -8px 0 14px rgba(24, 39, 55, 0.06);
}

th.sticky-actions {
  background: var(--panel-soft);
}

tr:last-child td { border-bottom: 0; }

.user-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #e8eefc;
  color: var(--brand-dark);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 13px;
}

.user-cell strong,
.device-row strong {
  display: block;
  font-size: 13px;
}

.user-cell span,
.device-row span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.pill {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.pill-ok { background: #e8eefc; color: var(--success); }
.pill-warn { background: #fff4df; color: var(--warn); }
.pill-off { background: #feeceb; color: var(--danger); }
.pill-info { background: #eee8ff; color: var(--accent); }

.row-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.inline-form {
  display: inline;
  margin: 0;
}

.task-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.task-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid #e4e9ee;
  border-radius: 8px;
  padding: 11px 12px;
  background: #ffffff;
  color: var(--muted);
  font-size: 13px;
}

.task-item strong {
  font-size: 20px;
}

.task-ok { color: var(--brand); }
.task-warn { color: var(--warn); }
.task-off { color: var(--danger); }

.right-stack {
  display: grid;
  gap: 16px;
}

.card-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.site-card,
.device-row,
.order-row {
  border: 1px solid #e4e9ee;
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
}

.site-card {
  display: grid;
  gap: 10px;
}

.site-head,
.device-row,
.order-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.site-domain {
  font-weight: 800;
  font-size: 14px;
}

.site-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

.site-actions,
.bind-actions,
.plan-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.site-actions .btn,
.bind-actions .btn,
.plan-actions .btn {
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.progress {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #ecf1f4;
}

.progress span {
  display: block;
  height: 100%;
  background: var(--brand);
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 6px;
  background: #eef2f5;
  border-radius: 8px;
}

.tab {
  position: relative;
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
  transition: background .16s ease, color .16s ease, box-shadow .16s ease;
}

.tab:hover {
  background: rgba(255,255,255,0.62);
  color: var(--text);
}

.tab.active {
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 1px 4px rgba(24,39,55,0.1);
}

.bind-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.bind-card {
  display: grid;
  gap: 10px;
  border: 1px solid #e4e9ee;
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
}

.bind-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.bind-head strong {
  display: block;
  font-size: 13px;
}

.muted {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.bind-flow {
  display: grid;
  grid-template-columns: 1fr 28px 1fr;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.bind-node {
  min-height: 58px;
  border: 1px solid #e6ebf0;
  border-radius: 8px;
  padding: 9px;
  background: #f9fafb;
}

.bind-node strong {
  display: block;
  margin-bottom: 3px;
  color: var(--text);
  font-size: 13px;
}

.bind-arrow {
  display: grid;
  place-items: center;
  color: var(--brand);
  font-weight: 900;
}

.simple-grid,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.settings-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

.grid-cards {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.ad-preview-grid,
.ad-grid {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.ad-preview-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.ad-preview-card,
.ad-card {
  border: 1px solid #e4e9ee;
  border-radius: 8px;
  background: #ffffff;
  overflow: hidden;
}

.ad-preview-card {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
}

.ad-preview-card img {
  width: 100%;
  aspect-ratio: 4 / 1;
  object-fit: cover;
  border-radius: 7px;
}

.ad-preview-card strong,
.ad-preview-card span {
  display: block;
}

.ad-preview-card span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.ad-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.ad-image {
  padding: 12px 12px 0;
}

.ad-image img {
  width: 100%;
  aspect-ratio: 4 / 1;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}

.ad-body {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.ad-title-row {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.ad-title-row h3 {
  margin: 0;
  font-size: 15px;
}

.ad-title-row p,
.ad-meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.ad-meta {
  display: grid;
  gap: 4px;
  margin: 0;
}

.ad-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ad-actions .btn {
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.ad-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.ad-form-grid label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.ad-form-grid input,
.ad-form-grid select {
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 9px;
  font-size: 12px;
}

.plan-panel {
  padding: 18px;
  display: grid;
  gap: 12px;
  align-content: start;
}

.plan-panel label:not(.check-row) {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.plan-panel h2 {
  margin: 0;
  font-size: 18px;
}

.plan-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.plan-price {
  color: var(--brand);
  font-size: 28px;
  font-weight: 800;
}

.form-panel {
  padding-bottom: 16px;
}

.form-panel label {
  display: grid;
  gap: 7px;
  margin: 14px 16px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.form-panel input {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 11px;
  color: var(--text);
  font-size: 13px;
  background: #ffffff;
}

.form-panel .btn {
  margin: 2px 16px 0;
}

@media (max-width: 1120px) {
  .app { grid-template-columns: 80px minmax(0, 1fr); }
  .brand div:last-child,
  .nav a span:last-child,
  .sidebar-foot { display: none; }
  .brand { justify-content: center; padding: 4px 0 16px; }
  .nav a { justify-content: center; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .layout,
  .dashboard-grid { grid-template-columns: 1fr; }
  .simple-grid,
  .settings-grid,
  .grid-cards,
  .ad-grid,
  .ad-preview-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .app { display: block; }
  .sidebar { display: none; }
  .topbar { align-items: stretch; flex-direction: column; padding: 14px; }
  .top-actions { flex-wrap: wrap; }
  .search { width: 100%; }
  .notice,
  .flash-notice,
  .action-strip { align-items: flex-start; flex-direction: column; }
  .flash-notice { grid-template-columns: 1fr; }
  .filter-bar input,
  .filter-bar select,
  .filter-bar .btn { width: 100%; }
  .content { padding: 14px; }
  .metrics { grid-template-columns: 1fr; }
  .simple-grid,
  .settings-grid,
  .grid-cards,
  .ad-grid,
  .ad-preview-grid { grid-template-columns: 1fr; }
  .ad-preview-card { grid-template-columns: 1fr; }
  table { min-width: 720px; }
  .panel { overflow-x: auto; }
}
