:root {
  color-scheme: light;
  --bg: #edf1f6;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --ink: #111827;
  --muted: #64748b;
  --line: #d8e0ea;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --accent: #b45309;
  --danger: #b91c1c;
  --ok: #15803d;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 8%, rgba(20, 184, 166, 0.13), transparent 28%),
    linear-gradient(135deg, #edf1f6 0%, #f8fafc 48%, #eef2f7 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgba(15, 23, 42, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 23, 42, 0.035) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(to bottom, #000, transparent 78%);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  color: #e5eef6;
  background: #0f172a;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 6px 22px;
  border-bottom: 1px solid rgba(226, 232, 240, 0.12);
}

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

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 3px;
  color: #94a3b8;
  font-size: 12px;
}

.nav-tabs {
  display: grid;
  gap: 8px;
  margin-top: 24px;
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  color: #cbd5e1;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

.nav-tab.active,
.nav-tab:hover {
  color: #fff;
  border-color: rgba(20, 184, 166, 0.35);
  background: rgba(15, 118, 110, 0.28);
}

.icon {
  width: 22px;
  text-align: center;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.hero-board {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: stretch;
  margin-bottom: 16px;
  padding: 22px;
  border: 1px solid rgba(15, 118, 110, 0.24);
  border-radius: 8px;
  color: #f8fafc;
  background:
    linear-gradient(120deg, rgba(15, 23, 42, 0.95), rgba(17, 94, 89, 0.94)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='420' height='220' viewBox='0 0 420 220'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.12'%3E%3Cpath d='M0 160C70 120 130 120 210 160s140 40 210 0'/%3E%3Cpath d='M0 84c70-40 130-40 210 0s140 40 210 0'/%3E%3C/g%3E%3C/svg%3E");
  box-shadow: var(--shadow);
  overflow: hidden;
}

.hero-board h2 {
  margin: 8px 0 8px;
  font-size: 34px;
  line-height: 1.1;
  letter-spacing: 0;
}

.hero-board p {
  max-width: 680px;
  margin: 0;
  color: #cbd5e1;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid rgba(20, 184, 166, 0.4);
  border-radius: 999px;
  color: #99f6e4;
  font-size: 12px;
  text-transform: uppercase;
}

.live-draw-card {
  display: grid;
  align-content: center;
  gap: 10px;
  min-height: 138px;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
}

.live-draw-card span {
  color: #cbd5e1;
  font-size: 13px;
}

.live-draw-card strong {
  font-size: 20px;
}

.live-balls .ball,
.draw-row.updating .ball {
  animation: popBall 0.42s ease both;
}

@keyframes popBall {
  0% {
    transform: translateY(-8px) scale(0.84);
    opacity: 0;
  }
  70% {
    transform: translateY(2px) scale(1.06);
    opacity: 1;
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.topbar h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: 0;
}

.topbar p,
.panel-head p,
.metric span,
.metric small {
  margin: 0;
  color: var(--muted);
}

.menu-toggle {
  display: none;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  white-space: nowrap;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(21, 128, 61, 0.12);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.metric {
  position: relative;
  padding: 18px;
  overflow: hidden;
}

.metric::after {
  content: "";
  position: absolute;
  top: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.18), rgba(180, 83, 9, 0.13));
}

.metric strong {
  display: block;
  margin: 8px 0 6px;
  font-size: 28px;
  line-height: 1.1;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.78fr);
  gap: 16px;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.panel-head.compact {
  align-items: flex-start;
}

.panel-head h2 {
  margin: 0 0 4px;
  font-size: 18px;
  letter-spacing: 0;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(54px, 1fr));
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.segment {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.segment.active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

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

.lottery-card {
  position: relative;
  min-height: 154px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(15, 118, 110, 0.08), rgba(245, 158, 11, 0.05)),
    var(--surface);
  overflow: hidden;
}

.lottery-card::after {
  content: "";
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 74px;
  height: 74px;
  border: 10px solid rgba(15, 118, 110, 0.08);
  border-radius: 50%;
}

.lottery-card h3 {
  margin: 0 0 10px;
  font-size: 17px;
}

.lottery-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.balls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 16px;
}

.ball {
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  border-radius: 50%;
  color: #fff;
  background: var(--brand);
  font-weight: 700;
  font-size: 13px;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.16), 0 8px 16px rgba(15, 118, 110, 0.18);
}

.ball.alt {
  background: var(--accent);
}

.ticket-panel {
  align-self: start;
}

.ticket-display {
  display: flex;
  align-items: center;
  min-height: 70px;
  padding: 14px;
  border: 1px dashed #a8b4c3;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
}

.number-pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 14px 0;
}

