/* ==========================================================================
   Tohi reje — sleek, restrained, animated
   Dual theme (dark / light), low-bandwidth friendly, no external CSS
   ========================================================================== */

:root {
  --bg: #0b1020;
  --bg-elev: #121933;
  --bg-elev-2: #1a2247;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-strong: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8ecf8;
  --text-muted: #9aa3bf;
  --text-faint: #6b7390;
  --primary: #6366f1;
  --primary-2: #22d3ee;
  --primary-soft: rgba(99, 102, 241, 0.18);
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --radius-sm: 10px;
  --header-h: 60px;
  --tap: 44px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

[data-theme="light"] {
  --bg: #f5f7fb;
  --bg-elev: #ffffff;
  --bg-elev-2: #ffffff;
  --surface: rgba(15, 23, 42, 0.04);
  --surface-strong: rgba(15, 23, 42, 0.08);
  --border: rgba(15, 23, 42, 0.10);
  --text: #0f172a;
  --text-muted: #475569;
  --text-faint: #94a3b8;
  --primary: #4f46e5;
  --primary-2: #0891b2;
  --primary-soft: rgba(79, 70, 229, 0.10);
  --shadow: 0 10px 25px rgba(15, 23, 42, 0.10);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: contain;
}

body {
  background:
    radial-gradient(circle at 10% -10%, rgba(99,102,241,.18), transparent 40%),
    radial-gradient(circle at 110% 0%, rgba(34,211,238,.14), transparent 45%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  transition: background-color .3s var(--ease), color .3s var(--ease);
}
[data-theme="light"] body {
  background:
    radial-gradient(circle at 10% -10%, rgba(79,70,229,.10), transparent 40%),
    radial-gradient(circle at 110% 0%, rgba(8,145,178,.08), transparent 45%),
    var(--bg);
  background-attachment: fixed;
}

img { max-width: 100%; display: block; }
button { font: inherit; cursor: pointer; }
a { color: var(--primary-2); text-decoration: none; }

/* ============================ Splash ============================ */
.splash {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; z-index: 5000;
  background: var(--bg);
  animation: splashOut .5s var(--ease) 1.4s forwards;
}
.splash-logo svg { animation: pop .6s var(--ease) both; }
.splash-title { font-weight: 700; font-size: 22px; letter-spacing: .3px; opacity: 0; animation: fadeUp .5s var(--ease) .2s forwards; }
.splash-loader { display: flex; gap: 6px; }
.splash-loader span {
  width: 8px; height: 8px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  animation: bounce 1.2s var(--ease) infinite;
}
.splash-loader span:nth-child(2) { animation-delay: .15s; }
.splash-loader span:nth-child(3) { animation-delay: .3s; }
@keyframes splashOut { to { opacity: 0; visibility: hidden; pointer-events: none; } }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fadeUp { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes bounce { 0%,100% { transform: translateY(0); opacity: .6; } 50% { transform: translateY(-7px); opacity: 1; } }

/* ============================ Header ============================ */
.header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  background: color-mix(in oklab, var(--bg) 75%, transparent);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 17px; letter-spacing: .2px;
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  display: grid; place-items: center; color: white;
  box-shadow: 0 6px 16px rgba(99,102,241,.35);
}
.header-actions { display: flex; gap: 6px; align-items: center; }

.icon-btn {
  width: var(--tap); height: var(--tap);
  border-radius: 12px; border: 1px solid transparent;
  background: var(--surface); color: var(--text);
  display: grid; place-items: center;
  transition: transform .2s var(--ease), background .2s var(--ease), border-color .2s var(--ease);
}
.icon-btn:hover { background: var(--surface-strong); border-color: var(--border); }
.icon-btn:active { transform: scale(.94); }

.lang-switch {
  display: flex; gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 3px; border-radius: 12px;
}
.lang-switch button {
  border: none; background: transparent; color: var(--text-muted);
  padding: 6px 10px; border-radius: 9px; font-weight: 600; font-size: 12px;
  letter-spacing: .5px; text-transform: uppercase;
  transition: background .2s var(--ease), color .2s var(--ease);
}
.lang-switch button.is-active {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white;
}

/* ============================ Layout ============================ */
.container {
  max-width: 980px; margin: 0 auto;
  padding: 16px 16px 100px;
}

.page-title {
  font-size: 24px; font-weight: 700;
  margin: 8px 0 4px;
  background: linear-gradient(135deg, var(--text), var(--primary-2));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.page-sub { color: var(--text-muted); margin-bottom: 18px; font-size: 14px; }

/* ============================ Cards / List ============================ */
.toolbar {
  display: flex; gap: 10px; align-items: center;
  margin-bottom: 14px; flex-wrap: wrap;
}
.search {
  flex: 1; min-width: 200px;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 14px;
  transition: border-color .2s var(--ease), background .2s var(--ease);
}
.search:focus-within { border-color: var(--primary); background: var(--surface-strong); }
.search input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); font-size: 15px;
}
.search input::placeholder { color: var(--text-faint); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.card {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform .25s var(--ease), box-shadow .25s var(--ease), border-color .2s var(--ease);
  animation: cardIn .45s var(--ease) both;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--primary-soft); }
.card-img-wrap {
  position: relative;
  aspect-ratio: 16 / 10;
  background:
    linear-gradient(120deg, var(--surface) 25%, var(--surface-strong) 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.6s linear infinite;
}
.card-img-wrap.loaded { animation: none; background: var(--surface); }
.card-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity .4s var(--ease);
}
.card-img.loaded { opacity: 1; }
.card-body { padding: 12px 14px 14px; }
.card-title { font-weight: 600; font-size: 15px; margin: 0 0 4px; }
.card-desc { font-size: 13px; color: var(--text-muted); margin: 0; min-height: 1.2em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { display: flex; gap: 8px; margin-top: 10px; align-items: center; font-size: 12px; color: var(--text-faint); }
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary-2);
  font-size: 11px; font-weight: 600; letter-spacing: .3px;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* Empty state */
.empty {
  text-align: center; padding: 60px 20px; color: var(--text-muted);
}
.empty svg { opacity: .55; margin-bottom: 10px; }
.empty h3 { margin: 0 0 4px; color: var(--text); font-weight: 600; }

/* ============================ Modal viewer ============================ */
.modal {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0, 0, 0, .82);
  display: none; align-items: center; justify-content: center;
  animation: fadeIn .25s var(--ease);
  padding: 16px;
}
.modal.is-open { display: flex; }
.modal-content {
  position: relative; width: 100%; max-width: 1100px; max-height: 92vh;
  display: flex; flex-direction: column;
  animation: zoomIn .35s var(--ease);
}
.modal-img-wrap {
  flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: auto;
  border-radius: var(--radius);
  background: rgba(255,255,255,.03);
}
.modal-img {
  max-width: 100%; max-height: 86vh; object-fit: contain;
  border-radius: 8px;
  user-select: none; -webkit-user-drag: none;
  cursor: zoom-in;
  transition: transform .25s var(--ease);
}
.modal-img.zoomed { cursor: zoom-out; transform: scale(1.8); }
.modal-bar {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 10px; padding: 0 4px;
}
.modal-title { color: white; font-weight: 600; font-size: 16px; }
.modal-close {
  position: absolute; top: -10px; right: -10px;
  width: 40px; height: 40px; border-radius: 50%;
  background: white; color: #0f172a; border: none;
  display: grid; place-items: center;
  box-shadow: 0 8px 22px rgba(0,0,0,.35);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes zoomIn { from { transform: scale(.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ============================ Buttons ============================ */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 42px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font-weight: 600; font-size: 14px;
  transition: transform .15s var(--ease), background .2s var(--ease), border-color .2s var(--ease);
}
.btn:hover { background: var(--surface-strong); }
.btn:active { transform: scale(.97); }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white; border-color: transparent;
  box-shadow: 0 8px 20px rgba(99,102,241,.30);
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-danger { background: rgba(239, 68, 68, .12); color: var(--danger); border-color: rgba(239,68,68,.30); }
.btn-danger:hover { background: rgba(239, 68, 68, .20); }
.btn-block { width: 100%; justify-content: center; }
.btn-ghost { background: transparent; }

/* ============================ Forms ============================ */
.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--text-muted); margin-bottom: 6px;
}
.input, .textarea, .select {
  width: 100%; padding: 12px 14px;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font-size: 15px; outline: none;
  transition: border-color .2s var(--ease), background .2s var(--ease);
}
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--primary); background: var(--surface-strong);
}
.textarea { resize: vertical; min-height: 80px; font-family: inherit; }

