/* ==========================================================================
   Huevos K Admin - Premium Production UI
   ========================================================================== */
:root {
  --hk-bg-0: #06120f;
  --hk-bg-1: #0d1e1a;
  --hk-surface-1: #142a25;
  --hk-surface-2: #1a3630;
  --hk-surface-soft: rgba(255, 255, 255, 0.04);
  --hk-line-soft: rgba(220, 240, 233, 0.14);
  --hk-line-strong: rgba(220, 240, 233, 0.26);
  --hk-text-1: #f6f8f7;
  --hk-text-2: #c3d0cb;
  --hk-brand-1: #4cb39b;
  --hk-brand-2: #69d7bb;
  --hk-ok: #63cc9f;
  --hk-warn: #efbf61;
  --hk-error: #f06262;

  --hk-shadow-1: 0 12px 34px rgba(0, 0, 0, 0.26);
  --hk-shadow-2: 0 22px 54px rgba(0, 0, 0, 0.34);
  --hk-shadow-focus: 0 0 0 3px rgba(105, 215, 187, 0.34);
  --hk-radius-sm: 10px;
  --hk-radius-md: 16px;
  --hk-radius-lg: 22px;
  --hk-space-1: 0.5rem;
  --hk-space-2: 0.75rem;
  --hk-space-3: 1rem;
  --hk-space-4: 1.25rem;
  --hk-space-5: 1.75rem;
  --hk-space-6: 2.25rem;

  --hk-font-sans: Inter, "Segoe UI", Roboto, Arial, sans-serif;
  --hk-fs-xs: 0.78rem;
  --hk-fs-sm: 0.9rem;
  --hk-fs-md: 0.96rem;
  --hk-fs-lg: 1rem;

  --hk-tr-fast: 150ms ease;
  --hk-tr-base: 260ms ease;
  --hk-z-sticky: 20;
}

/* ==========================================================================
   Base
   ========================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body.admin-body {
  min-height: 100dvh;
  color: var(--hk-text-1);
  font-family: var(--hk-font-sans);
  line-height: 1.45;
  background:
    radial-gradient(1000px 520px at -12% -15%, rgba(105, 215, 187, 0.2), transparent 60%),
    radial-gradient(900px 460px at 115% 110%, rgba(239, 191, 97, 0.16), transparent 58%),
    linear-gradient(155deg, var(--hk-bg-0) 0%, var(--hk-bg-1) 45%, #091815 100%);
  padding:
    max(0.75rem, env(safe-area-inset-top))
    max(0.75rem, env(safe-area-inset-right))
    max(0.75rem, env(safe-area-inset-bottom))
    max(0.75rem, env(safe-area-inset-left));
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   Layout
   ========================================================================== */
.admin-shell {
  width: min(1260px, 100%);
  margin: 0 auto;
  min-width: 0;
}

.admin-app,
.side-col,
.main-col,
.stack {
  display: grid;
  gap: var(--hk-space-4);
}

.stack {
  gap: var(--hk-space-3);
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(300px, 370px) 1fr;
  gap: var(--hk-space-4);
  align-items: start;
  min-width: 0;
}

.card {
  min-width: 0;
  padding: var(--hk-space-4);
  border-radius: var(--hk-radius-lg);
  border: 1px solid var(--hk-line-soft);
  background:
    linear-gradient(180deg, var(--hk-surface-soft) 0%, rgba(255, 255, 255, 0) 100%),
    var(--hk-surface-1);
  box-shadow: var(--hk-shadow-1);
  transition: border-color var(--hk-tr-base), box-shadow var(--hk-tr-base), transform var(--hk-tr-base);
}

.panel-elevated {
  background:
    linear-gradient(165deg, rgba(30, 59, 52, 0.94), rgba(19, 41, 36, 0.95)),
    var(--hk-surface-1);
  border-color: rgba(105, 215, 187, 0.24);
}

.panel-section {
  position: relative;
}

.panel-section::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(105, 215, 187, 0.84), rgba(239, 191, 97, 0.7));
  opacity: 0.62;
}

.panel-section > * {
  position: relative;
  z-index: 1;
}

.card:hover {
  border-color: rgba(105, 215, 187, 0.3);
  box-shadow: var(--hk-shadow-2);
}

/* ==========================================================================
   Headings and helpers
   ========================================================================== */
h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: clamp(1.55rem, 2.2vw, 2.08rem);
}

h2 {
  font-size: clamp(1.24rem, 1.6vw, 1.54rem);
}

