/* ==========================================================
   CapCaption - Mobile-first CapCut style theme
   ========================================================== */
:root {
  --bg: #0b0b0d;
  --bg-elev: #161619;
  --bg-elev-2: #1f1f23;
  --card: #1c1c20;
  --border: #2a2a2f;
  --text: #f5f5f7;
  --text-dim: #9a9aa2;
  --accent: #7C4DFF;
  --accent-2: #00E5A0;
  --danger: #ff4d4f;
  --radius: 16px;
  --radius-sm: 10px;
  --nav-h: 64px;
  --topbar-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px); /* Added for mobile notch support */
}
body.theme-light {
  --bg: #f3f3f6;
  --bg-elev: #ffffff;
  --bg-elev-2: #eeeef2;
  --card: #ffffff;
  --border: #e3e3e8;
  --text: #17171a;
  --text-dim: #6b6b74;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Sinhala", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; }
img { max-width: 100%; display: block; }

.app-shell {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom));
  background: var(--bg);
}

/* ---------- Topbar ---------- */
.topbar {
  /* Adjusted height and padding to account for iOS/Android notches */
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) 14px 0 14px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 40;
  background: rgba(11, 11, 13, 0.85);
  -webkit-backdrop-filter: blur(10px); /* Fixed Safari support */
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
body.theme-light .topbar { background: rgba(255, 255, 255, 0.85); }
.topbar .title { font-weight: 700; font-size: 17px; }
.topbar .icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-elev-2); border: none; color: var(--text);
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-width: 520px; margin: 0 auto;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 50;
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--text-dim); font-size: 11px;
}
.bottom-nav a.active { color: var(--accent); }
.bottom-nav svg { width: 22px; height: 22px; }
.bottom-nav .fab {
  width: 52px; height: 52px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  margin-top: -22px; box-shadow: 0 6px 18px rgba(124, 77, 255, 0.45);
  color: #fff;
}