.file-drop {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 26px 14px; text-align: center;
  background: var(--surface); color: var(--text-muted);
  transition: border-color .2s var(--ease), background .2s var(--ease);
  cursor: pointer;
}
.file-drop:hover, .file-drop.is-drag { border-color: var(--primary); background: var(--primary-soft); color: var(--text); }
.file-drop input { display: none; }
.file-drop .preview-img {
  max-height: 220px; margin: 10px auto 0; border-radius: 10px; box-shadow: var(--shadow);
}

/* ============================ Sheet (mobile bottom sheet) ============================ */
.sheet {
  position: fixed; inset: 0; z-index: 1200; display: none;
  background: rgba(0,0,0,.55);
  animation: fadeIn .2s var(--ease);
}
.sheet.is-open { display: block; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--bg-elev);
  border-top-left-radius: 22px; border-top-right-radius: 22px;
  padding: 18px 18px 28px;
  max-height: 92vh; overflow-y: auto;
  animation: slideUp .35s var(--ease);
  box-shadow: 0 -10px 30px rgba(0,0,0,.35);
}
.sheet-handle {
  width: 42px; height: 4px; border-radius: 4px; background: var(--border);
  margin: 0 auto 14px;
}
.sheet h2 { margin: 0 0 14px; font-size: 18px; font-weight: 700; }
@keyframes slideUp { from { transform: translateY(12%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ============================ Toasts ============================ */
.toasts {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0) + 24px);
  transform: translateX(-50%); z-index: 2000;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 16px; min-width: 220px; max-width: 90vw;
  display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow);
  animation: toastIn .35s var(--ease);
  pointer-events: auto;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--primary); }
