/* ============================================================
   Media AI Box - Apple-style 2026
   Light, calm, generous whitespace, soft elevation.
   ============================================================ */

:root {
  /* Surface */
  --bg: #f5f5f7;
  --bg-2: #ffffff;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --surface-hover: #f0f0f3;
  --surface-pressed: #e8e8eb;
  --overlay: rgba(255, 255, 255, 0.7);

  /* Border / divider */
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.12);
  --divider: rgba(0, 0, 0, 0.06);

  /* Text */
  --text: #1d1d1f;
  --text-2: #424245;
  --text-3: #6e6e73;
  --text-muted: #86868b;
  --text-on-accent: #ffffff;

  /* Accent - Apple system blue */
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-pressed: #006edb;
  --accent-soft: rgba(0, 113, 227, 0.08);
  --accent-soft-2: rgba(0, 113, 227, 0.15);

  /* Semantic */
  --green: #34c759;
  --orange: #ff9500;
  --red: #ff3b30;
  --purple: #af52de;
  --indigo: #5e5ce6;
  --pink: #ff2d55;
  --teal: #5ac8fa;

  /* Shadows - Apple-style soft elevation */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.06), 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-lg:
    0 24px 48px -12px rgba(0, 0, 0, 0.12), 0 4px 8px rgba(0, 0, 0, 0.04);
  --shadow-focus: 0 0 0 4px rgba(0, 113, 227, 0.15);

  /* Radius */
  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  --r-xl: 22px;
  --r-2xl: 28px;
  --r-pill: 999px;

  /* Spacing */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-7: 28px;
  --s-8: 32px;
  --s-10: 40px;
  --s-12: 48px;
  --s-16: 64px;
  --s-20: 80px;

  /* Layout */
  --nav-w: 240px;
  --topbar-h: 56px;

  /* Easing */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);

  color-scheme: light;
}

/* ===== Reset / Base ===== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  font-family:
    -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Inter",
    "Heebo", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  letter-spacing: -0.01em;
}

button,
input,
textarea,
select {
  font-family: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
}

a {
  color: inherit;
  text-decoration: none;
}

::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 12px;
  border: 3px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

::selection {
  background: var(--accent-soft-2);
  color: var(--text);
}

/* ===== App Shell ===== */
#app-shell {
  display: grid;
  grid-template-columns: var(--nav-w) 1fr;
  height: 100vh;
  width: 100vw;
  background: var(--bg);
}

/* ===== Side Nav ===== */
.side-nav {
  background: var(--bg);
  border-inline-start: 1px solid var(--divider);
  display: flex;
  flex-direction: column;
  padding: var(--s-3);
  position: relative;
  z-index: 10;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-2) var(--s-4);
}

.brand-logo {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.brand-logo svg {
  width: 100%;
  height: 100%;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.brand-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}

/* + new project button */
.sidebar-new-btn {
  margin-bottom: var(--s-4);
  font-size: 13px;
}

.sidebar-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0 var(--s-2);
  margin-bottom: var(--s-2);
}

.sidebar-projects {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0 -2px;
  padding: 0 2px var(--s-3);
}

.sidebar-project {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 7px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background 0.15s;
  color: var(--text-2);
  font-size: 13px;
}

.sidebar-project:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.sidebar-project.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  box-shadow: var(--shadow-xs);
}

.sidebar-project-thumb {
  width: 24px;
  height: 24px;
  border-radius: 5px;
  background: var(--surface-pressed);
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-project-thumb.media-thumb--video .media-thumb-video-el {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.sidebar-project-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-empty {
  padding: var(--s-3) var(--s-2);
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

/* Nav-item used in footer (settings) */
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 7px 10px;
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s var(--ease-out);
}

.nav-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.nav-item.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

.nav-icon {
  font-size: 14px;
  width: 16px;
  display: flex;
  justify-content: center;
  color: var(--text-3);
}

.nav-item.active .nav-icon {
  color: var(--accent);
}

.nav-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-status-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  column-gap: 6px;
  row-gap: 2px;
  padding: 10px 12px 8px;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.2;
  color: var(--text-3);
}

.nav-footer .nav-item-lg {
  border-top: 1px solid var(--divider);
}

.sidebar-status-meta .status-bit {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  justify-content: flex-start;
}

.status-bit-sep {
  color: var(--text-3);
  opacity: 0.3;
  user-select: none;
  font-size: 10px;
}

.sidebar-status-meta .status-dot {
  width: 5px;
  height: 5px;
}

.nav-item-lg {
  padding: 10px 12px;
  font-size: 14px;
  position: relative;
}

.nav-item-lg .nav-icon {
  font-size: 16px;
  width: 18px;
}

/* Small AI status dot inside settings nav item */
.api-status-dot {
  margin-inline-start: auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--orange);
  flex-shrink: 0;
  position: relative;
}