/* ---------- Cards / lists ---------- */
.container { padding: 14px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card-title { font-weight: 700; font-size: 15px; margin-bottom: 8px; }
.muted { color: var(--text-dim); font-size: 13px; }

.video-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.video-thumb {
  position: relative; border-radius: var(--radius-sm); overflow: hidden;
  aspect-ratio: 9/16; background: var(--bg-elev-2);
  border: 1px solid var(--border);
}
.video-thumb video, .video-thumb img { width: 100%; height: 100%; object-fit: cover; }
.video-thumb .badge {
  position: absolute; top: 6px; left: 6px;
  background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 10px;
  padding: 2px 6px; border-radius: 6px;
}
.video-thumb .expiry {
  position: absolute; bottom: 6px; left: 6px; right: 6px;
  font-size: 10px; color: #fff; background: rgba(0, 0, 0, 0.55);
  padding: 3px 6px; border-radius: 6px; text-align: center;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; padding: 13px 16px; border-radius: 14px; border: none;
  font-size: 15px; font-weight: 700; cursor: pointer;
  background: var(--bg-elev-2); color: var(--text);
}
.btn-primary { background: linear-gradient(135deg, var(--accent), #9b6bff); color: #fff; }
.btn-accent { background: linear-gradient(135deg, var(--accent-2), #00c98a); color: #04241a; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-sm { padding: 9px 12px; font-size: 13px; border-radius: 10px; width: auto; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block-row { display: flex; gap: 10px; }
.btn-block-row .btn { flex: 1; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 13px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg-elev-2);
  color: var(--text); font-size: 15px; outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.hint { font-size: 12px; color: var(--text-dim); margin-top: 6px; }
.error-box {
  background: rgba(255, 77, 79, 0.12); border: 1px solid rgba(255, 77, 79, 0.4);
  color: #ff8a8c; padding: 10px 12px; border-radius: 12px; font-size: 13px; margin-bottom: 14px;
}
.success-box {
  background: rgba(0, 229, 160, 0.12); border: 1px solid rgba(0, 229, 160, 0.4);
  color: var(--accent-2); padding: 10px 12px; border-radius: 12px; font-size: 13px; margin-bottom: 14px;
}

/* ---------- Auth screens ---------- */
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 28px 22px; max-width: 460px; margin: 0 auto; }
.auth-logo {
  width: 64px; height: 64px; border-radius: 20px; margin: 0 auto 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center; font-size: 28px; font-weight: 800; color: #fff;
}
.auth-title { text-align: center; font-size: 22px; font-weight: 800; margin-bottom: 4px; }
.auth-sub { text-align: center; color: var(--text-dim); font-size: 13px; margin-bottom: 26px; }
.auth-switch { text-align: center; margin-top: 18px; font-size: 13px; color: var(--text-dim); }
.auth-switch a { color: var(--accent); font-weight: 700; }

/* ---------- Upload page ---------- */
.upload-drop {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 40px 16px; text-align: center; color: var(--text-dim);
  background: var(--bg-elev);
}
.upload-drop.dragover { border-color: var(--accent); background: rgba(124, 77, 255, 0.08); }
.progress-bar { height: 8px; border-radius: 8px; background: var(--bg-elev-2); overflow: hidden; margin-top: 10px; }
.progress-bar>div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); width: 0%; transition: width .2s; }

/* ---------- Editor ---------- */
.editor-shell { max-width: 520px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; background: #000; }
.editor-preview {
  position: relative; width: 100%; aspect-ratio: 9/16; background: #000; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.editor-preview video, .editor-preview canvas { width: 100%; height: 100%; object-fit: contain; position: absolute; inset: 0; }
.caption-overlay {
  position: absolute; left: 6%; right: 6%; text-align: center;
  pointer-events: none; line-height: 1.25; word-break: break-word;
}

/* Editor tabs horizontal scroll fix */
.editor-tabs {
  display: flex; background: var(--bg-elev); border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none; /* Firefox */
}
.editor-tabs::-webkit-scrollbar { display: none; } /* Chrome, Safari */
.editor-tabs button {
  flex: none; padding: 12px 16px; background: none; border: none; color: var(--text-dim);
  font-weight: 700; font-size: 13px; border-bottom: 2px solid transparent; cursor: pointer;
}
.editor-tabs button.active { color: var(--accent); border-color: var(--accent); }
.editor-panel { flex: 1; overflow-y: auto; background: var(--bg); padding: 14px; padding-bottom: 100px; }

.caption-line {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 8px;
}
.caption-line .time { font-size: 11px; color: var(--text-dim); margin-bottom: 4px; display: flex; justify-content: space-between; }
.caption-line textarea {
  width: 100%; background: transparent; border: none; color: var(--text);
  font-size: 14px; resize: none; outline: none; min-height: 36px;
}
.caption-line.active { border-color: var(--accent); }

.style-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.style-swatch {
  border-radius: 12px; background: #111; border: 2px solid var(--border);
  aspect-ratio: 9/12; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 6px; font-size: 12px; cursor: pointer; overflow: hidden;
}
.style-swatch.selected { border-color: var(--accent); }
.style-swatch span { -webkit-text-stroke: 0.5px #000; }

.slider-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.slider-row label { width: 70px; font-size: 13px; color: var(--text-dim); flex: none; }
.slider-row input[type=range] { flex: 1; }
.color-row { display: flex; gap: 8px; flex-wrap: wrap; }
.color-dot { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--border); cursor: pointer; }
.color-dot.selected { border-color: var(--accent); }

.editor-bottombar {
  position: sticky; bottom: 0; background: var(--bg-elev); border-top: 1px solid var(--border);
  padding: 10px 14px; padding-bottom: calc(10px + var(--safe-bottom)); display: flex; gap: 10px;
}

/* ---------- Admin ---------- */
.admin-shell { display: flex; min-height: 100vh; }
.admin-sidebar {
  width: 220px; flex: none; background: var(--bg-elev); border-right: 1px solid var(--border);
  padding: 18px 12px;
}
.admin-sidebar .brand { font-weight: 800; font-size: 18px; margin-bottom: 22px; padding: 0 8px; }
.admin-sidebar a {
  display: flex; align-items: center; gap: 10px; padding: 11px 10px; border-radius: 10px;
  color: var(--text-dim); font-size: 14px; font-weight: 600; margin-bottom: 4px;
}
.admin-sidebar a.active, .admin-sidebar a:hover { background: var(--bg-elev-2); color: var(--text); }
.admin-main { flex: 1; padding: 22px; max-width: 1000px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 16px; }
.stat-card .num { font-size: 26px; font-weight: 800; }
.stat-card .lbl { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

/* Fixed Table Border Radius Bug */
table.admin-table { 
  width: 100%; 
  border-collapse: separate; 
  border-spacing: 0; 
  background: var(--card); 
  border: 1px solid var(--border); 
  border-radius: 12px; 
  overflow: hidden; 
}
table.admin-table th, table.admin-table td { padding: 10px 12px; text-align: left; font-size: 13px; border-bottom: 1px solid var(--border); }
table.admin-table th { color: var(--text-dim); font-weight: 700; background: var(--bg-elev-2); }
table.admin-table tr:last-child td { border-bottom: none; } /* Clean up last border */
.pill { padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.pill.active { background: rgba(0, 229, 160, 0.15); color: var(--accent-2); }
.pill.blocked { background: rgba(255, 77, 79, 0.15); color: #ff8a8c; }

@media (max-width: 720px) {
  .admin-shell { flex-direction: column; }
  .admin-sidebar { 
    width: 100%; display: flex; overflow-x: auto; 
    border-right: none; border-bottom: 1px solid var(--border); padding: 10px;
    scrollbar-width: none; 
  }
  .admin-sidebar::-webkit-scrollbar { display: none; }
  .admin-sidebar .brand { display: none; }
  .admin-sidebar a { white-space: nowrap; margin-bottom: 0; flex-shrink: 0; } /* Prevent link squashing */
  .admin-main { padding: 14px; }
}

.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.25); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { text-align: center; padding: 50px 20px; color: var(--text-dim); }