/* =========================================================
   Subtitle Manager — Admin Design System v2
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg: #f4f5fa;
  --surface: #ffffff;
  --surface-2: #fafbfe;
  --border: #e6e8f0;
  --border-strong: #d7dae6;
  --text: #1a1d29;
  --text-muted: #6b7185;
  --text-faint: #9aa0b4;
  --accent: #6a5cf5;
  --accent-hover: #5847e8;
  --accent-light: #efedff;
  --accent-text: #4b3ce0;
  --success: #16a34a;
  --success-light: #e9f9ee;
  --danger: #e0324c;
  --danger-light: #fdecef;
  --warning: #d97a12;
  --warning-light: #fef3e2;
  --info: #0d8fce;
  --info-light: #e6f6fd;
  --sidebar-bg: #16182b;
  --sidebar-bg-2: #1d2038;
  --sidebar-text: #b7b9d6;
  --sidebar-border: #262a45;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(20,20,43,0.05);
  --shadow: 0 4px 16px rgba(20,20,43,0.06);
  --shadow-lg: 0 12px 32px rgba(20,20,43,0.12);
  --sidebar-w: 260px;
  --topbar-h: 68px;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0d1a;
    --surface: #14141f;
    --surface-2: #1a1a2e;
    --border: #2a2a45;
    --border-strong: #3a3a55;
    --text: #e8e8f0;
    --text-muted: #9a9dc2;
    --text-faint: #6b7185;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow: 0 4px 16px rgba(0,0,0,0.4);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.5);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s ease;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface-2); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

a { color: inherit; text-decoration: none; }
code, .mono { font-family: 'JetBrains Mono', monospace; }

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: linear-gradient(185deg, var(--sidebar-bg), var(--sidebar-bg-2));
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 22px 18px;
  border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-brand .mark {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--accent), #9b8cff);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 17px;
  flex: none;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.sidebar-brand .name { color: #fff; font-size: 15px; font-weight: 700; line-height: 1.2; }
.sidebar-brand .tag { color: var(--text-faint); font-size: 11.5px; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
}
.sidebar-group-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #5c5f80;
  padding: 14px 10px 6px;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 2px;
  color: var(--sidebar-text);
  font-size: 13.6px;
  font-weight: 500;
  transition: var(--transition);
  position: relative;
}
.sidebar-link i { font-size: 16px; width: 18px; text-align: center; flex: none; opacity: 0.85; }
.sidebar-link:hover { background: rgba(255,255,255,0.06); color: #fff; transform: translateX(4px); }
.sidebar-link.active {
  background: rgba(106,92,245,0.18);
  color: #fff;
}
.sidebar-link.active i { opacity: 1; color: #a99bff; }
.sidebar-link.active::before {
  content: "";
  position: absolute; left: -12px; top: 8px; bottom: 8px;
  width: 3px; border-radius: 3px;
  background: var(--accent);
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from { height: 0; opacity: 0; }
  to { height: calc(100% - 16px); opacity: 1; }
}

.sidebar-user {
  padding: 14px;
  margin: 10px 12px 14px;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.05);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-user .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, #9b8cff, var(--accent));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex: none;
}
.sidebar-user .who { min-width: 0; flex: 1; }
.sidebar-user .name { color: #fff; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .role { font-size: 11px; color: var(--text-faint); text-transform: capitalize; }
.sidebar-user .logout-btn {
  flex: none; width: 30px; height: 30px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--sidebar-text); transition: var(--transition);
}
.sidebar-user .logout-btn:hover { background: rgba(224,50,76,0.18); color: #ff8fa1; transform: scale(1.1); }

.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(10,10,20,0.5);
  z-index: 99;
  backdrop-filter: blur(4px);
}

/* Main */
.main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 26px;
  position: sticky;
  top: 0;
  z-index: 40;
  gap: 16px;
  backdrop-filter: blur(10px);
}
.topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.topbar-title { font-size: 18px; font-weight: 700; }
.topbar-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 1px; }
.sidebar-toggle {
  display: none;
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  align-items: center; justify-content: center; font-size: 16px; color: var(--text);
  flex: none;
  cursor: pointer;
  transition: var(--transition);
}
.sidebar-toggle:hover { background: var(--surface-2); border-color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 10px; flex: none; }