.api-status-dot.connected {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.15);
}

.api-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  /* background: var(--surface); */
  /* border-radius: var(--r-sm); */
  font-size: 12px;
  color: var(--text-3);
  /* box-shadow: var(--shadow-xs); */
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--orange);
}

.api-status.connected .status-dot {
  background: var(--green);
}

.api-status.connected {
  color: var(--text-2);
}

/* ===== Main Area ===== */
.main-area {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: var(--bg);
}

.mobile-toggle {
  display: none;
  position: absolute;
  top: var(--s-3);
  inset-inline-end: var(--s-3);
  z-index: 5;
}

@media (max-width: 960px) {
  .mobile-toggle {
    display: flex;
  }
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 16px;
  transition: all 0.15s;
}

.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.mobile-only {
  display: none;
}

/* ===== Content Area ===== */
.content-area {
  flex: 1;
  overflow-y: auto;
  padding: var(--s-8) var(--s-10);
  position: relative;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px var(--s-4);
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.01em;
  transition: all 0.15s var(--ease-out);
  border: 1px solid transparent;
  white-space: nowrap;
  position: relative;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
  font-weight: 500;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:active:not(:disabled) {
  background: var(--accent-pressed);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-2);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-danger {
  background: var(--red);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn-text {
  background: transparent;
  color: var(--accent);
  padding: 4px 8px;
}

.btn-text:hover:not(:disabled) {
  background: var(--accent-soft);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  min-height: 0;
  line-height: 1.4;
}

.btn-lg {
  padding: 11px 22px;
  font-size: 14px;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  padding: 0;
  width: 32px;
  height: 32px;
}

.btn-icon.btn-sm {
  width: 28px;
  height: 28px;
}

/* ===== Loading Spinner ===== */
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.btn-secondary .spinner,
.btn-ghost .spinner {
  border-color: rgba(0, 0, 0, 0.15);
  border-top-color: var(--text);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-6);
  animation: fadeIn 0.2s var(--ease-out);
}

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

.modal {
  background: var(--surface);
  border-radius: var(--r-xl);
  padding: var(--s-7);
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.3s var(--ease-out);
}

.modal.modal-lg {
  max-width: 1080px;
}

.modal.modal-lg:has(.lightbox) {
  max-width: 960px;
  padding: var(--s-5);
  overflow: hidden;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s-5);
}

.modal-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

/* ===== SF-style SVG icon base ===== */
.ui-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1em;
  height: 1em;
  flex-shrink: 0;
  vertical-align: -0.125em;
  line-height: 1;
}
.ui-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* Toast icon */
.toast-icon {
  flex-shrink: 0;
  font-size: 15px;
}
.toast-success .toast-icon {
  color: #30d158;
}
.toast-error .toast-icon {
  color: #ff453a;
}
.toast-warning .toast-icon {
  color: #ffd60a;
}
.toast-info .toast-icon {
  color: #0a84ff;
}
.toast-loading .toast-icon {
  color: #0a84ff;
}
/* Spinner animation for loading icon handled inline via animateTransform SVG element */

