:root {
  color-scheme: dark;
  --ink: #f3f7ff;
  --muted: #8b9ab1;
  --muted-2: #64748b;
  --base: #050914;
  --panel: #0b1220;
  --panel-2: #101927;
  --line: rgba(148, 163, 184, 0.16);
  --line-strong: rgba(148, 163, 184, 0.28);
  --cyan: #22d3ee;
  --blue: #4f7cff;
  --green: #38d996;
  --amber: #f7c760;
  --red: #fb7185;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--base); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 15%, rgba(34, 211, 238, 0.1), transparent 28rem),
    radial-gradient(circle at 88% 82%, rgba(79, 124, 255, 0.1), transparent 32rem),
    var(--base);
  font-size: 1rem;
  line-height: 1.5;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid rgba(34, 211, 238, 0.38);
  outline-offset: 2px;
}

.auth-page::before, .dashboard-page::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.34;
  background-image:
    linear-gradient(rgba(148, 163, 184, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.055) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: linear-gradient(to bottom, black, transparent 80%);
}

.auth-page {
  display: grid;
  place-items: center;
  padding: 2.5rem;
}

.auth-shell {
  position: relative;
  z-index: 1;
  width: min(1030px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px;
  border: 1px solid var(--line);
  border-radius: 28px;
  overflow: hidden;
  background: rgba(7, 13, 25, 0.84);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.auth-intro {
  min-height: 650px;
  padding: 4.5rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  overflow: hidden;
  border-right: 1px solid var(--line);
}

.auth-intro::after {
  content: "";
  position: absolute;
  width: 24rem;
  height: 24rem;
  right: -9rem;
  bottom: -10rem;
  border: 1px solid rgba(34, 211, 238, 0.25);
  border-radius: 50%;
  box-shadow: 0 0 0 3rem rgba(79, 124, 255, 0.03), 0 0 0 7rem rgba(34, 211, 238, 0.025);
}

.brand-mark {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  margin-bottom: 2.2rem;
  border-radius: 18px;
  background: linear-gradient(145deg, var(--cyan), var(--blue));
  color: #03101b;
  box-shadow: 0 18px 48px rgba(34, 211, 238, 0.2);
}

.brand-mark svg { width: 34px; fill: none; stroke: currentColor; stroke-width: 2; }

.eyebrow, .section-kicker {
  margin: 0 0 0.55rem;
  color: var(--cyan);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.17em;
}

.auth-intro h1 {
  margin: 0;
  font-size: clamp(2.3rem, 5vw, 4.4rem);
  line-height: 1;
  letter-spacing: -0.055em;
}

.auth-intro h1 span {
  display: block;
  margin-top: 0.45rem;
  font-weight: 650;
  color: transparent;
  background: linear-gradient(90deg, var(--cyan), #77a2ff);
  background-clip: text;
}

.intro-copy {
  max-width: 31rem;
  margin: 1.75rem 0 0;
  color: #b6c1d1;
  font-size: 1.07rem;
}

.security-note {
  max-width: 34rem;
  margin-top: 3rem;
  padding: 0.9rem 1rem;
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  color: var(--muted);
  border: 1px solid rgba(34, 211, 238, 0.18);
  border-radius: 14px;
  background: rgba(34, 211, 238, 0.055);
  font-size: 0.88rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  margin-top: 0.38rem;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(56, 217, 150, 0.12);
}

.auth-card {
  padding: 3.5rem 2.4rem;
  align-self: center;
}

.auth-card-head { display: flex; gap: 0.9rem; align-items: center; margin-bottom: 2rem; }
.auth-card-head h2, .records-toolbar h2, .dialog-head h2 { margin: 0; line-height: 1.2; }
.mini-lock { color: var(--cyan); font-size: 2.2rem; line-height: 1; transform: rotate(10deg); }

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 1.5rem;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(2, 6, 15, 0.48);
}

.auth-tab {
  border: 0;
  border-radius: 9px;
  padding: 0.72rem;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

.auth-tab.is-active { color: var(--ink); background: var(--panel-2); box-shadow: 0 4px 14px rgba(0,0,0,.22); }

.auth-form { display: grid; gap: 0.62rem; }
.auth-form label, .form-grid label { color: #c4cede; font-size: 0.88rem; font-weight: 700; }
.auth-form input { margin-bottom: 0.55rem; }

input, select, textarea {
  width: 100%;
  padding: 0.85rem 0.95rem;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: rgba(4, 9, 18, 0.72);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

input:hover, select:hover, textarea:hover { border-color: rgba(148, 163, 184, 0.45); }
input:focus, select:focus, textarea:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.1); outline: 0; }
input::placeholder, textarea::placeholder { color: #526079; }
textarea { resize: vertical; min-height: 105px; }

.primary-button, .danger-button, .ghost-button, .text-button, .icon-button {
  border: 0;
  color: var(--ink);
}

.primary-button {
  min-height: 46px;
  padding: 0.75rem 1.05rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  border-radius: 11px;
  background: linear-gradient(105deg, #19cbe7, #546eff);
  color: #04101b;
  font-weight: 850;
  box-shadow: 0 12px 30px rgba(79, 124, 255, 0.18);
}

.primary-button:hover { filter: brightness(1.08); transform: translateY(-1px); }
.primary-button:disabled { opacity: 0.6; cursor: wait; transform: none; }
.primary-button.compact { min-height: 42px; padding-inline: 1rem; }

.form-message { min-height: 1.45rem; margin: -0.4rem 0 0.5rem; color: var(--red); font-size: 0.86rem; }
.form-message.success { color: var(--green); }
.form-hint { margin: 0.3rem 0 0; color: var(--muted-2); font-size: 0.78rem; }
.is-hidden { display: none !important; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 72px;
  padding: 0 3.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(5, 9, 20, 0.82);
  backdrop-filter: blur(18px);
}

.top-brand { display: flex; align-items: center; gap: 0.72rem; color: var(--ink); text-decoration: none; font-size: 1.03rem; letter-spacing: 0.02em; }
.top-brand b { color: var(--cyan); }
.top-brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; color: #03101b; background: linear-gradient(145deg, var(--cyan), var(--blue)); font-weight: 900; }
.user-actions { display: flex; align-items: center; gap: 0.8rem; }
.access-badge { display: flex; align-items: center; gap: 0.58rem; padding: 0.55rem 0.8rem; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; font-size: 0.82rem; }
.access-badge .status-dot { margin: 0; }
.ghost-button { min-height: 40px; padding: 0.6rem 0.9rem; border: 1px solid var(--line-strong); border-radius: 10px; background: rgba(15, 23, 38, 0.7); font-weight: 700; }
.ghost-button:hover { background: #152033; border-color: rgba(148, 163, 184, 0.45); }

.dashboard-shell { position: relative; z-index: 1; width: min(1200px, calc(100% - 3rem)); margin: 0 auto; padding: 3.2rem 0 5rem; }
.welcome-row { display: flex; align-items: end; justify-content: space-between; gap: 2rem; margin-bottom: 2rem; }
.welcome-row h1 { margin: 0; font-size: clamp(1.8rem, 4vw, 3rem); letter-spacing: -0.04em; }
.welcome-row p:last-child { margin: 0.65rem 0 0; color: var(--muted); }

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1rem; }
.stat-card { min-height: 148px; padding: 1.25rem 1.35rem; display: grid; grid-template-columns: 1fr auto; border: 1px solid var(--line); border-radius: 18px; background: linear-gradient(145deg, rgba(15, 24, 39, .9), rgba(8, 14, 26, .86)); box-shadow: 0 16px 40px rgba(0,0,0,.16); }
.stat-card span { color: var(--muted); font-size: 0.88rem; font-weight: 700; }
.stat-card strong { grid-column: 1 / -1; font-size: 2.3rem; line-height: 1; letter-spacing: -0.04em; }
.stat-card small { color: var(--muted-2); }
.stat-card.accent { border-color: rgba(34, 211, 238, .25); background: linear-gradient(145deg, rgba(15, 36, 49, .92), rgba(9, 17, 31, .9)); }
.stat-card.accent strong { color: var(--cyan); }

.records-panel { border: 1px solid var(--line); border-radius: 20px; overflow: hidden; background: rgba(9, 15, 27, .88); box-shadow: 0 18px 48px rgba(0,0,0,.16); }
.records-toolbar { padding: 1.35rem 1.5rem; display: flex; align-items: end; justify-content: space-between; gap: 1rem; border-bottom: 1px solid var(--line); }
.search-box { width: min(360px, 100%); display: flex; align-items: center; gap: .55rem; color: var(--muted); }
.search-box input { min-height: 42px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 1rem 1.1rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: 0.76rem; letter-spacing: .06em; text-transform: uppercase; }
td { color: #c9d3e2; font-size: 0.9rem; }
tbody tr:hover { background: rgba(34, 211, 238, .025); }
.account-primary { display: grid; gap: .15rem; }
.account-primary strong { color: var(--ink); }
.account-primary small { color: var(--muted); }
.status-pill { display: inline-flex; align-items: center; gap: .4rem; padding: .35rem .58rem; border-radius: 999px; background: rgba(148,163,184,.1); color: #c5cfdd; font-size: .78rem; font-weight: 750; }
.status-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.status-pill.active { color: #86efc2; background: rgba(56,217,150,.09); }
.status-pill.active::before { background: var(--green); }
.status-pill.pending { color: #ffe19a; background: rgba(247,199,96,.09); }
.status-pill.pending::before { background: var(--amber); }
.status-pill.disabled { color: #fda4af; background: rgba(251,113,133,.09); }
.status-pill.disabled::before { background: var(--red); }
.row-actions { display: flex; justify-content: end; gap: .35rem; }
.row-button { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: transparent; }
.row-button:hover { color: var(--ink); border-color: var(--line-strong); background: var(--panel-2); }
.row-button.delete:hover { color: var(--red); border-color: rgba(251,113,133,.35); }
.table-status { padding: 1rem 1.5rem; color: var(--muted); font-size: .86rem; }
.table-status:empty { display: none; }
.empty-state { padding: 4.3rem 1.5rem; text-align: center; color: var(--muted); }
.empty-state > div { width: 48px; height: 48px; margin: 0 auto 1rem; display: grid; place-items: center; border-radius: 14px; color: var(--cyan); background: rgba(34,211,238,.08); font-size: 1.5rem; }
.empty-state h3 { margin: 0; color: var(--ink); }
.empty-state p { margin: .45rem 0 1rem; }
.text-button { padding: .45rem; color: var(--cyan); background: transparent; font-weight: 750; }

dialog { color: var(--ink); border: 1px solid var(--line-strong); border-radius: 20px; background: #0b1321; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(1, 4, 12, .76); backdrop-filter: blur(5px); }
.account-dialog { width: min(680px, calc(100% - 2rem)); padding: 0; }
.account-dialog form { padding: 1.5rem; }
.dialog-head { display: flex; justify-content: space-between; gap: 1rem; align-items: start; margin-bottom: 1.4rem; }
.icon-button { width: 38px; height: 38px; border-radius: 10px; color: var(--muted); background: rgba(148,163,184,.08); font-size: 1.4rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid label { display: grid; gap: .45rem; }
.form-grid .wide { grid-column: 1 / -1; }
.dialog-actions { display: flex; justify-content: end; gap: .7rem; margin-top: 1.2rem; }
.delete-dialog { width: min(410px, calc(100% - 2rem)); padding: 1.7rem; text-align: center; }
.delete-dialog h2 { margin: .8rem 0 .4rem; }
.delete-dialog p { margin: 0; color: var(--muted); }
.danger-icon { width: 46px; height: 46px; margin: 0 auto; display: grid; place-items: center; color: #2a0710; border-radius: 50%; background: var(--red); font-weight: 900; }
.danger-button { min-height: 40px; padding: .6rem .9rem; border-radius: 10px; color: white; background: #dc3654; font-weight: 800; }
.toast { position: fixed; right: 1.4rem; bottom: 1.4rem; z-index: 50; max-width: 340px; padding: .8rem 1rem; border: 1px solid rgba(56,217,150,.24); border-radius: 11px; color: #a7f3d0; background: rgba(7, 37, 31, .96); box-shadow: var(--shadow); opacity: 0; transform: translateY(10px); pointer-events: none; transition: 180ms ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { color: #fecdd3; border-color: rgba(251,113,133,.3); background: rgba(49, 11, 21, .96); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 850px) {
  .auth-page { padding: 1.2rem; }
  .auth-shell { grid-template-columns: 1fr; width: min(500px, 100%); }
  .auth-intro { min-height: auto; padding: 2.4rem; border-right: 0; border-bottom: 1px solid var(--line); }
  .auth-intro h1 { font-size: 2.5rem; }
  .intro-copy { margin-top: 1rem; }
  .security-note { margin-top: 1.5rem; }
  .brand-mark { width: 52px; height: 52px; margin-bottom: 1.5rem; }
  .auth-card { padding: 2.3rem; }
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card { min-height: 120px; }
}

@media (max-width: 640px) {
  .topbar { padding: 0 1rem; }
  .top-brand > span:last-child { display: none; }
  .access-badge { display: none; }
  .dashboard-shell { width: min(100% - 1.4rem, 1200px); padding-top: 2rem; }
  .welcome-row { align-items: stretch; flex-direction: column; gap: 1.2rem; }
  .welcome-row .primary-button { width: 100%; }
  .records-toolbar { align-items: stretch; flex-direction: column; }
  .search-box { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .auth-intro, .auth-card { padding: 1.6rem; }
  .security-note { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