h3 {
  font-size: var(--hk-fs-lg);
}

.section-head,
.section-headline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--hk-space-2);
  flex-wrap: wrap;
  min-width: 0;
}

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

.eyebrow {
  margin: 0 0 0.2rem;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--hk-brand-2);
  font-weight: 700;
}

.sub {
  margin: 0;
  font-size: 0.92rem;
  color: var(--hk-text-2);
  overflow-wrap: anywhere;
}

.kbd-hint {
  font-size: 0.8rem;
  color: #cfe6de;
}

/* ==========================================================================
   Login
   ========================================================================== */
.login-wrap {
  min-height: calc(100dvh - 2rem);
  display: grid;
  place-items: center;
}

.login-card {
  width: min(470px, 100%);
  padding: var(--hk-space-5);
}

.login-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.48rem;
}

.brand-dot {
  width: 0.62rem;
  height: 0.62rem;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--hk-brand-2), var(--hk-brand-1));
  box-shadow: 0 0 0 4px rgba(105, 215, 187, 0.14);
}

.error {
  color: #ffd1d1;
  border: 1px solid rgba(240, 98, 98, 0.48);
  background: rgba(240, 98, 98, 0.2);
  border-radius: var(--hk-radius-sm);
  padding: 0.55rem 0.62rem;
  margin: 0;
  font-size: var(--hk-fs-sm);
}

/* ==========================================================================
   Topbar
   ========================================================================== */
.topbar {
  position: sticky;
  top: 0.75rem;
  z-index: var(--hk-z-sticky);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--hk-space-3);
  padding: 1rem 1.1rem;
  backdrop-filter: blur(8px);
}

.topbar-main {
  min-width: 0;
}

.topbar-actions {
  display: inline-flex;
  align-items: center;
  gap: var(--hk-space-2);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar-badge {
  opacity: 0.9;
}

/* ==========================================================================
   Forms and controls
   ========================================================================== */
label {
  display: grid;
  gap: 0.4rem;
  font-size: var(--hk-fs-sm);
  color: #d8e7e1;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  min-width: 0;
  min-height: 2.6rem;
  border-radius: var(--hk-radius-sm);
  border: 1px solid var(--hk-line-strong);
  color: var(--hk-text-1);
  background: rgba(4, 11, 9, 0.5);
  padding: 0.68rem 0.75rem;
  transition: border-color var(--hk-tr-fast), box-shadow var(--hk-tr-fast), background var(--hk-tr-fast);
}

input:hover,
select:hover {
  border-color: rgba(105, 215, 187, 0.46);
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: none;
  border-color: var(--hk-brand-2);
  box-shadow: var(--hk-shadow-focus);
}

button {
  border: 1px solid transparent;
  border-radius: var(--hk-radius-sm);
  min-height: 2.55rem;
  padding: 0.64rem 0.9rem;
  color: #042018;
  font-weight: 650;
  background: linear-gradient(180deg, var(--hk-brand-2), var(--hk-brand-1));
  cursor: pointer;
  transition: transform var(--hk-tr-fast), filter var(--hk-tr-fast), opacity var(--hk-tr-fast), background var(--hk-tr-fast);
}

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

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

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

button.ghost {
  border-color: var(--hk-line-strong);
  color: #d2e4dd;
  background: rgba(255, 255, 255, 0.05);
}

button.ghost:hover {
  background: rgba(255, 255, 255, 0.1);
}

.context-actions,
.upload-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--hk-space-2);
}

.file-input-wrap {
  padding: 0.6rem;
  border-radius: var(--hk-radius-sm);
  border: 1px dashed rgba(220, 240, 233, 0.22);
  background: rgba(255, 255, 255, 0.02);
}

/* ==========================================================================
   URL, statuses and progress
   ========================================================================== */
.url-line {
  display: grid;
  gap: var(--hk-space-2);
  min-width: 0;
}

.url-line code {
  display: block;
  width: 100%;
  min-height: 42px;
  border: 1px dashed var(--hk-line-strong);
  border-radius: var(--hk-radius-sm);
  padding: 0.58rem 0.7rem;
  background: rgba(2, 8, 7, 0.45);
  color: #c9ddd6;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.79rem;
  overflow-wrap: anywhere;
}

.status-line {
  min-height: 1.4rem;
  padding: 0.34rem 0.48rem;
  border-radius: 8px;
  overflow-wrap: anywhere;
}

