:root {
  color-scheme: light;
  --app-bg: #edf3fb;
  --panel-bg: rgba(255, 255, 255, 0.82);
  --panel-strong: rgba(255, 255, 255, 0.96);
  --panel-border: rgba(148, 163, 184, 0.18);
  --soft-border: rgba(148, 163, 184, 0.12);
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #94a3b8;
  --accent: #4f46e5;
  --accent-soft: rgba(79, 70, 229, 0.08);
  --success: #059669;
  --success-soft: rgba(5, 150, 105, 0.1);
  --warning: #d97706;
  --warning-soft: rgba(217, 119, 6, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 18px;
  --shadow-xl: 0 24px 64px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  font-family: Inter, "SF Pro Text", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(79, 70, 229, 0.08), transparent 26%),
    radial-gradient(circle at top right, rgba(14, 165, 233, 0.08), transparent 22%),
    linear-gradient(180deg, #f7faff 0%, var(--app-bg) 100%);
  color: var(--text-primary);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.45) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.45) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.3), transparent 70%);
}

body.modal-open {
  overflow: hidden;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  min-height: 100vh;
  padding: 28px 20px;
  backdrop-filter: blur(18px);
  background: rgba(255, 255, 255, 0.72);
  border-right: 1px solid var(--panel-border);
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 24px;
}

.brand-block {
  display: grid;
  gap: 6px;
}

.brand-block h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.brand-block p,
.section-lede,
.microcopy,
.empty-copy {
  margin: 0;
  color: var(--text-secondary);
  line-height: 1.5;
}

.sidebar-nav {
  display: grid;
  gap: 10px;
  align-content: start;
}

.nav-link {
  border-radius: 18px;
  text-decoration: none;
  color: var(--text-primary);
  padding: 14px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.45);
  transition: background 180ms ease, color 180ms ease, transform 180ms ease;
}

.nav-link:hover {
  transform: translateY(-1px);
}

.nav-link.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.page {
  height: 100vh;
  padding: 0 20px 20px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  overflow: hidden;
}

.page-topbar {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 18px;
  padding: 14px 0 8px;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  backdrop-filter: none;
  position: sticky;
  top: 0;
  z-index: 10;
}

.page-topbar h2,
.panel-card h3,
.modal-card h3,
.section-title {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.topbar-meta,
.chip-row,
.toolbar,
.card-footer,
.stack-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.glass-panel,
.panel-card,
.stat-card,
.mail-card,
.modal-card,
.pill-input,
.theme-preview {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  backdrop-filter: blur(18px);
}

.panel-card,
.mail-card,
.theme-preview {
  padding: 18px;
}

.mailbox-card {
  border-radius: 30px;
  padding: 22px;
  gap: 16px;
}

.mailbox-card .title-line {
  gap: 10px;
}

.mailbox-card .card-grid {
  gap: 14px;
  margin: 10px 0 0;
}

.mailbox-card .info-card {
  padding: 16px 18px;
}

.mailbox-card .card-footer {
  padding-top: 14px;
  justify-content: flex-end;
}

.panel-grid {
  display: grid;
  gap: 16px;
}

.page-notice-sticky {
  position: sticky;
  top: 76px;
  z-index: 9;
  padding: 2px 6px 0;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(8px);
  border-radius: 12px;
}

.page-notice-sticky:empty {
  display: none;
}

#page-content {
  min-height: 0;
  overflow: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

#page-content::-webkit-scrollbar {
  display: none;
}

.full-height-panel {
  min-height: calc(100vh - 220px);
}

.admin-page-card {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.admin-section-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  padding-bottom: 14px;
}

.scroll-region {
  min-height: 0;
  max-height: 100%;
  overflow: auto;
  padding-right: 6px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.scroll-region::-webkit-scrollbar {
  display: none;
}

.detail-tab-scroll::-webkit-scrollbar {
  display: none;
}

.account-record-scroll {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.account-record-scroll::-webkit-scrollbar {
  display: none;
}

.scrollbar-hide {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.scrollbar-hide::-webkit-scrollbar {
  display: none;
}

.admin-content-flow {
  display: grid;
  gap: 14px;
  align-content: stretch;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  min-height: 0;
}

.panel-grid.two-col {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.panel-grid.rules-layout {
  grid-template-columns: 320px minmax(0, 1fr);
}

.tab-strip {
  display: inline-flex;
  gap: 10px;
  padding: 8px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--soft-border);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.05);
  margin-top: 0;
}

.admin-page-tabs {
  justify-self: start;
  position: sticky;
  top: 0;
  z-index: 5;
}

.mailbox-list-shell {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
}

.mailbox-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-content: start;
}

.tab-btn {
  border: 0;
  background: transparent;
  border-radius: 16px;
  padding: 11px 16px;
  font: inherit;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
}

.tab-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.tab-btn:not(.is-active) {
  background: transparent;
}

.toolbar {
  padding: 16px 18px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--soft-border);
}

