/* ============================================================
   TANSINH Tasks — Warm Refined Dashboard
   ============================================================ */

:root {
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;

  --teal-50: #f0fdfa; --teal-100: #ccfbf1; --teal-200: #99f6e4;
  --teal-400: #2dd4bf; --teal-500: #14b8a6; --teal-600: #0d9488; --teal-700: #0f766e;

  --amber-50: #fffbeb; --amber-100: #fef3c7; --amber-500: #f59e0b; --amber-700: #b45309;
  --rose-50: #fff1f2; --rose-100: #ffe4e6; --rose-500: #f43f5e; --rose-700: #be123c;
  --sky-50: #f0f9ff; --sky-100: #e0f2fe; --sky-500: #0ea5e9; --sky-700: #0369a1;
  --emerald-500: #10b981; --emerald-600: #059669;
  --violet-50: #f5f3ff; --violet-100: #ede9fe; --violet-700: #6d28d9;
  --green-50: #f0fdf4; --green-100: #dcfce7; --green-700: #15803d;

  --bg: #f5f6fa;
  --surface: #ffffff;
  --accent: var(--teal-600);
  --accent-hover: var(--teal-700);
  --accent-light: var(--teal-50);
  --text: var(--slate-800);
  --text-soft: var(--slate-500);
  --border: var(--slate-200);
  --danger: var(--rose-500);

  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 7px;
  --shadow-sm: 0 1px 3px rgba(15,23,42,0.04);
  --shadow-md: 0 4px 16px rgba(15,23,42,0.07);
  --shadow-lg: 0 12px 40px rgba(15,23,42,0.1);
  --transition: 0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  min-height: 100svh;
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ======================== LOGIN ======================== */

.login-wrapper {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(20,184,166,0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(14,165,233,0.06) 0%, transparent 50%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 20px;
  padding: 40px 32px 36px;
  box-shadow: var(--shadow-lg);
  animation: cardIn 0.5s ease both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }

.brand-icon {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, var(--teal-500), var(--teal-700));
  color: #fff; display: grid; place-items: center; font-size: 1rem;
  box-shadow: 0 4px 12px rgba(13,148,136,0.25);
}

.brand-text { font-size: 1.15rem; font-weight: 700; color: var(--slate-800); letter-spacing: -0.02em; }

.login-title {
  font-family: 'Instrument Serif', serif;
  font-size: 1.7rem; font-weight: 400; color: var(--slate-900); margin-bottom: 4px;
}
.login-subtitle { font-size: 0.9rem; color: var(--text-soft); margin-bottom: 28px; }

.input-group { margin-bottom: 18px; }
.input-group label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--slate-600); margin-bottom: 6px; }

.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap > i:first-child { position: absolute; left: 14px; color: var(--slate-400); font-size: 0.85rem; pointer-events: none; }
.input-wrap input {
  width: 100%; padding: 12px 14px 12px 40px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-family: inherit; font-size: 0.92rem; background: var(--slate-50);
  color: var(--text); outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.input-wrap input:focus {
  border-color: var(--accent); background: #fff;
  box-shadow: 0 0 0 4px rgba(13,148,136,0.1);
}

.pwd-toggle {
  position: absolute; right: 10px; background: none; border: none;
  color: var(--slate-400); cursor: pointer; padding: 4px 6px; border-radius: 6px;
  font-size: 0.85rem; transition: color var(--transition);
}
.pwd-toggle:hover { color: var(--accent); }

.login-btn {
  width: 100%; padding: 13px; margin-top: 8px; border: none; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--teal-500), var(--teal-700));
  color: #fff; font-family: inherit; font-size: 0.95rem; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 4px 14px rgba(13,148,136,0.3);
  transition: transform 0.1s ease, box-shadow var(--transition);
}
.login-btn:hover { box-shadow: 0 6px 20px rgba(13,148,136,0.35); }
.login-btn:active { transform: translateY(1px); }

.login-msg { margin-top: 14px; font-size: 0.88rem; font-weight: 500; text-align: center; min-height: 1.3em; }
.login-msg.error { color: var(--danger); }