.status-line.ok {
  color: #d8ffe9;
  background: rgba(99, 204, 159, 0.14);
}

.status-line.warn {
  color: #fff0cf;
  background: rgba(239, 191, 97, 0.16);
}

.status-line.err {
  color: #ffd2d2;
  background: rgba(240, 98, 98, 0.16);
}

.upload-progress {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--hk-line-strong);
  background: rgba(255, 255, 255, 0.05);
}

.upload-progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--hk-brand-1), var(--hk-brand-2));
  transition: width 180ms ease;
}

.upload-progress-text {
  min-height: 1.25rem;
  font-size: 0.84rem;
}

.upload-progress-text.warn {
  color: #ffe7ba;
}

.btn-upload-cancel {
  font-size: 0.8rem;
  padding: 0.44rem 0.74rem;
  border-color: rgba(240, 98, 98, 0.42);
  color: #ffd9d9;
  background: rgba(240, 98, 98, 0.14);
}

.btn-upload-cancel:hover {
  background: rgba(240, 98, 98, 0.24);
}

/* ==========================================================================
   Preview
   ========================================================================== */
.panel-preview {
  padding-bottom: calc(var(--hk-space-4) + 0.15rem);
}

.preview-frame-wrap {
  position: relative;
  border-radius: var(--hk-radius-md);
  border: 1px solid var(--hk-line-strong);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

.preview-frame-wrap.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    110deg,
    rgba(255, 255, 255, 0.01) 0%,
    rgba(255, 255, 255, 0.08) 50%,
    rgba(255, 255, 255, 0.01) 100%
  );
  animation: hk-preview-sheen 0.9s ease;
}

#preview-frame {
  transition: opacity var(--hk-tr-base);
}

.preview-frame-wrap.is-loading #preview-frame {
  opacity: 0.84;
}

#preview-frame {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
  background: #000;
  display: block;
}