.toolbar .control {
  min-width: 138px;
}

.control,
.field-block {
  display: grid;
  gap: 8px;
}

.control label,
.field-block label,
.field-label {
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
}

.field-block.compact {
  gap: 6px;
}

.card-list,
.mail-list,
.detail-stack,
.modal-stack {
  display: grid;
  gap: 16px;
}

.empty-panel {
  min-height: 100%;
  display: grid;
  place-items: center;
  border-radius: 24px;
  border: 1px dashed rgba(79, 70, 229, 0.24);
  background: rgba(255, 255, 255, 0.56);
  padding: 28px;
  text-align: center;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.32);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 40;
}

.floating-modal {
  width: min(880px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  overflow: auto;
}

.mail-card {
  gap: 14px;
}

.mail-card .title-line,
.rule-card .title-line {
  display: grid;
  gap: 6px;
}

.mail-card h3,
.rule-card h3 {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 700;
}

.mono {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
}

.meta-line {
  color: var(--text-secondary);
  font-size: 0.84rem;
}

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

.basic-form-grid {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  align-items: start;
}

.daisy-card-grid {
  gap: 20px;
}

.daisy-field {
  padding: 16px 18px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.1);
}

.admin-scroll-stack {
  min-height: 0;
  height: 100%;
  overflow: auto;
  display: grid;
  gap: 16px;
  align-content: start;
  padding-right: 6px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.admin-scroll-stack::-webkit-scrollbar {
  display: none;
}

.admin-basic-card,
.admin-runtime-card,
.admin-theme-card {
  min-height: unset;
}

.admin-basic-card,
.admin-runtime-card {
  gap: 18px;
}

.admin-theme-fill {
  min-height: calc(100vh - 188px);
  align-content: start;
}

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

.runtime-grid .info-card {
  min-height: 132px;
}

.runtime-stats {
  width: 100%;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--soft-border);
  border-radius: 24px;
  box-shadow: none;
}

.runtime-stats .stat {
  min-height: 146px;
}

.stat-value-compact {
  font-size: 1rem;
  line-height: 1.7;
  font-weight: 600;
  white-space: normal;
  word-break: break-all;
}

.rule-flow {
  display: grid;
  gap: 12px;
}

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

.flow-pill,
.info-card,
.result-card {
  border-radius: var(--radius-md);
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--soft-border);
}

.flow-pill h4,
.info-card h4,
.result-card h4 {
  margin: 0 0 6px;
  font-size: 0.95rem;
  font-weight: 700;
}

.match-row,
.extractor-row {
  display: grid;
  grid-template-columns: 92px 132px 132px minmax(0, 1fr) auto auto;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--soft-border);
}

.match-row .cell,
.extractor-row .cell {
  min-height: 52px;
  border-radius: 14px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  background: #f8fafc;
  color: var(--text-primary);
  font-size: 0.84rem;
  font-weight: 600;
}

.match-row .logic.and {
  background: var(--accent-soft);
  color: var(--accent);
}

.match-row .logic.or {
  background: var(--success-soft);
  color: var(--success);
}

.help-banner {
  padding: 16px 18px;
  border-radius: var(--radius-md);
  background: #fff7ed;
  border: 1px solid rgba(249, 115, 22, 0.18);
  color: #9a3412;
}

.icon-btn {
  width: 44px;
  min-width: 44px;
  padding: 0;
  font-size: 1.1rem;
}

.btn-danger {
  background: #fee2e2;
  color: #b91c1c;
}

.badge-soft {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 0 12px;
  font-size: 0.76rem;
  font-weight: 700;
}

.badge-soft.badge-accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge-soft.badge-success {
  background: var(--success-soft);
  color: var(--success);
}

.badge-soft.badge-warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.badge-soft.badge-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.modal-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 92px 24px;
}