.num-button {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.num-button.active {
  color: #fff;
  border-color: var(--brand);
  background: var(--brand);
}

.ticket-actions {
  display: grid;
  grid-template-columns: 1fr 92px;
  gap: 10px;
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 14px;
}

.primary-button {
  color: white;
  border-color: var(--brand);
  background: var(--brand);
}

.primary-button:hover {
  background: var(--brand-dark);
}

.secondary-button,
.ghost-button {
  color: var(--ink);
  background: var(--surface);
}

.ghost-button {
  min-height: 34px;
  color: var(--muted);
}

.draw-list,
.rule-list,
.event-list {
  display: grid;
  gap: 10px;
}

.draw-row,
.rule-row,
.event-row {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.draw-row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.draw-title {
  display: grid;
  gap: 4px;
}

.draw-title strong,
.event-row strong {
  font-size: 15px;
}

.draw-title span,
.event-row span,
.rule-row span {
  color: var(--muted);
  font-size: 13px;
}

canvas {
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.search-input {
  width: min(260px, 100%);
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.form-grid,
.fund-form {
  display: grid;
  gap: 12px;
}

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

.form-grid label,
.fund-form label {
  display: grid;
  gap: 7px;
}

.form-grid label span,
.fund-form label span {
  color: var(--muted);
  font-size: 13px;
}

.form-grid input,
.form-grid select,
.fund-form input,
.fund-form select,
.notice-editor textarea {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.notice-editor {
  display: grid;
  gap: 12px;
}

.notice-editor textarea {
  padding: 12px;
  resize: vertical;
  line-height: 1.55;
}

.form-submit {
  grid-column: 1 / -1;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 16px;
}

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

.admin-card,
.fund-card {
  display: grid;
  gap: 8px;
  min-height: 112px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(145deg, #fff, #f7f9fc);
}

.admin-card strong,
.fund-card strong {
  font-size: 24px;
}

.admin-card span,
.fund-card span {
  color: var(--muted);
  font-size: 13px;
}

.fund-form {
  grid-template-columns: 1.1fr 0.9fr 0.8fr 1.2fr auto;
  align-items: center;
  margin-bottom: 14px;
}

.fund-summary {
  display: grid;
  gap: 12px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  background: var(--surface);
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  background: var(--surface-2);
  font-weight: 600;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  color: var(--brand-dark);
  background: rgba(20, 184, 166, 0.12);
}

.badge.warn {
  color: var(--danger);
  background: rgba(185, 28, 28, 0.1);
}

.rule-row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.switch {
  position: relative;
  width: 46px;
  height: 26px;
}

.switch input {
  opacity: 0;
}

.switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #cbd5e1;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  transition: transform 0.2s ease;
}

.switch input:checked + span {
  background: var(--brand);
}

.switch input:checked + span::after {
  transform: translateX(20px);
}

.settings-panel {
  max-width: 760px;
}

.settings-grid {
  display: grid;
  gap: 12px;
}

.setting-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 14px;
  min-height: 54px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  max-width: calc(100vw - 40px);
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: #0f172a;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1100px) {
  .metrics-grid,
  .lottery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .main-grid,
  .two-column,
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .hero-board,
  .fund-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: 248px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .workspace {
    padding: 16px;
  }

  .menu-toggle {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar h1 {
    font-size: 24px;
  }

  .hero-board {
    padding: 18px;
  }

  .hero-board h2 {
    font-size: 26px;
  }

  .status-strip {
    display: none;
  }

  .metrics-grid,
  .lottery-grid {
    grid-template-columns: 1fr;
  }

  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .segmented {
    width: 100%;
  }

  .ticket-actions {
    grid-template-columns: 1fr;
  }

  .form-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .draw-row {
    grid-template-columns: 1fr;
  }
}
