:root {
  --admin-primary: #1e40af;
  --admin-primary-hover: #1d4ed8;
  --admin-primary-soft: #eff6ff;
  --admin-accent: #f59e0b;
  --admin-success: #047857;
  --admin-danger: #b91c1c;
  --admin-bg: #f4f7fb;
  --admin-card: #ffffff;
  --admin-text: #172033;
  --admin-muted: #64748b;
  --admin-border: #dbe3ef;
  --admin-sidebar: #102b67;
  --admin-sidebar-deep: #0b1e48;
  --admin-shadow: 0 10px 30px rgb(15 23 42 / 7%);
  --sidebar-width: 252px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  color: var(--admin-text);
  background: var(--admin-bg);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--admin-bg);
}

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

button,
a,
select {
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgb(59 130 246 / 35%);
  outline-offset: 2px;
}

.admin-shell {
  min-height: 100vh;
}

.admin-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  color: #fff;
  background:
    radial-gradient(circle at 10% 10%, rgb(59 130 246 / 24%), transparent 32%),
    linear-gradient(165deg, var(--admin-sidebar), var(--admin-sidebar-deep));
  box-shadow: 8px 0 28px rgb(15 23 42 / 12%);
}

.admin-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 88px;
  padding: 18px 22px;
  border-bottom: 1px solid rgb(255 255 255 / 10%);
}

.admin-brand-mark {
  display: inline-grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border: 1px solid rgb(255 255 255 / 24%);
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(145deg, #2563eb, #1e40af);
  box-shadow: 0 8px 20px rgb(37 99 235 / 26%);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .06em;
}

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

.admin-brand strong {
  font-size: 16px;
}

.admin-brand div > span {
  margin-top: 4px;
  color: #b9c8e8;
  font-size: 12px;
}

.admin-nav {
  display: grid;
  gap: 6px;
  padding: 22px 14px;
}

.admin-nav-item {
  display: flex;
  width: 100%;
  min-height: 46px;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  color: #c7d4ed;
  background: transparent;
  text-align: left;
  transition: color 180ms ease, background 180ms ease;
}

.admin-nav-item:hover {
  color: #fff;
  background: rgb(255 255 255 / 8%);
}

.admin-nav-item.is-active {
  color: #fff;
  background: linear-gradient(90deg, rgb(59 130 246 / 70%), rgb(59 130 246 / 30%));
  box-shadow: inset 3px 0 #fbbf24;
}

.admin-nav-item svg,
.icon-button svg {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  fill: currentColor;
}

.admin-sidebar-foot {
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding: 16px 20px 24px;
  border-top: 1px solid rgb(255 255 255 / 10%);
}

.admin-sidebar-foot a {
  color: #b9c8e8;
  font-size: 13px;
  text-decoration: none;
}

.admin-sidebar-foot a:hover {
  color: #fff;
}

.admin-workspace {
  min-height: 100vh;
  margin-left: var(--sidebar-width);
}

.admin-topbar {
  position: sticky;
  top: 0;
  z-index: 25;
  display: flex;
  min-height: 88px;
  align-items: center;
  gap: 16px;
  padding: 14px 30px;
  border-bottom: 1px solid var(--admin-border);
  background: rgb(255 255 255 / 94%);
  backdrop-filter: blur(16px);
}

.admin-topbar h1,
.admin-topbar p,
.section-heading h2,
.section-heading p,
.card-heading h3 {
  margin: 0;
}

.admin-topbar h1 {
  font-size: 22px;
  letter-spacing: -.02em;
}

.admin-topbar p {
  margin-top: 4px;
  color: var(--admin-muted);
  font-size: 13px;
}

.admin-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.admin-identity strong,
.admin-identity span {
  display: block;
}

.admin-identity strong {
  font-size: 14px;
}

.admin-identity div > span {
  margin-top: 2px;
  color: var(--admin-muted);
  font-size: 12px;
}

.identity-avatar {
  display: grid !important;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 12px;
  color: var(--admin-primary);
  background: var(--admin-primary-soft);
  font-size: 14px;
  font-weight: 800;
}

.icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--admin-border);
  border-radius: 10px;
  color: var(--admin-text);
  background: #fff;
}

.admin-menu-button {
  display: none;
}

.admin-content {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 28px 30px 48px;
}

.admin-panel {
  display: none;
}

.admin-panel.is-active {
  display: block;
  animation: panel-in 220ms ease both;
}

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

.section-heading,
.card-heading,
.card-actions,
.dialog-heading,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-heading {
  margin-bottom: 20px;
}

.section-heading h2 {
  font-size: 20px;
}

.section-heading p,
.card-heading span {
  margin-top: 5px;
  color: var(--admin-muted);
  font-size: 13px;
}

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

.overview-card,
.content-card,
.filter-card {
  border: 1px solid var(--admin-border);
  border-radius: 14px;
  background: var(--admin-card);
  box-shadow: var(--admin-shadow);
}

.overview-card {
  position: relative;
  min-height: 142px;
  overflow: hidden;
  padding: 20px;
}