@keyframes toastIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ============================ Notifications popup ============================ */
.notify-pop {
  position: fixed; top: calc(var(--header-h) + 10px); right: 12px; z-index: 1500;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  padding: 12px 14px; border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex; align-items: flex-start; gap: 10px;
  max-width: calc(100vw - 24px); width: 320px;
  animation: notifyIn .45s var(--ease);
}
.notify-pop .ic {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center; color: white;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
}
.notify-pop strong { display: block; font-size: 14px; margin-bottom: 2px; }
.notify-pop p { margin: 0; font-size: 13px; color: var(--text-muted); }
@keyframes notifyIn { from { transform: translate(20px, -10px); opacity: 0; } to { transform: translate(0,0); opacity: 1; } }

/* ============================ Connection bar ============================ */
.conn {
  position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: var(--bg-elev-2); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 999px; font-size: 12px; color: var(--text-muted);
  display: none; align-items: center; gap: 8px; z-index: 90;
  box-shadow: var(--shadow);
}
.conn.show { display: inline-flex; }
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); animation: pulse 1.4s infinite; }
.conn.offline .dot { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .4; transform: scale(1.3); } }

/* ============================ FAB ============================ */
.fab {
  position: fixed; right: 18px; bottom: calc(env(safe-area-inset-bottom, 0) + 18px);
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white; border: none;
  display: grid; place-items: center;
  box-shadow: 0 12px 28px rgba(99,102,241,.45);
  z-index: 80;
  transition: transform .2s var(--ease);
}
.fab:hover { transform: scale(1.05); }
.fab:active { transform: scale(.94); }

/* ============================ Admin list rows ============================ */
.row {
  display: flex; gap: 12px; align-items: center;
  padding: 10px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px;
  margin-bottom: 8px;
}
.row-thumb { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; flex-shrink: 0; background: var(--surface-strong); }
.row-info { flex: 1; min-width: 0; }
.row-info strong { display: block; font-size: 14px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-info span { font-size: 12px; color: var(--text-muted); }
.row-actions { display: flex; gap: 6px; }

/* ============================ Auth form ============================ */
.auth-card {
  max-width: 380px; margin: 60px auto;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 22px;
  box-shadow: var(--shadow);
  animation: zoomIn .35s var(--ease);
}
.auth-card h2 { margin: 0 0 6px; font-size: 22px; }
.auth-card p { margin: 0 0 20px; color: var(--text-muted); font-size: 14px; }

/* Mobile tweaks */
@media (max-width: 640px) {
  .header { padding: 0 12px; }
  .brand { font-size: 16px; }
  .container { padding: 12px 12px 110px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  .card-body { padding: 10px 12px 12px; }
  .card-title { font-size: 13.5px; }
  .card-desc { font-size: 12px; }
  .lang-switch button { padding: 5px 7px; font-size: 11px; }
  .page-title { font-size: 20px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