/* ======================== APP SHELL ======================== */

.app { min-height: 100svh; display: flex; flex-direction: column; }

.topbar {
  height: 56px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  position: sticky; top: 0; z-index: 200; box-shadow: var(--shadow-sm);
}
.topbar-brand { font-size: 1rem; font-weight: 700; color: var(--accent); display: flex; align-items: center; gap: 8px; }
.topbar-brand i { font-size: 0.95rem; }

.topbar-logout {
  width: 34px; height: 34px; border: 1.5px solid var(--border); border-radius: 9px;
  background: transparent; color: var(--slate-500); cursor: pointer;
  display: grid; place-items: center; font-size: 0.88rem; transition: all var(--transition);
}
.topbar-logout:hover { border-color: var(--danger); color: var(--danger); background: var(--rose-50); }

.dashboard { flex: 1; max-width: 1140px; width: 100%; margin: 0 auto; padding: 24px 20px 40px; }

/* ======================== STATS ======================== */

.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }

.stat-card {
  background: var(--surface); border-radius: var(--radius); padding: 18px 20px;
  display: flex; align-items: center; gap: 14px;
  box-shadow: var(--shadow-sm); border: 1px solid var(--border);
  animation: cardIn 0.4s ease both;
}
.stat-card:nth-child(2) { animation-delay: 0.05s; }
.stat-card:nth-child(3) { animation-delay: 0.1s; }
.stat-card:nth-child(4) { animation-delay: 0.15s; }

.stat-icon {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center; font-size: 1.05rem; flex-shrink: 0;
}
.ic-teachers   { background: var(--sky-50); color: var(--sky-700); }
.ic-admins     { background: var(--amber-50); color: var(--amber-700); }
.ic-assigned   { background: var(--teal-50); color: var(--teal-700); }
.ic-unassigned { background: var(--rose-50); color: var(--rose-700); }

.stat-value { display: block; font-size: 1.4rem; font-weight: 700; line-height: 1.2; color: var(--slate-900); }
.stat-label { font-size: 0.78rem; color: var(--text-soft); font-weight: 500; }

/* ======================== PANEL ======================== */

.panel {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-md); border: 1px solid var(--border); overflow: hidden;
  animation: cardIn 0.5s ease both; animation-delay: 0.2s;
}

.panel-header {
  padding: 22px 24px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.panel-title { font-size: 1.12rem; font-weight: 700; color: var(--slate-800); }
.panel-desc { font-size: 0.82rem; color: var(--text-soft); margin-top: 2px; }

.panel-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.search-input { position: relative; }
.search-input i {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--slate-400); font-size: 0.8rem; pointer-events: none;
}
.search-input input {
  padding: 8px 12px 8px 32px; border: 1.5px solid var(--border); border-radius: var(--radius-xs);
  font-family: inherit; font-size: 0.85rem; background: var(--slate-50); color: var(--text);
  outline: none; width: 200px;
  transition: border-color var(--transition), box-shadow var(--transition), width var(--transition);
}
.search-input input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(13,148,136,0.08); width: 240px; }

.ctrl-select {
  padding: 8px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-xs);
  font-family: inherit; font-size: 0.83rem; color: var(--text); background: var(--slate-50);
  outline: none; cursor: pointer; transition: border-color var(--transition);
}
.ctrl-select:focus { border-color: var(--accent); }

.state-msg {
  padding: 56px 24px; text-align: center; color: var(--text-soft); font-size: 0.92rem;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.state-msg i { font-size: 1.4rem; opacity: 0.5; }

/* ======================== TABLE ======================== */

.table-wrap { overflow-x: auto; }

.data-table { width: 100%; border-collapse: collapse; min-width: 640px; }

.data-table thead th {
  padding: 11px 18px; text-align: left; font-size: 0.72rem; font-weight: 700;
  color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.06em;
  background: var(--slate-50); border-bottom: 1px solid var(--border);
  position: sticky; top: 56px; z-index: 10;
}

.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: rgba(13,148,136,0.02); }