.content { 
  padding: 26px; 
  max-width: 1400px; 
  width: 100%; 
  margin: 0 auto;
  animation: fadeInUp 0.4s ease;
}

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

/* Grid */
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-sidebar { grid-template-columns: 340px 1fr; align-items: start; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-sidebar { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.card:hover { box-shadow: var(--shadow); }
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-header h2, .card-header h3 { font-size: 15px; display: flex; align-items: center; gap: 8px; }
.card-body { padding: 20px; }
.card-body.pad-0 { padding: 0; }

/* Stat Cards */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  transition: var(--transition);
}
.stat-card:hover { 
  transform: translateY(-4px); 
  box-shadow: var(--shadow);
  border-color: var(--accent);
}
.stat-card .num { 
  font-size: 26px; 
  font-weight: 800; 
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent), #9b8cff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.stat-card .lbl { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; font-weight: 500; }
.stat-card .ico {
  width: 42px; height: 42px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; flex: none;
  transition: var(--transition);
}
.stat-card:hover .ico { transform: scale(1.1) rotate(-5deg); }
.ico-violet { background: var(--accent-light); color: var(--accent-text); }
.ico-green  { background: var(--success-light); color: var(--success); }
.ico-red    { background: var(--danger-light); color: var(--danger); }
.ico-amber  { background: var(--warning-light); color: var(--warning); }
.ico-blue   { background: var(--info-light); color: var(--info); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.3px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  line-height: 1.2;
}
.btn i { font-size: 14.5px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(106,92,245,0.3); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); transform: translateY(-1px); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(0.93); transform: translateY(-1px); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.93); transform: translateY(-1px); }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { filter: brightness(0.93); transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); transform: translateY(-1px); }
.btn-sm { padding: 6px 11px; font-size: 12.2px; border-radius: 7px; }
.btn-xs { padding: 4px 9px; font-size: 11.5px; border-radius: 6px; }
.btn-block { width: 100%; }
.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.btn-stack { display: flex; flex-direction: column; gap: 6px; }

/* Forms */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 12.6px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.field .hint { font-size: 11.8px; color: var(--text-faint); margin-top: 5px; }
.field .required { color: var(--danger); }

.control {
  width: 100%;
  padding: 10px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13.6px;
  font-family: inherit;
  transition: var(--transition);
}
.control:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 4px rgba(106,92,245,0.1);
}
select.control { cursor: pointer; }
textarea.control { resize: vertical; min-height: 90px; }

.row-fields { display: grid; gap: 14px; }
.row-2 { grid-template-columns: 1fr 1fr; }
.row-3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 700px) { .row-2, .row-3 { grid-template-columns: 1fr; } }

/* Switch */
.switch { display: flex; align-items: center; gap: 10px; }
.switch input { display: none; }
.switch .track {
  width: 40px; height: 22px; border-radius: 20px; background: var(--border-strong);
  position: relative; transition: var(--transition); flex: none; cursor: pointer;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: var(--shadow-sm); transition: var(--transition);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch .switch-label { font-size: 13.3px; font-weight: 500; cursor: pointer; }

/* Dropzone */
.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 30px 18px;
  text-align: center;
  cursor: pointer;
  background: var(--surface-2);
  transition: var(--transition);
}
.dropzone:hover { border-color: var(--accent); background: var(--accent-light); transform: scale(1.01); }
.dropzone i { font-size: 30px; color: var(--text-faint); transition: var(--transition); }
.dropzone:hover i { color: var(--accent); transform: translateY(-4px); }
.dropzone p { margin-top: 8px; font-size: 13px; font-weight: 600; }
.dropzone small { color: var(--text-muted); }
.dropzone .picked { margin-top: 8px; font-size: 12.5px; color: var(--accent-text); font-weight: 600; }