/* ==========================================================================
   Media list
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 0.24rem 0.56rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
}

.badge.neutral {
  color: #eaf5f1;
  border-color: rgba(220, 240, 233, 0.2);
  background: rgba(220, 240, 233, 0.14);
}

.badge.ok {
  color: #e4ffef;
  border-color: rgba(99, 204, 159, 0.4);
  background: rgba(99, 204, 159, 0.24);
}

.badge.warn {
  color: #fff3d7;
  border-color: rgba(239, 191, 97, 0.45);
  background: rgba(239, 191, 97, 0.24);
}

.panel-media {
  gap: var(--hk-space-4);
}

.media-head {
  align-items: flex-start;
}

.media-head-copy {
  min-width: 0;
  display: grid;
  gap: 0.35rem;
}

.media-counter {
  padding: 0.32rem 0.72rem;
  font-size: 0.75rem;
  letter-spacing: 0.03em;
  border-color: rgba(105, 215, 187, 0.32);
  background: linear-gradient(180deg, rgba(105, 215, 187, 0.16), rgba(105, 215, 187, 0.08));
  color: #dffdF2;
}

.media-list-shell {
  min-width: 0;
  display: grid;
  gap: var(--hk-space-3);
}

.media-list-shell[data-state='loading'] .media-list {
  opacity: 0.6;
}

.media-list-shell[data-state='loading'] .media-list,
.media-list.is-busy {
  pointer-events: none;
}

.media-list-shell[data-state='loading'] .empty-state,
.media-list-shell[data-state='error'] .empty-state {
  border-style: solid;
}

.media-list-shell[data-state='loading'] .empty-state {
  border-color: rgba(239, 191, 97, 0.42);
}

.media-list-shell[data-state='error'] .empty-state {
  border-color: rgba(240, 98, 98, 0.42);
}

.empty-state {
  margin: 0;
  padding: 1rem 1rem 1rem 2.5rem;
  border: 1px dashed rgba(220, 240, 233, 0.28);
  border-radius: var(--hk-radius-md);
  color: #cfdfda;
  background: linear-gradient(180deg, rgba(6, 17, 14, 0.58), rgba(6, 17, 14, 0.42));
  position: relative;
}

.empty-state::before {
  content: "";
  position: absolute;
  left: 1rem;
  top: 50%;
  width: 0.72rem;
  height: 0.72rem;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--hk-brand-2), var(--hk-brand-1));
  transform: translateY(-50%);
  opacity: 0.9;
}

.media-list-shell[aria-busy="true"] .empty-state {
  border-style: solid;
  border-color: rgba(239, 191, 97, 0.42);
}

.media-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--hk-space-3);
  max-height: min(58vh, 900px);
  overflow: auto;
  overscroll-behavior: contain;
  padding-right: 0.2rem;
}

.media-list::-webkit-scrollbar {
  width: 10px;
}

.media-list::-webkit-scrollbar-thumb {
  background: rgba(220, 240, 233, 0.24);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.media-list::-webkit-scrollbar-track {
  background: transparent;
}

.media-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(210px, 0.9fr);
  gap: var(--hk-space-3);
  align-items: center;
  min-width: 0;
  padding: 0.9rem 0.95rem;
  border-radius: var(--hk-radius-md);
  border: 1px solid var(--hk-line-soft);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.065), rgba(255, 255, 255, 0.015)),
    rgba(0, 0, 0, 0.08);
  transition: border-color var(--hk-tr-base), transform var(--hk-tr-base), box-shadow var(--hk-tr-base);
  position: relative;
}

.media-row:hover {
  transform: translateY(-1px);
  border-color: rgba(105, 215, 187, 0.34);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
}

.media-row::after {
  content: "";
  position: absolute;
  left: 0.7rem;
  top: 0.75rem;
  bottom: 0.75rem;
  width: 2px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(105, 215, 187, 0.8), rgba(105, 215, 187, 0.2));
  opacity: 0.78;
}

.media-meta {
  min-width: 0;
  display: grid;
  gap: 0.44rem;
  padding-left: 0.62rem;
}

.media-name {
  margin: 0;
  font-size: 0.94rem;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.media-kind {
  margin: 0;
  color: #cfe1db;
  font-size: 0.82rem;
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
}

.media-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.media-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: 0.45rem;
  justify-items: stretch;
  align-content: center;
  min-width: 0;
  width: 100%;
  max-width: 360px;
  margin-left: auto;
}

.btn-tiny {
  min-height: 2rem;
  padding: 0.36rem 0.62rem;
  font-size: 0.76rem;
  font-weight: 650;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.18);
  color: #d9e8e3;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.btn-tiny:focus-visible {
  outline: none;
  box-shadow: var(--hk-shadow-focus);
}

.btn-tiny:hover {
  border-color: rgba(105, 215, 187, 0.42);
  background: rgba(105, 215, 187, 0.14);
}

.btn-tiny:focus-visible {
  box-shadow: var(--hk-shadow-focus);
}

.btn-tiny:disabled {
  opacity: 0.52;
  filter: saturate(0.7);
}

.btn-tiny.danger {
  color: #ffd8d8;
  border-color: rgba(240, 98, 98, 0.38);
  background: rgba(240, 98, 98, 0.15);
}

.btn-tiny.danger:hover {
  border-color: rgba(240, 98, 98, 0.65);
  background: rgba(240, 98, 98, 0.24);
}

/* ==========================================================================
   Motion and responsive
   ========================================================================== */
@keyframes hk-card-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes hk-preview-sheen {
  from {
    opacity: 0;
    transform: translateX(-6%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.admin-app .card {
  animation: hk-card-in 320ms ease;
}

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

@media (max-width: 760px) {
  .admin-shell {
    width: min(100%, calc(100vw - 1rem));
    margin: 0.4rem auto 1rem;
  }

  .card {
    border-radius: var(--hk-radius-md);
    padding: var(--hk-space-3);
  }

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

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .topbar button {
    width: 100%;
  }

  .media-row {
    grid-template-columns: 1fr;
    gap: var(--hk-space-2);
  }

  .media-actions {
    margin-left: 0;
    max-width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .btn-tiny {
    min-width: 0;
    width: 100%;
  }
}

@media (max-width: 430px) {
  .admin-grid {
    gap: var(--hk-space-3);
  }

  .card {
    padding: var(--hk-space-3);
  }

  h1 {
    font-size: clamp(1.3rem, 6vw, 1.6rem);
  }

  h2 {
    font-size: clamp(1.05rem, 4.8vw, 1.25rem);
  }

  .media-head {
    gap: 0.65rem;
  }

  .media-counter {
    width: 100%;
    justify-content: flex-start;
  }

  .media-actions {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 1600px) {
  .admin-shell {
    max-width: 1500px;
  }
}

@media (orientation: portrait) and (max-width: 980px) {
  #preview-frame {
    aspect-ratio: 10 / 16;
    max-height: min(72vh, 820px);
  }
}

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