:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --line: #d7dee8;
  --text: #142132;
  --muted: #62748a;
  --accent: #0d6b6f;
  --accent-2: #f59e0b;
  --danger: #c53d3d;
  --blue-soft: #d8eef4;
  --green-soft: #d7f5e3;
  --amber-soft: #fff0c7;
  --red-soft: #ffe0e0;
  --gray-soft: #eef2f7;
  --shadow: 0 20px 40px rgba(20, 33, 50, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "IBM Plex Sans", "Noto Sans SC", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(13,107,111,0.08), transparent 35%),
    radial-gradient(circle at bottom right, rgba(245,158,11,0.08), transparent 30%),
    var(--bg);
  color: var(--text);
}
a { color: inherit; text-decoration: none; }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card, .panel, .stat-card {
  background: rgba(255,255,255,0.86);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.7);
  box-shadow: var(--shadow);
}

.login-card {
  width: min(420px, 100%);
  border-radius: 28px;
  padding: 32px;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  padding: 28px;
  border-right: 1px solid var(--line);
  background: rgba(255,255,255,0.75);
  backdrop-filter: blur(10px);
}

.brand h1 { margin: 6px 0 0; }
.brand-lockup,
.login-brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  display: block;
}

.brand-mark-large {
  width: 52px;
  height: 52px;
}

.login-brand {
  margin-bottom: 18px;
}

.brand-kicker, .eyebrow {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 28px 0;
}

.nav a {
  position: relative;
  overflow: hidden;
  padding: 12px 14px 12px 18px;
  border-radius: 14px;
  color: var(--muted);
  transition:
    background-color 0.18s ease,
    color 0.18s ease,
    transform 0.18s ease,
    box-shadow 0.18s ease;
}

.nav a::before {
  content: "";
  position: absolute;
  inset: 8px auto 8px 8px;
  width: 4px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--accent), #14999f);
  opacity: 0;
  transform: scaleY(0.4);
  transform-origin: center;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.nav a.active,
.nav a:hover {
  color: var(--text);
  background: var(--gray-soft);
  transform: translateX(3px);
}

.nav a.active {
  box-shadow: inset 0 0 0 1px rgba(13,107,111,0.08);
}

.nav a.active::before,
.nav a:hover::before {
  opacity: 1;
  transform: scaleY(1);
}