.modal-card {
  width: min(1060px, calc(100vw - 48px));
  min-height: 720px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.modal-card.is-medium {
  width: min(920px, calc(100vw - 48px));
  min-height: 700px;
}

.modal-card.is-large {
  width: min(1100px, calc(100vw - 48px));
  min-height: 780px;
}

.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-header {
  min-height: 96px;
  padding: 24px 28px;
  border-bottom: 1px solid var(--soft-border);
  justify-content: space-between;
}

.modal-header-split {
  align-items: flex-start;
}

.modal-title-block {
  display: grid;
  gap: 8px;
  flex: 1 1 auto;
}

.modal-body {
  padding: 28px;
  display: grid;
  gap: 18px;
}

.modal-body-form {
  gap: 24px;
}

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

.modal-switch-row {
  padding-top: 4px;
}

.modal-footer {
  min-height: 92px;
  padding: 20px 28px;
  border-top: 1px solid var(--soft-border);
  background: rgba(248, 250, 252, 0.72);
  border-bottom-left-radius: 28px;
  border-bottom-right-radius: 28px;
}

.modal-footer-right {
  justify-content: flex-end;
}

.modal-section {
  padding: 20px;
  border-radius: 24px;
  background: rgba(248, 250, 252, 0.86);
  border: 1px solid var(--soft-border);
  display: grid;
  gap: 12px;
}

.modal-section.accent {
  background: var(--accent-soft);
}

.modal-section.warning {
  background: #fff7ed;
}

.modal-section.muted {
  background: #f3f4f6;
}

.rule-option {
  padding: 18px;
  border-radius: 22px;
  border: 1px solid var(--soft-border);
  background: rgba(255, 255, 255, 0.82);
  display: grid;
  gap: 8px;
}

.rule-option.is-selected {
  background: var(--accent-soft);
}

.theme-swatch-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.theme-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  align-content: start;
}

.theme-card {
  border: 1px solid var(--soft-border);
  background: rgba(255, 255, 255, 0.86);
  border-radius: 22px;
  padding: 18px;
  display: grid;
  gap: 14px;
  text-align: left;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.theme-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.08);
  border-color: rgba(79, 70, 229, 0.24);
}

.theme-card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  text-transform: capitalize;
}

.theme-card-preview {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 8px;
}

.theme-card-preview span {
  height: 72px;
  border-radius: 16px;
}

.theme-light span:nth-child(1) { background: #ffffff; border: 1px solid rgba(15, 23, 42, 0.08); }
.theme-light span:nth-child(2) { background: #eef2ff; }
.theme-light span:nth-child(3) { background: #dbeafe; }
.theme-dark span:nth-child(1) { background: #111827; }
.theme-dark span:nth-child(2) { background: #1f2937; }
.theme-dark span:nth-child(3) { background: #374151; }
.theme-cupcake span:nth-child(1) { background: #faf7f5; }
.theme-cupcake span:nth-child(2) { background: #fcd4dc; }
.theme-cupcake span:nth-child(3) { background: #b8f2e6; }
.theme-emerald span:nth-child(1) { background: #ecfdf5; }
.theme-emerald span:nth-child(2) { background: #34d399; }
.theme-emerald span:nth-child(3) { background: #a7f3d0; }

.theme-swatch {
  min-width: 92px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--soft-border);
  font-size: 0.82rem;
  font-weight: 700;
}

.notice-inline {
  color: var(--text-secondary);
  font-size: 0.82rem;
}

.app-toast-item {
  min-width: 280px;
  max-width: 420px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14);
  border: 1px solid rgba(148, 163, 184, 0.1);
  border-radius: 16px;
  animation: toast-in 0.18s ease;
}

.app-toast-close {
  min-height: 28px;
  height: 28px;
  width: 28px;
  min-width: 28px;
  padding: 0;
  opacity: 0.75;
}

.app-toast-close:hover {
  opacity: 1;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

  .sidebar {
    position: relative;
    height: auto;
    min-height: 0;
    grid-template-rows: auto auto;
    padding: 16px;
    gap: 16px;
  }

  .sidebar-nav {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
  }

  .nav-link {
    padding: 12px 14px;
  }

  .page {
    height: auto;
    min-height: 0;
    padding: 0 16px 16px;
    overflow: visible;
  }

  .page-topbar {
    position: static;
    padding-top: 4px;
  }

  #page-content {
    overflow: visible;
  }

  .panel-grid.two-col,
  .panel-grid.rules-layout,
  .card-grid,
  .flow-strip,
  .mailbox-grid,
  .basic-form-grid,
  .runtime-grid,
  .theme-card-grid,
  .modal-form-grid {
    grid-template-columns: 1fr;
  }

  .match-row,
  .extractor-row {
    grid-template-columns: 1fr;
  }
}