.data-table td {
  padding: 14px 18px; font-size: 0.88rem;
  border-bottom: 1px solid var(--slate-100); vertical-align: middle;
}

.cell-avatar { display: inline-flex; align-items: center; gap: 10px; }
.avatar-circle {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  font-size: 0.72rem; font-weight: 700; color: #fff; flex-shrink: 0;
}
.cell-name { font-weight: 600; color: var(--slate-800); }
.cell-email { color: var(--text-soft); font-size: 0.82rem; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 6px; font-size: 0.73rem; font-weight: 600; }
.badge-teacher     { background: var(--sky-100); color: var(--sky-700); }
.badge-admin       { background: var(--amber-100); color: var(--amber-700); }
.badge-super-admin { background: var(--rose-100); color: var(--rose-700); }

/* Avatar colors */
.av-0 { background: #0d9488; } .av-1 { background: #0369a1; }
.av-2 { background: #7c3aed; } .av-3 { background: #c026d3; }
.av-4 { background: #db2777; } .av-5 { background: #dc2626; }
.av-6 { background: #ea580c; } .av-7 { background: #ca8a04; }

/* ======================== DEPARTMENT CHIPS ======================== */

.dept-cell { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 180px; }

.dept-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 6px 4px 10px; border-radius: 7px;
  font-size: 0.76rem; font-weight: 600; white-space: nowrap;
  animation: chipIn 0.2s ease both;
}

@keyframes chipIn {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}

.chip-x {
  width: 18px; height: 18px; border: none; border-radius: 5px;
  background: transparent; cursor: pointer; display: grid; place-items: center;
  font-size: 0.65rem; padding: 0; transition: all var(--transition);
}

/* Chip colors per department */
.chip-ttkb       { background: var(--sky-100); color: var(--sky-700); border: 1px solid #bae6fd; }
.chip-ttkb .chip-x { color: var(--sky-700); }
.chip-ttkb .chip-x:hover { background: var(--rose-100); color: var(--danger); }

.chip-breakout   { background: var(--rose-100); color: var(--rose-700); border: 1px solid #fecdd3; }
.chip-breakout .chip-x { color: var(--rose-700); }
.chip-breakout .chip-x:hover { background: #fda4af33; color: #9f1239; }

.chip-mix        { background: var(--violet-100); color: var(--violet-700); border: 1px solid #ddd6fe; }
.chip-mix .chip-x { color: var(--violet-700); }
.chip-mix .chip-x:hover { background: var(--rose-100); color: var(--danger); }

.chip-organizer  { background: var(--amber-100); color: var(--amber-700); border: 1px solid #fde68a; }
.chip-organizer .chip-x { color: var(--amber-700); }
.chip-organizer .chip-x:hover { background: var(--rose-100); color: var(--danger); }

.chip-supporter  { background: var(--green-100); color: var(--green-700); border: 1px solid #a7f3d0; }
.chip-supporter .chip-x { color: var(--green-700); }
.chip-supporter .chip-x:hover { background: var(--rose-100); color: var(--danger); }

/* + Add button */
.dept-add-wrap { position: relative; display: inline-flex; }

.dept-add-btn {
  width: 28px; height: 28px; border: 1.5px dashed var(--slate-300); border-radius: 7px;
  background: transparent; color: var(--slate-400); cursor: pointer;
  display: grid; place-items: center; font-size: 0.8rem; transition: all var(--transition);
}
.dept-add-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }

/* Dropdown */
.dept-dropdown {
  position: absolute; top: calc(100% + 6px); left: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); padding: 5px; z-index: 500; min-width: 150px;
  display: none;
}
.dept-dropdown.open { display: block; animation: dropIn 0.18s ease both; }

@keyframes dropIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: none; }
}

.dd-item {
  display: block; width: 100%; padding: 8px 12px; border: none; border-radius: 6px;
  background: transparent; font-family: inherit; font-size: 0.84rem; font-weight: 500;
  color: var(--text); cursor: pointer; text-align: left; transition: background var(--transition);
}
.dd-item:hover { background: var(--accent-light); color: var(--accent); }
.dd-item:disabled { opacity: 0.35; cursor: default; pointer-events: none; }

.dd-empty {
  padding: 10px 12px; font-size: 0.82rem; color: var(--text-soft); text-align: center;
}

/* ======================== TOAST ======================== */

.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(80px);
  padding: 12px 24px; border-radius: var(--radius-sm); font-family: inherit;
  font-size: 0.86rem; font-weight: 500; color: #fff; z-index: 9999;
  opacity: 0; pointer-events: none;
  transition: transform 0.35s cubic-bezier(0.34,1.56,0.64,1), opacity 0.35s ease;
  box-shadow: 0 8px 28px rgba(0,0,0,0.18);
}
.toast.ok  { background: var(--emerald-600); }
.toast.err { background: var(--danger); }
.toast.pop { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ======================== RESPONSIVE ======================== */

@media (max-width: 900px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .panel-header { flex-direction: column; }
  .panel-controls { width: 100%; }
  .search-input { flex: 1; }
  .search-input input, .search-input input:focus { width: 100%; }
}

@media (max-width: 640px) {
  .stats-row { gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 1.15rem; }
  .dashboard { padding: 14px 10px 30px; }
  .panel-controls { flex-direction: column; align-items: stretch; }
  .ctrl-select { width: 100%; }
  .col-email, .data-table td:nth-child(2) { display: none; }
  .data-table td { padding: 12px 12px; }
  .data-table thead th { padding: 10px 12px; }
}

@media (max-width: 420px) {
  .col-role, .data-table td:nth-child(3) { display: none; }
}


/* ======================== CONFIRM MODAL ======================== */

.confirm-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.35);
  backdrop-filter: blur(4px); z-index: 10000;
  display: grid; place-items: center; padding: 20px;
  animation: overlayIn 0.2s ease both;
}

@keyframes overlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.confirm-box {
  background: var(--surface); border-radius: 18px; padding: 32px 28px 24px;
  max-width: 380px; width: 100%; text-align: center;
  box-shadow: 0 20px 60px rgba(15,23,42,0.18);
  animation: boxIn 0.3s cubic-bezier(0.34,1.56,0.64,1) both;
}

@keyframes boxIn {
  from { opacity: 0; transform: scale(0.9) translateY(10px); }
  to   { opacity: 1; transform: none; }
}

.confirm-icon {
  width: 52px; height: 52px; border-radius: 14px;
  display: inline-grid; place-items: center; font-size: 1.3rem; margin-bottom: 16px;
}

.confirm-icon.icon-add { background: var(--teal-50); color: var(--teal-600); }
.confirm-icon.icon-remove { background: var(--rose-50); color: var(--rose-500); }

.confirm-text {
  font-size: 0.95rem; color: var(--slate-700); line-height: 1.5; margin-bottom: 24px;
}
.confirm-text strong { color: var(--slate-900); }

.confirm-btns { display: flex; gap: 10px; }

.confirm-cancel {
  flex: 1; padding: 11px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); font-family: inherit; font-size: 0.9rem; font-weight: 600;
  color: var(--slate-600); cursor: pointer; transition: all var(--transition);
}
.confirm-cancel:hover { background: var(--slate-50); border-color: var(--slate-300); }

.confirm-ok {
  flex: 1; padding: 11px; border: none; border-radius: var(--radius-sm);
  font-family: inherit; font-size: 0.9rem; font-weight: 600;
  color: #fff; cursor: pointer; transition: all var(--transition);
}
.confirm-ok.btn-add {
  background: linear-gradient(135deg, var(--teal-500), var(--teal-700));
  box-shadow: 0 4px 14px rgba(13,148,136,0.3);
}
.confirm-ok.btn-add:hover { box-shadow: 0 6px 20px rgba(13,148,136,0.4); }

.confirm-ok.btn-remove {
  background: linear-gradient(135deg, var(--rose-500), var(--rose-700));
  box-shadow: 0 4px 14px rgba(244,63,94,0.3);
}
.confirm-ok.btn-remove:hover { box-shadow: 0 6px 20px rgba(244,63,94,0.4); }