.content {
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.page-transition-target {
  will-change: opacity, transform;
}

body.htmx-swapping .page-transition-target {
  opacity: 0.34;
  transform: translateY(10px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

body.htmx-settling .page-transition-target {
  animation: page-enter 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 20px;
}

.page-header h2 { margin: 6px 0; font-size: 30px; }
.page-header p { margin: 0; color: var(--muted); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.stat-card, .panel {
  border-radius: 24px;
  padding: 22px;
}

.stat-card span {
  display: block;
  color: var(--muted);
  margin-bottom: 10px;
}

.stat-card strong { font-size: 32px; }

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.panel h3 {
  margin-top: 0;
  margin-bottom: 14px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

label span {
  display: block;
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 6px;
}

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

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.92);
}

textarea {
  line-height: 1.6;
  resize: vertical;
}

.checkbox {
  display: flex;
  gap: 10px;
  align-items: center;
}

.checkbox input { width: auto; }

button, .button-secondary, .ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  padding: 11px 18px;
  border: 0;
  cursor: pointer;
  background: linear-gradient(135deg, #0d6b6f, #14999f);
  color: white;
}

.button-secondary, .ghost-button {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

.ghost-button.danger { color: var(--danger); border-color: rgba(197,61,61,0.3); }
.ghost-button.wide { width: 100%; }

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

.badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-blue { background: var(--blue-soft); color: #0b5163; }
.badge-green { background: var(--green-soft); color: #14613a; }
.badge-amber { background: var(--amber-soft); color: #9a6700; }
.badge-red { background: var(--red-soft); color: #9b2c2c; }
.badge-gray { background: var(--gray-soft); color: #556070; }

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th, .data-table td {
  padding: 14px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(215, 222, 232, 0.8);
  vertical-align: top;
}

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

.alert {
  border-radius: 14px;
  padding: 12px 14px;
}

.alert-error {
  background: var(--red-soft);
  color: #962d2d;
}

.notice-stack {
  position: fixed;
  top: 22px;
  right: 22px;
  z-index: 60;
  width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}

.notice-toast {
  pointer-events: auto;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 18px;
  border-radius: 22px;
  color: #fff;
  background: linear-gradient(135deg, rgba(20,33,50,0.96), rgba(62,116,138,0.94));
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 24px 60px rgba(20, 33, 50, 0.22);
  backdrop-filter: blur(14px);
  animation: notice-enter 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.notice-success {
  background: linear-gradient(135deg, rgba(11,81,99,0.96), rgba(13,107,111,0.96));
}

.notice-error {
  background: linear-gradient(135deg, rgba(136, 40, 40, 0.96), rgba(197, 61, 61, 0.94));
}

.notice-copy strong {
  display: block;
  margin-bottom: 6px;
  font-size: 15px;
}

.notice-copy p {
  margin: 0;
  line-height: 1.55;
  color: rgba(255,255,255,0.82);
}

.notice-close {
  flex: 0 0 auto;
  padding: 9px 12px;
  min-width: auto;
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.2);
}

.notice-stack.is-dismissing .notice-toast {
  animation: notice-exit 0.18s ease forwards;
}

.modal-shell[hidden] {
  display: none;
}

.modal-shell {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 33, 50, 0.42);
  backdrop-filter: blur(6px);
}

.modal-card {
  position: relative;
  width: min(480px, 100%);
  padding: 24px;
  border-radius: 28px;
  background: rgba(255,255,255,0.94);
  border: 1px solid rgba(255,255,255,0.72);
  box-shadow: 0 28px 70px rgba(20, 33, 50, 0.18);
  transform: translateY(10px) scale(0.98);
  opacity: 0;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.modal-shell.is-open .modal-card {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.modal-copy h3 {
  margin: 8px 0 10px;
  font-size: 24px;
}

.modal-copy p {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 22px;
}

.preview-card {
  border-radius: 20px;
  padding: 18px;
  background: linear-gradient(135deg, rgba(13,107,111,0.1), rgba(245,158,11,0.08));
  border: 1px solid rgba(13,107,111,0.15);
  min-height: 160px;
}

.preview-text {
  white-space: pre-line;
  line-height: 1.7;
}

.preview-text a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(13,107,111,0.3);
  text-underline-offset: 3px;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid rgba(215, 222, 232, 0.8);
}

.settings-actions form {
  margin: 0;
}

.settings-actions .ghost-button {
  background: rgba(255,255,255,0.7);
}

.file-picker {
  position: relative;
  display: grid;
  gap: 10px;
  padding: 18px;
  border-radius: 20px;
  border: 1px dashed rgba(13,107,111,0.34);
  background:
    linear-gradient(135deg, rgba(13,107,111,0.08), rgba(20,153,159,0.04)),
    rgba(255,255,255,0.76);
  cursor: pointer;
  transition:
    border-color 0.18s ease,
    transform 0.18s ease,
    box-shadow 0.18s ease,
    background-color 0.18s ease;
}

.file-picker:hover {
  border-color: rgba(13,107,111,0.56);
  transform: translateY(-1px);
  box-shadow: 0 18px 32px rgba(13, 107, 111, 0.08);
}

.file-picker:focus-within {
  border-color: rgba(13,107,111,0.72);
  box-shadow: 0 0 0 4px rgba(13,107,111,0.12);
}

.file-picker input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  padding: 0;
  margin: 0;
  border: 0;
}

.file-picker-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(13,107,111,0.1);
  color: var(--accent);
  font-weight: 600;
}

.file-picker-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.file-picker-hint {
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

[data-file-picker][data-has-file="false"] .file-picker-name {
  color: var(--muted);
  font-weight: 500;
}

.thumb-grid {
  display: grid;
  gap: 10px;
}

.thumb {
  display: block;
  padding: 12px;
  border-radius: 14px;
  background: var(--gray-soft);
  word-break: break-all;
}

@keyframes page-enter {
  from {
    opacity: 0.44;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes notice-enter {
  from {
    opacity: 0;
    transform: translateY(-10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes notice-exit {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
  }
}

@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .page-header { flex-direction: column; }
  .notice-stack {
    top: auto;
    right: 16px;
    bottom: 16px;
    left: 16px;
    width: auto;
  }
}

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

  body.htmx-swapping .page-transition-target,
  body.htmx-settling .page-transition-target {
    opacity: 1;
    transform: none;
  }
}
