:root {
  --bg: #08111f;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-soft: rgba(255, 255, 255, 0.76);
  --line: #dbe7f4;
  --text: #172033;
  --muted: #64748b;
  --blue: #2563eb;
  --cyan: #06b6d4;
  --green: #16a34a;
  --amber: #f59e0b;
  --red: #dc2626;
  --slate: #334155;
  --shadow: 0 20px 70px rgba(2, 8, 23, .18);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 10%, rgba(6, 182, 212, .22), transparent 28%),
    radial-gradient(circle at 95% 0%, rgba(37, 99, 235, .22), transparent 30%),
    linear-gradient(135deg, #07111f 0%, #0b1730 48%, #0f172a 100%);
}

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

button,
a {
  cursor: pointer;
}

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

.sidebar {
  padding: 28px 22px;
  color: #e2e8f0;
  border-right: 1px solid rgba(148, 163, 184, .25);
  background: linear-gradient(180deg, rgba(15, 23, 42, .98), rgba(15, 23, 42, .86));
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand-mark {
  width: 62px;
  height: 62px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 900;
  letter-spacing: .08em;
  background: linear-gradient(135deg, var(--blue), var(--cyan));
  box-shadow: 0 0 38px rgba(6, 182, 212, .28);
}

.brand-title {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.32;
  margin-top: 18px;
}

.brand-subtitle {
  color: #93c5fd;
  margin-top: 8px;
  font-size: 13px;
}

.side-line {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(148, 163, 184, .7), transparent);
  margin: 24px 0;
}

.side-card,
.status-box {
  border: 1px solid rgba(148, 163, 184, .24);
  border-radius: 18px;
  padding: 16px;
  background: rgba(15, 23, 42, .62);
}

.side-card span,
.passcode-block span {
  display: block;
  color: #93c5fd;
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.side-card strong {
  color: #fff;
}

.side-card p {
  color: #cbd5e1;
  font-size: 13px;
  line-height: 1.65;
  margin: 8px 0 0;
}

.passcode-block {
  display: block;
  margin-top: 18px;
}

.passcode-block input {
  width: 100%;
  border: 1px solid rgba(148, 163, 184, .4);
  border-radius: 12px;
  padding: 11px 12px;
  color: #fff;
  background: rgba(2, 6, 23, .45);
  outline: none;
}

.status-box {
  margin-top: 16px;
  color: #cbd5e1;
  font-size: 13px;
  line-height: 1.6;
}

.main {
  padding: 28px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  color: #fff;
  margin-bottom: 22px;
}

.eyebrow {
  color: #67e8f9;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 42px);
  margin-bottom: 10px;
  letter-spacing: -.04em;
}

.topbar p {
  color: #cbd5e1;
  max-width: 900px;
  line-height: 1.7;
  margin-bottom: 0;
}

.top-actions,
.toolbar,
.action-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

button,
.file-btn,
.ghost-btn,
.secondary-btn,
.primary-btn,
.danger-btn {
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
  transition: transform .15s ease, filter .15s ease, box-shadow .15s ease;
}

button:hover,
.file-btn:hover,
.ghost-btn:hover,
.secondary-btn:hover,
.primary-btn:hover,
.danger-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.02);
}

.primary-btn {
  background: linear-gradient(135deg, var(--blue), var(--cyan));
  color: #fff;
  box-shadow: 0 12px 26px rgba(37, 99, 235, .25);
}

.secondary-btn {
  background: #e0f2fe;
  color: #075985;
  border: 1px solid #bae6fd;
}

.ghost-btn {
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(148, 163, 184, .32);
  color: inherit;
}

.sidebar .ghost-btn {
  color: #e2e8f0;
}

.danger-btn {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.full {
  width: 100%;
  margin-top: 10px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi {
  border-radius: 20px;
  padding: 18px;
  background: var(--panel-soft);
  border: 1px solid rgba(255, 255, 255, .75);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  position: relative;
  overflow: hidden;
}

.kpi::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 4px;
  background: var(--blue);
}

.kpi.warn::after { background: var(--amber); }
.kpi.ok::after { background: var(--green); }
.kpi.info::after { background: var(--cyan); }
.kpi.done::after { background: var(--slate); }

.kpi span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.kpi strong {
  display: block;
  font-size: 34px;
  margin-top: 8px;
}

.panel {
  background: var(--panel);
  border-radius: 26px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, .82);
  overflow: hidden;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(248, 250, 252, .9);
}