.overview-card::after {
  position: absolute;
  top: 0;
  right: 0;
  width: 84px;
  height: 84px;
  border-radius: 0 0 0 84px;
  background: var(--admin-primary-soft);
  content: "";
}

.overview-card span,
.overview-card strong,
.overview-card small {
  position: relative;
  z-index: 1;
  display: block;
}

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

.overview-card strong {
  margin-top: 14px;
  font-size: 32px;
  line-height: 1;
  letter-spacing: -.04em;
}

.overview-card small {
  margin-top: 12px;
  color: var(--admin-muted);
}

.content-card {
  padding: 20px;
}

.card-heading {
  margin-bottom: 16px;
}

.card-heading h3 {
  font-size: 16px;
}

.filter-card {
  display: flex;
  min-height: 78px;
  align-items: end;
  gap: 14px;
  margin-bottom: 18px;
  padding: 15px 18px;
}

label {
  display: grid;
  gap: 7px;
  color: #334155;
  font-size: 13px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  color: var(--admin-text);
  background: #fff;
  font-size: 14px;
}

textarea {
  min-height: 84px;
  padding-top: 10px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgb(59 130 246 / 12%);
}

input:disabled {
  color: #64748b;
  background: #f1f5f9;
}

.filter-card label {
  min-width: 160px;
}

.filter-note {
  align-self: center;
  margin-left: auto;
  color: var(--admin-muted);
  font-size: 13px;
}

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: 0 17px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 650;
  white-space: nowrap;
  transition: background 180ms ease, border-color 180ms ease, color 180ms ease;
}

.button:disabled {
  cursor: not-allowed;
  opacity: .58;
}

.button-primary {
  color: #fff;
  background: var(--admin-primary);
}

.button-primary:hover:not(:disabled) {
  background: var(--admin-primary-hover);
}

.button-secondary {
  border-color: #cbd5e1;
  color: #334155;
  background: #fff;
}

.button-secondary:hover:not(:disabled),
.button-quiet:hover:not(:disabled) {
  border-color: #93c5fd;
  color: var(--admin-primary);
  background: var(--admin-primary-soft);
}

.button-quiet {
  min-height: 36px;
  padding: 0 12px;
  border-color: transparent;
  color: var(--admin-muted);
  background: transparent;
}

.button-danger {
  border-color: #fecaca;
  color: var(--admin-danger);
  background: #fff7f7;
}

.button-small {
  min-height: 34px;
  padding: 0 10px;
  font-size: 12px;
}

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

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

.wide-table {
  min-width: 1080px;
}

.data-table th,
.data-table td {
  padding: 13px 12px;
  border-bottom: 1px solid #e7edf5;
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  color: #475569;
  background: #f8fafc;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.data-table tbody tr:hover {
  background: #f8fbff;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table .numeric {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.edit-table input {
  min-width: 96px;
  height: 38px;
}

.edit-table .attendance-note {
  min-width: 180px;
}

.edit-table [data-field="target"] {
  min-width: 150px;
}

.edit-table [data-field="standard-time"] {
  min-width: 150px;
}

.status-pill {
  display: inline-flex;
  min-height: 25px;
  align-items: center;
  padding: 0 9px;
  border-radius: 999px;
  color: #475569;
  background: #eef2f7;
  font-size: 12px;
  font-weight: 650;
}

.status-pill.success {
  color: var(--admin-success);
  background: #ecfdf5;
}

.status-pill.danger {
  color: var(--admin-danger);
  background: #fef2f2;
}

.status-pill.primary {
  color: var(--admin-primary);
  background: var(--admin-primary-soft);
}

.row-title strong,
.row-title span {
  display: block;
}

.row-title span {
  margin-top: 3px;
  color: var(--admin-muted);
  font-size: 12px;
}

.row-actions {
  display: flex;
  gap: 7px;
}

.card-actions {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid #e7edf5;
}

.inline-status {
  color: var(--admin-muted);
  font-size: 13px;
}

.inline-status.is-error,
.login-status {
  color: var(--admin-danger);
}

.inline-status.is-success {
  color: var(--admin-success);
}