/* Table */
.table-wrap { 
  overflow-x: auto; 
  position: relative;
}
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.3px; }
table.tbl th {
  text-align: left; padding: 11px 14px; font-size: 11.3px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted);
  border-bottom: 1.5px solid var(--border); white-space: nowrap;
  position: sticky; top: 0; background: var(--surface);
}
table.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tbody tr { transition: var(--transition); }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl tbody tr:last-child td { border-bottom: none; }

/* Pills */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.01em;
  transition: var(--transition);
}
.pill:hover { transform: scale(1.05); }
.pill-green  { background: var(--success-light); color: var(--success); }
.pill-red    { background: var(--danger-light); color: var(--danger); }
.pill-amber  { background: var(--warning-light); color: var(--warning); }
.pill-blue   { background: var(--info-light); color: var(--info); }
.pill-violet { background: var(--accent-light); color: var(--accent-text); }
.pill-gray   { background: #eef0f5; color: var(--text-muted); }

/* Alerts */
.alert {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 13px 16px; border-radius: var(--radius);
  font-size: 13.4px; margin-bottom: 18px; border: 1px solid transparent;
  animation: slideDown 0.3s ease;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}
.alert i { font-size: 16px; margin-top: 1px; }
.alert-success { background: var(--success-light); color: #0d7a37; border-color: #c8ecd6; }
.alert-danger  { background: var(--danger-light); color: #b8233a; border-color: #f6c9d1; }
.alert-info    { background: var(--info-light); color: #0a6c9c; border-color: #c3e8f7; }
.alert .close-alert { margin-left: auto; cursor: pointer; opacity: 0.6; transition: var(--transition); }
.alert .close-alert:hover { opacity: 1; transform: scale(1.2); }

#toast-stack {
  position: fixed; bottom: 22px; right: 22px; z-index: 999;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-end;
}
.toast {
  background: var(--text); color: #fff;
  padding: 12px 18px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 9px;
  animation: toastIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  max-width: 360px;
}
.toast.success { background: #0f7a3d; }
.toast.danger { background: #c0273f; }
@keyframes toastIn { from { transform: translateY(20px) scale(0.95); opacity: 0; } to { transform: translateY(0) scale(1); opacity: 1; } }
@keyframes toastOut { from { transform: translateY(0) scale(1); opacity: 1; } to { transform: translateY(20px) scale(0.95); opacity: 0; } }

/* Confirm Dialog */
.confirm-overlay {
  position: fixed; inset: 0; background: rgba(15,15,25,0.6);
  display: none; align-items: center; justify-content: center; z-index: 998;
  backdrop-filter: blur(4px);
}
.confirm-overlay.open { display: flex; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.confirm-box {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 24px; width: 360px; box-shadow: var(--shadow-lg);
  animation: scaleIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes scaleIn { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.confirm-box .ic { width: 42px; height: 42px; border-radius: 12px; background: var(--danger-light); color: var(--danger); display: flex; align-items: center; justify-content: center; font-size: 20px; margin-bottom: 12px; }
.confirm-box h4 { font-size: 15px; margin-bottom: 6px; }
.confirm-box p { font-size: 13px; color: var(--text-muted); margin-bottom: 18px; }
.confirm-box .actions { display: flex; gap: 8px; justify-content: flex-end; }

/* Collapse */
.collapse-panel { display: none; }
.collapse-panel.open { display: block; animation: slideDown 0.3s ease; }

/* Empty State */
.empty {
  text-align: center; padding: 50px 20px; color: var(--text-muted);
}
.empty i { font-size: 38px; color: var(--text-faint); margin-bottom: 10px; display: block; transition: var(--transition); }
.empty:hover i { transform: scale(1.1) rotate(-5deg); color: var(--accent); }
.empty p { font-size: 13.5px; margin-top: 4px; }

/* Search Box */
.search-box { position: relative; }
.search-box i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-faint); font-size: 14px; }
.search-box .control { padding-left: 34px; }

/* Progress */
.progress-track { background: #eef0f5; border-radius: 20px; height: 8px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #9b8cff); border-radius: 20px; transition: width 0.6s ease; }

/* Skeleton loading */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }

/* Responsive */
@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .main { margin-left: 0; }
  .sidebar-toggle { display: flex; }
  .content { padding: 18px; }
  .topbar { padding: 0 16px; }
}