.tabs {
  display: flex;
  gap: 8px;
}

.tab {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}

.tab.active {
  background: #0f172a;
  color: #fff;
  border-color: #0f172a;
}

.toolbar .ghost-btn {
  color: #0f172a;
  background: #fff;
}

.search,
select,
input,
textarea {
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.search {
  min-width: 280px;
}

.action-row {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.file-btn {
  display: inline-flex;
  background: #eef2ff;
  color: #3730a3;
  border: 1px solid #c7d2fe;
}

.file-btn input {
  display: none;
}

.hint {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 340px);
}

table {
  width: 100%;
  min-width: 1250px;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  padding: 12px 10px;
  text-align: left;
  background: #0f172a;
  color: #e2e8f0;
  border-bottom: 1px solid #1e293b;
  white-space: nowrap;
}

tbody td {
  padding: 12px 10px;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: top;
}

tbody tr:hover {
  background: #f8fafc;
}

.sticky-check {
  left: 0;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 34px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.badge-pending { background: #fef3c7; color: #92400e; }
.badge-ok { background: #dcfce7; color: #166534; }
.badge-admin { background: #dbeafe; color: #1e40af; }
.badge-reject { background: #fee2e2; color: #991b1b; }
.badge-closed { background: #e2e8f0; color: #334155; }

.muted {
  color: var(--muted);
}

.case-meta {
  color: #64748b;
  font-size: 12px;
  margin-top: 4px;
}

.check-approve {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  font-weight: 800;
  color: #0f172a;
}

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

.small-btn {
  padding: 7px 10px;
  border-radius: 10px;
  font-size: 12px;
}

.modal {
  border: 0;
  padding: 0;
  background: transparent;
  width: min(1060px, calc(100vw - 32px));
}

.modal::backdrop {
  background: rgba(2, 6, 23, .62);
  backdrop-filter: blur(4px);
}

.modal-card {
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, .35);
  overflow: hidden;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px;
  background: #0f172a;
  color: #fff;
}

.modal-head h2 {
  margin-bottom: 0;
}

.icon-btn {
  border-radius: 999px;
  width: 38px;
  height: 38px;
  padding: 0;
  background: rgba(255,255,255,.12);
  color: #fff;
  font-size: 24px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  padding: 22px;
}

label {
  font-weight: 800;
  color: #334155;
  font-size: 13px;
}

label input,
label select,
label textarea {
  display: block;
  width: 100%;
  margin-top: 7px;
  font-weight: 500;
}

.wide-label {
  display: block;
  padding: 0 22px;
}

.history {
  margin: 18px 22px 0;
  border-radius: 18px;
  border: 1px solid var(--line);
  padding: 14px;
  background: #f8fafc;
  max-height: 210px;
  overflow: auto;
}

.history h3 {
  font-size: 15px;
  margin-bottom: 10px;
}

.log-item {
  display: grid;
  grid-template-columns: 170px 130px 1fr;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid #e2e8f0;
  font-size: 13px;
}

.log-item:last-child {
  border-bottom: 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 18px 22px 22px;
}

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

  .sidebar {
    position: static;
    height: auto;
  }

  .topbar,
  .panel-head {
    flex-direction: column;
  }

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

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

  .table-wrap {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 16px;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .search {
    min-width: 100%;
  }

  .toolbar,
  .top-actions,
  .action-row {
    align-items: stretch;
  }

  .toolbar > *,
  .top-actions > *,
  .action-row > * {
    width: 100%;
  }

  .hint {
    margin-left: 0;
  }
}

.repeat-tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 900;
  color: #9a3412;
  background: #ffedd5;
  border: 1px solid #fed7aa;
}

.source-edit-block {
  margin: 0 22px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #f8fafc;
  max-height: 42vh;
  overflow: auto;
}

.source-edit-block h3 {
  font-size: 15px;
  margin-bottom: 12px;
}

.compact-grid {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}

.check-line span {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-weight: 700;
}

.check-line input[type="checkbox"] {
  width: auto;
  margin: 0;
}

@media (max-width: 1024px) {
  .compact-grid {
    grid-template-columns: 1fr;
  }
}