.modal-close {
  width: 28px;
  height: 28px;
  border-radius: var(--r-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  font-size: 15px;
  transition: all 0.15s;
  background: var(--surface-2);
}

.modal-close:hover {
  background: var(--surface-pressed);
  color: var(--text);
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}

.modal-footer {
  display: flex;
  gap: var(--s-2);
  justify-content: flex-end;
  margin-top: var(--s-6);
  padding-top: var(--s-5);
  border-top: 1px solid var(--divider);
}

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom, 0px));
  inset-inline-end: 24px;
  z-index: 250;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 12px 10px 14px;
  min-width: 260px;
  max-width: 380px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.14),
    0 1px 4px rgba(0, 0, 0, 0.08);
  border: 1px solid var(--_toast-color, var(--border));
  animation: toastIn 0.28s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  pointer-events: auto;
}

.toast-success {
  --_toast-color: rgba(52, 199, 89, 0.35);
  background: color-mix(in srgb, var(--surface) 96%, #34c759);
}
.toast-error {
  --_toast-color: rgba(255, 59, 48, 0.35);
  background: color-mix(in srgb, var(--surface) 96%, #ff3b30);
}
.toast-warning {
  --_toast-color: rgba(255, 159, 10, 0.35);
  background: color-mix(in srgb, var(--surface) 96%, #ff9f0a);
}
.toast-info {
  --_toast-color: rgba(0, 122, 255, 0.28);
  background: color-mix(in srgb, var(--surface) 96%, #007aff);
}
.toast-loading {
  --_toast-color: rgba(0, 122, 255, 0.28);
  background: color-mix(in srgb, var(--surface) 96%, #007aff);
}

/* Colored dot indicator */
.toast-dot {
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
}
.toast-success .toast-dot {
  background: #34c759;
}
.toast-error .toast-dot {
  background: #ff3b30;
}
.toast-warning .toast-dot {
  background: #ff9f0a;
}
.toast-info .toast-dot {
  background: #007aff;
}
.toast-loading .toast-dot {
  background: transparent;
}

/* Spinning ring for loading toasts */
.toast-dot-spin {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid rgba(0, 122, 255, 0.2);
  border-top-color: #007aff;
  animation: toastDotSpin 0.75s linear infinite;
  flex-shrink: 0;
}
@keyframes toastDotSpin {
  to {
    transform: rotate(360deg);
  }
}

.toast-text {
  font-size: 13px;
  color: var(--text);
  flex: 1;
  font-weight: 450;
  letter-spacing: -0.008em;
  line-height: 1.4;
}

.toast-close {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  color: var(--text-3);
  padding: 0;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  font-size: 11px;
  transition: color 0.15s;
  margin-inline-start: 2px;
}
.toast-close:hover {
  color: var(--text);
}

/* Clickable toasts — return to the editing / creation context */
.toast.toast-clickable {
  cursor: pointer;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease;
}

.toast.toast-clickable:hover {
  transform: translateY(-2px);
  box-shadow:
    0 6px 28px rgba(0, 0, 0, 0.16),
    0 2px 6px rgba(0, 0, 0, 0.1);
}

.toast.toast-clickable:active {
  transform: translateY(0);
}

.toast.toast-clickable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ===== Responsive ===== */
@media (max-width: 960px) {
  :root {
    --nav-w: 0px;
  }

  .side-nav {
    position: fixed;
    inset-inline-start: 0;
    top: 0;
    bottom: 0;
    width: 240px;
    transform: translateX(100%);
    transition: transform 0.18s var(--ease-out);
    z-index: 50;
    box-shadow: var(--shadow-lg);
  }

  .side-nav.open {
    transform: translateX(0);
  }

  .mobile-only {
    display: flex;
  }

  .search-box {
    display: none;
  }

  .content-area {
    padding: var(--s-5);
  }
}

/* ===== Login Screen ===== */
.login-screen[hidden] {
  display: none;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-6);
}

.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-4);
  animation: fadeInUp 0.3s var(--ease-out);
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.login-logo svg {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: block;
  box-shadow: var(--shadow-md);
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  margin: 0;
}

.login-hint {
  font-size: 14px;
  color: var(--text-3);
  text-align: center;
  line-height: 1.5;
  margin: 0;
}

.login-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.login-input {
  text-align: center;
  font-size: 15px;
  letter-spacing: 0.1em;
}

.login-error {
  font-size: 13px;
  color: var(--danger, #ef4444);
  text-align: center;
  margin: 0;
}
