:root {
  --bg-1: #e9eff9;
  --bg-2: #e3ecff;
  --surface: #ffffff;
  --surface-soft: #f5f8ff;
  --text: #0e1c3d;
  --text-sub: #526182;
  --line: #d6e0f2;
  --brand: #1b4fd8;
  --brand-2: #3f6dff;
  --brand-soft: #ecf2ff;
  --success: #1a7f3a;
  --error: #9f1722;
  --radius-2xl: 18px;
  --radius-lg: 12px;
  --shadow: 0 22px 48px rgb(20 40 90 / 16%);
  --font-stack: 'Pretendard', 'Noto Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
}

body.theme-dark {
  --bg-1: #0f182e;
  --bg-2: #121e38;
  --surface: #0f1730;
  --surface-soft: #132047;
  --text: #e6eeff;
  --text-sub: #9ab0d8;
  --line: #324b78;
  --brand: #5aa1ff;
  --brand-2: #89bcff;
  --brand-soft: #192a4d;
  --success: #54c77b;
  --error: #ff6670;
  --shadow: 0 20px 42px rgb(0 0 0 / 42%);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-stack);
  color: var(--text);
  background:
    radial-gradient(circle at 8% 10%, var(--bg-1) 0%, var(--bg-2) 45%, color-mix(in oklab, var(--bg-2) 88%, #c7dcff) 100%),
    linear-gradient(140deg, var(--bg-1) 0%, var(--bg-2) 55%, #d5e5ff 100%);
}

body {
  min-height: 100vh;
  padding: max(env(safe-area-inset-top), 0px) max(env(safe-area-inset-right), 0px)
    max(env(safe-area-inset-bottom), 0px) max(env(safe-area-inset-left), 0px);
}

a {
  color: var(--brand);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 3px solid color-mix(in oklab, var(--brand) 35%, transparent);
  outline-offset: 2px;
}

.auth-shell,
.app-shell {
  width: min(1220px, calc(100% - 2rem));
  margin: 0 auto;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  align-items: center;
  gap: 1.5rem;
  padding: 2rem 0;
}

.auth-panel {
  padding: 2.5rem;
  color: white;
  border-radius: var(--radius-2xl);
  background: linear-gradient(140deg, #092a6f, #1743b2 45%, #3d69dc);
  box-shadow: var(--shadow);
  min-height: 420px;
  display: grid;
  gap: 1rem;
  align-content: center;
}

.auth-panel h1 {
  font-size: clamp(1.8rem, 2vw, 2.4rem);
  letter-spacing: -0.02em;
  margin: 0;
}

.auth-panel p {
  margin: 0;
  color: #d9e4ff;
}

.auth-panel ul {
  margin: 0;
  padding-left: 1.1rem;
  line-height: 1.7;
}

.auth-panel li {
  margin: 0.4rem 0;
}

.auth-card {
  width: min(520px, 100%);
  margin-left: auto;
  margin-right: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow);
  padding: 2rem;
}

h1,
h2 {
  margin: 0;
  line-height: 1.3;
}

h1 {
  font-size: clamp(1.5rem, 2.7vw, 2rem);
}

h2 {
  font-size: clamp(1.05rem, 2vw, 1.22rem);
}

h3 {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.35;
}

body.theme-dark .auth-panel {
  background: linear-gradient(140deg, #09162f, #102f64 45%, #2150a1);
}

body.theme-dark .auth-card,
body.theme-dark .card,
body.theme-dark .admin-panel-surface {
  background: var(--surface);
}

.stack {
  display: grid;
  gap: 0.75rem;
}

.stack label,
label {
  display: grid;
  gap: 0.45rem;
  color: var(--text);
  font-weight: 600;
  font-size: 0.96rem;
}

input,
button,
select {
  font: inherit;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  padding: 0.64rem 0.75rem;
  color: var(--text);
  min-height: 42px;
  background: var(--surface-soft);
}

body.theme-dark input,
body.theme-dark button,
body.theme-dark select {
  background: #121f40;
}

input,
select {
  width: 100%;
}

button {
  border: none;
  font-weight: 700;
  cursor: pointer;
  transition: transform 150ms ease, filter 150ms ease, background-color 150ms ease, border-color 150ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

.btn {
  text-align: center;
  width: 100%;
  min-height: 42px;
}

.btn-primary {
  background: linear-gradient(130deg, var(--brand), var(--brand-2));
  color: white;
}

.btn-outline {
  border: 1px solid #b4c7ea;
  background: white;
  color: #15356d;
}

.btn-ghost {
  background: #edf3ff;
  color: #173b73;
}

body.theme-dark .btn-outline {
  border-color: #39588b;
  background: #13254d;
  color: #c8daff;
}

body.theme-dark .btn-ghost {
  background: #11254a;
  color: #d7e5ff;
}

.btn-danger {
  background: #ffe9ec;
  border: 1px solid #ffbdc6;
  color: #a41a2a;
}

.btn-xs {
  min-height: 34px;
  width: auto;
  padding-inline: 0.75rem;
}

.feedback {
  margin-top: 0.8rem;
  min-height: 1.2rem;
}

.feedback[role='status'] {
  font-size: 0.94rem;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: normal;
}

.links {
  margin-top: 1rem;
}

.app-shell {
  padding: 1.2rem 0 2rem;
}

.topbar {
  background: color-mix(in oklab, var(--surface) 94%, #fff 6%);
  border: 1px solid var(--line);
  border-radius: var(--radius-2xl);
  padding: 1rem 1.2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 10px 26px rgb(20 47 101 / 8%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.brand h1 {
  font-size: 1.2rem;
}

.brand p {
  margin: 0.2rem 0 0;
  color: var(--text-sub);
  font-size: 0.9rem;
}

.brand-mark {
  width: 3rem;
  height: 3rem;
  border-radius: 12px;
  background: linear-gradient(135deg, #1f4ac9, #2f75ff);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.user-box {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.admin-panel {
  position: fixed;
  inset-inline-end: max(env(safe-area-inset-right), 0.8rem);
  inset-block-start: 78px;
  width: min(460px, calc(100vw - 1.5rem));
  max-height: calc(100vh - 140px);
  overflow: auto;
  display: none;
  z-index: 40;
  padding: 0;
}

.admin-panel.open {
  display: block;
}

.admin-panel-surface {
  background: color-mix(in oklab, var(--surface) 98%, var(--surface-soft));
  border-radius: var(--radius-2xl);
  padding: 1rem;
  border: 1px solid var(--line);
  box-shadow: 0 20px 40px rgb(11 21 44 / 30%);
  display: grid;
  gap: 0.85rem;
}

.admin-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 0.45rem;
}

.admin-panel h2 {
  margin-bottom: 0.2rem;
}

.admin-panel .card {
  padding: 0.85rem;
  box-shadow: none;
}

.role-pill {
  font-size: 0.8rem;
  color: #1e3f80;
  background: #ebf1ff;
  border-radius: 999px;
  padding: 0.35rem 0.72rem;
  border: 1px solid #d2e1ff;
  display: none;
}

body.theme-dark .role-pill {
  color: #dce9ff;
  background: #1c3561;
  border-color: #2e4775;
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-2xl);
  padding: 1rem;
  box-shadow: 0 10px 26px rgb(17 35 74 / 8%);
}

.panel {
  grid-column: span 4;
}

.card-wide {
  grid-column: span 12;
}

.card h2 {
  margin-bottom: 0.4rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.8rem;
  margin-bottom: 0.7rem;
}

.headline {
  font-size: 1.05rem;
  font-weight: 700;
}

.help-text {
  margin: 0.1rem 0 0;
  color: var(--text-sub);
  font-size: 0.93rem;
}

.status-chip,
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.18rem 0.62rem;
  background: var(--brand-soft);
  color: #1644a7;
  border: 1px solid #d3e2ff;
}

body.theme-dark .status-chip,
body.theme-dark .badge {
  background: #1d3258;
  color: #d0e0ff;
  border-color: #305285;
}

.progress-wrap {
  width: 100%;
  height: 10px;
  background: #ecf2ff;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #76a5ff, var(--brand));
  transition: width 0.22s ease;
}

.upload-workflow {
  display: grid;
  gap: 0.75rem;
}

.upload-toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.65rem;
}

.upload-summary {
  min-height: 1.25rem;
  color: var(--text-sub);
}

.upload-progress {
  display: grid;
  gap: 0.45rem;
}

.upload-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: #f7fbff;
  padding: 0.58rem;
  display: grid;
  gap: 0.25rem;
}

body.theme-dark .upload-item,
body.theme-dark .dropzone,
body.theme-dark table {
  background: var(--surface-soft);
}

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

.note {
  color: var(--text-sub);
  font-size: 0.92rem;
}

.dropzone {
  border: 2px dashed #bfd0ef;
  border-radius: var(--radius-lg);
  background: #f6f9ff;
  min-height: 128px;
  padding: 1rem;
  text-align: center;
  display: grid;
  align-content: center;
  gap: 0.25rem;
  cursor: pointer;
}

.dropzone.drag-over {
  border-color: #416fff;
  background: #edf3ff;
}

body.theme-dark .dropzone {
  border-color: #3a5688;
}

body.theme-dark .dropzone.drag-over {
  border-color: #78a6ff;
  background: #1a2f57;
}

.dropzone p {
  margin: 0;
}

.dropzone small {
  display: block;
  margin-top: 0.2rem;
}

.media-timeline {
  display: grid;
  gap: 1rem;
  margin-top: 0.9rem;
}

.file-bulk-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.7rem;
  margin-bottom: 0.7rem;
}

.file-bulk-actions .btn-xs {
  width: auto;
}

.file-bulk-actions .muted {
  margin-left: auto;
}

.media-year-group {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 0.8rem;
  background: color-mix(in oklab, var(--surface) 96%, var(--brand-soft));
}

.media-year-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.7rem;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}

.media-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface);
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 280px;
}

