:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 14px;
  --tabbar-h: 62px;
  color-scheme: light dark;
}

/* Thuộc tính `hidden` phải thắng mọi rule display khác (ví dụ .login-view{display:grid}),
   nếu không form đăng nhập sẽ nằm đè lên dashboard sau khi đăng nhập. */
[hidden] {
  display: none !important;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #111a2b;
    --surface-2: #16213a;
    --text: #e8eefb;
    --muted: #93a3bd;
    --border: #22304d;
    --primary: #3b82f6;
    --danger: #f87171;
    --ok: #4ade80;
    --warn: #fbbf24;
  }
}

* { 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, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1.05rem; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hint { color: var(--muted); font-size: 0.8rem; margin: 0; }
.error { color: var(--danger); font-size: 0.9rem; }
.ok { color: var(--ok); font-size: 0.9rem; }
.warn { color: var(--warn); font-size: 0.88rem; }

/* ---------------- Đăng nhập ---------------- */
.login-view {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 22px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.12);
}
.brand { text-align: center; margin-bottom: 20px; display: grid; gap: 6px; justify-items: center; }
.brand img { border-radius: 16px; }

/* ---------------- Khung app ---------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

#main {
  padding: 14px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 18px);
  max-width: 720px;
  margin: 0 auto;
}

/* ---------------- Điều khiển ---------------- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 11px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.06s ease, background 0.15s ease, opacity 0.15s;
  min-height: 44px;
}
.btn:active { transform: scale(0.975); }
.btn:disabled { opacity: 0.5; }
.btn.primary { background: var(--primary); border-color: transparent; color: var(--primary-text); }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 12px; min-height: 36px; font-size: 0.85rem; }
.btn.big { width: 100%; padding: 15px; font-size: 1rem; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }

input, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 13px;
  margin-top: 6px;
}
input:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 55%, transparent); outline-offset: 1px; }
textarea { resize: vertical; }
input[type="range"] { padding: 0; background: none; border: none; accent-color: var(--primary); }
input[type="checkbox"] { width: 26px; height: 26px; accent-color: var(--primary); margin: 0; }

label { display: block; font-size: 0.92rem; font-weight: 550; }
label.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.stack { display: grid; gap: 14px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
.row .btn { flex: 1; }

/* ---------------- Toolbar / chip ---------------- */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.85rem;
  white-space: nowrap;
  cursor: pointer;
}
.chip.active { background: var(--primary); color: var(--primary-text); border-color: transparent; }

.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 12px; }
.progress .bar { height: 100%; width: 0; background: var(--primary); transition: width 0.2s ease; }

/* ---------------- Lưới ảnh ---------------- */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }

.photo-card {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
  aspect-ratio: 1 / 1;
  border: 1px solid var(--border);
}
.photo-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-card .badge {
  position: absolute;
  left: 8px;
  bottom: 8px;
  font-size: 0.72rem;
  font-weight: 650;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.78);
  color: #fff;
  backdrop-filter: blur(6px);
}
.photo-card .del {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(15, 23, 42, 0.68);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.badge.st-pending { background: rgba(100, 116, 139, 0.9); }
.badge.st-captioned { background: rgba(217, 119, 6, 0.92); }
.badge.st-approved { background: rgba(37, 99, 235, 0.92); }
.badge.st-scheduled { background: rgba(79, 70, 229, 0.92); }
.badge.st-posted { background: rgba(22, 163, 74, 0.92); }
.badge.st-failed { background: rgba(220, 38, 38, 0.92); }
.badge.st-skipped { background: rgba(71, 85, 105, 0.9); }

/* ---------------- Danh sách ---------------- */
.list { display: grid; gap: 10px; }
.item {
  display: grid;
  grid-template-columns: 68px 1fr;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
}
.item img, .item .thumb-placeholder {
  width: 68px;
  height: 68px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--surface-2);
}
.item .body { min-width: 0; display: grid; gap: 4px; align-content: start; }
.item .caption {
  font-size: 0.9rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
}
.item .meta { font-size: 0.78rem; color: var(--muted); }
.item .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.item a { color: var(--primary); }

.empty { text-align: center; color: var(--muted); padding: 34px 10px; font-size: 0.92rem; }
.section-title { margin: 18px 0 10px; color: var(--muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.06em; }

/* ---------------- Tabbar ---------------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--border);
  z-index: 30;
}
.tabbar button {
  appearance: none;
  border: none;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  display: grid;
  gap: 2px;
  place-items: center;
  padding: 6px 0;
  cursor: pointer;
}
.tabbar button.active { color: var(--primary); }
.tabbar .ico { font-size: 1.15rem; line-height: 1; }

/* ---------------- Modal ---------------- */
dialog.sheet {
  width: min(560px, 100%);
  max-height: 92dvh;
  margin: auto auto 0;
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  color: var(--text);
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  position: fixed;
  inset: auto 0 0 0;
}
dialog.sheet::backdrop { background: rgba(2, 6, 23, 0.55); backdrop-filter: blur(2px); }
.edit-thumb { width: 100%; max-height: 190px; object-fit: cover; border-radius: 12px; background: var(--surface-2); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.94);
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  max-width: 88vw;
  text-align: center;
  z-index: 50;
}