.settings-grid {
  display: grid;
  max-width: 820px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.settings-actions {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  padding-top: 4px;
}

.admin-dialog {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  padding: 0;
  overflow: auto;
  border: 0;
  border-radius: 16px;
  color: var(--admin-text);
  background: #fff;
  box-shadow: 0 30px 80px rgb(15 23 42 / 28%);
}

.admin-dialog::backdrop {
  background: rgb(15 23 42 / 48%);
  backdrop-filter: blur(3px);
}

.admin-dialog form {
  display: grid;
  gap: 18px;
  padding: 24px;
}

.compact-dialog {
  width: min(460px, calc(100vw - 32px));
}

.dialog-heading h2,
.dialog-heading p {
  margin: 0;
}

.dialog-heading h2 {
  font-size: 19px;
}

.dialog-heading p {
  margin-top: 4px;
  color: var(--admin-muted);
  font-size: 13px;
}

.dialog-heading .icon-button {
  border: 0;
  font-size: 24px;
}

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

fieldset {
  padding: 14px;
  border: 1px solid var(--admin-border);
  border-radius: 10px;
}

legend {
  padding: 0 6px;
  color: #475569;
  font-size: 13px;
  font-weight: 700;
}

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

.group-check,
.toggle-row {
  display: flex;
  min-height: 38px;
  align-items: center;
  gap: 8px;
}

.group-check input,
.toggle-row input {
  width: 17px;
  height: 17px;
}

.dialog-actions {
  padding-top: 4px;
}

.dialog-actions .inline-status {
  margin-right: auto;
}

small {
  color: var(--admin-muted);
  font-weight: 400;
}

.admin-toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 80;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 10px;
  color: #fff;
  background: #0f172a;
  box-shadow: 0 16px 40px rgb(15 23 42 / 24%);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.admin-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.admin-toast.is-error {
  background: #991b1b;
}

.empty-cell {
  padding: 32px !important;
  color: var(--admin-muted);
  text-align: center !important;
}

.sidebar-backdrop {
  display: none;
}

.admin-only.is-hidden {
  display: none !important;
}

.is-hidden {
  display: none !important;
}

.admin-login-page {
  color: var(--admin-text);
  background: #eef3fa;
}

.login-layout {
  display: grid;
  min-height: 100vh;
  grid-template-columns: minmax(420px, 1.15fr) minmax(420px, .85fr);
}

.login-intro {
  position: relative;
  display: flex;
  overflow: hidden;
  flex-direction: column;
  padding: 48px clamp(40px, 7vw, 110px);
  color: #fff;
  background:
    linear-gradient(135deg, rgb(30 64 175 / 96%), rgb(11 30 72 / 98%)),
    repeating-linear-gradient(90deg, transparent 0 47px, rgb(255 255 255 / 4%) 48px);
}

.login-intro::after {
  position: absolute;
  right: -160px;
  bottom: -180px;
  width: 520px;
  height: 520px;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 50%;
  box-shadow: 0 0 0 70px rgb(255 255 255 / 3%), 0 0 0 140px rgb(255 255 255 / 2%);
  content: "";
}

.login-brand {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 15px;
  font-weight: 700;
}

.login-intro-copy {
  position: relative;
  z-index: 1;
  max-width: 620px;
  margin: auto 0;
}

.eyebrow {
  display: block;
  color: #93c5fd;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .18em;
}

.login-intro h1 {
  margin: 20px 0;
  font-size: clamp(40px, 5vw, 68px);
  line-height: 1.12;
  letter-spacing: -.04em;
}

.login-intro p {
  max-width: 520px;
  color: #cbd8ef;
  font-size: 17px;
  line-height: 1.8;
}

.login-safety {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 9px;
  color: #cbd8ef;
  font-size: 13px;
}

.login-safety span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 0 5px rgb(52 211 153 / 12%);
}

.login-card-wrap {
  display: grid;
  place-items: center;
  padding: 32px;
}

.login-card {
  display: grid;
  width: min(420px, 100%);
  gap: 20px;
  padding: 38px;
  border: 1px solid var(--admin-border);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 24px 70px rgb(15 23 42 / 12%);
}

.login-card h2,
.login-card p {
  margin: 0;
}

.login-card h2 {
  margin-top: 10px;
  font-size: 28px;
}

.login-card div > p {
  margin-top: 7px;
  color: var(--admin-muted);
}

.login-submit {
  width: 100%;
  min-height: 48px;
  margin-top: 2px;
}

.login-status {
  min-height: 20px;
  font-size: 13px;
  text-align: center;
}

.login-back {
  color: var(--admin-primary);
  font-size: 13px;
  text-align: center;
  text-decoration: none;
}

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

  .filter-note {
    display: none;
  }
}

@media (max-width: 900px) {
  .admin-sidebar {
    transform: translateX(-102%);
    transition: transform 220ms ease;
  }

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

  .admin-workspace {
    margin-left: 0;
  }

  .admin-menu-button {
    display: inline-grid;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgb(15 23 42 / 42%);
  }

  body.sidebar-open .sidebar-backdrop {
    display: block;
  }

  .login-layout {
    grid-template-columns: 1fr;
  }

  .login-intro {
    display: none;
  }
}

@media (max-width: 680px) {
  .admin-topbar {
    min-height: 74px;
    padding: 12px 16px;
  }

  .admin-topbar p,
  .admin-identity div,
  .admin-identity .identity-avatar {
    display: none !important;
  }

  .admin-topbar h1 {
    font-size: 18px;
  }

  .admin-content {
    padding: 20px 14px 36px;
  }

  .section-heading {
    align-items: flex-start;
  }

  .section-heading h2 {
    font-size: 18px;
  }

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

  .filter-card {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-card label {
    min-width: 0;
  }

  .history-filters .button {
    width: 100%;
  }

  .content-card {
    padding: 14px;
  }

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

  .dialog-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .dialog-actions .inline-status {
    margin: 0;
  }

  .login-card-wrap {
    padding: 18px;
  }

  .login-card {
    padding: 26px 22px;
  }
}

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