.media-preview {
  background: #0d162d;
  aspect-ratio: 16 / 10;
}

.media-preview img,
.media-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.media-meta {
  padding: 0.6rem;
  display: grid;
  gap: 0.25rem;
}

.media-select-line {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
  font-size: 0.82rem;
}

.media-name {
  font-size: 0.92rem;
  line-height: 1.35;
  word-break: break-all;
}

.media-actions {
  display: flex;
  gap: 0.4rem;
  padding: 0 0.6rem 0.6rem;
}

.media-actions .btn-xs {
  flex: 1;
  width: auto;
}

input.file-select-checkbox {
  width: 18px;
  height: 18px;
  min-height: 18px;
  margin: 0;
  padding: 0;
  border-radius: 4px;
  accent-color: var(--brand);
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 740px;
}

th,
td {
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--line);
  padding: 0.62rem 0.48rem;
  word-break: break-word;
}

th {
  color: #30436e;
  font-weight: 700;
  background: #f9fbff;
}

tr:hover td {
  background: #f8fbff;
}

body.theme-dark th {
  color: #c9d7f5;
  background: #19294e;
}

body.theme-dark tr:hover td,
body.theme-dark tr td {
  background: var(--surface);
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.table-wrap td:last-child {
  min-width: 280px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  border: 0;
  padding: 0;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  overflow: hidden;
}

.fade-up {
  opacity: 0;
  transform: translateY(16px);
  animation: fadeUp 500ms ease forwards;
}

.fade-up:nth-child(2) {
  animation-delay: 60ms;
}

.fade-up:nth-child(3) {
  animation-delay: 120ms;
}

.fade-up:nth-child(4) {
  animation-delay: 180ms;
}

@keyframes fadeUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1120px) {
  .app-shell {
    width: min(1220px, calc(100% - 1rem));
  }

  .panel {
    grid-column: span 12;
  }

  .card-wide {
    grid-column: span 12;
  }

  .upload-toolbar {
    grid-template-columns: 1fr;
  }

  .admin-panel {
    inset-inline-end: 0.75rem;
    width: min(470px, calc(100vw - 1rem));
    max-height: calc(100vh - 130px);
  }

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

@media (max-width: 900px) {
  .auth-shell {
    grid-template-columns: 1fr;
    padding: 1rem 0;
  }

  .auth-panel {
    order: 2;
    min-height: auto;
    padding: 1.4rem;
  }

  .auth-card {
    order: 1;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 680px) {
  .topbar {
    padding: 0.8rem;
  }

  .brand {
    width: 100%;
  }

  .user-box {
    width: 100%;
    justify-content: space-between;
  }

  .admin-panel {
    inset-block-start: 146px;
    width: calc(100vw - 1rem);
    max-height: calc(100vh - 176px);
  }

  .role-pill {
    display: inline-flex;
  }

  .upload-toolbar {
    grid-template-columns: 1fr;
  }

  .card {
    padding: 0.85rem;
  }

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

  .card-header {
    flex-direction: column;
  }

  table {
    min-width: 0;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
  }

  thead {
    display: none;
  }

  tr {
    margin-bottom: 0.8rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 0.5rem;
    background: #fff;
  }

  tr:hover td {
    background: #fff;
  }

  td {
    border: 0;
    display: flex;
    gap: 0.5rem;
    padding: 0.45rem 0;
    border-bottom: 1px dashed var(--line);
  }

  td::before {
    content: attr(data-label);
    flex: 0 0 94px;
    color: #32456e;
    font-weight: 700;
    font-size: 0.86rem;
  }

  td:last-child {
    border-bottom: 0;
  }

  .table-actions {
    flex-direction: column;
    width: 100%;
  }

  .table-actions .btn-xs {
    width: 100%;
  }

  .media-actions {
    flex-direction: column;
  }
}
