/* ============================================================
   Khana Platform Admin — Design System
   White + Turquoise | Google/Apple-grade polish
   ============================================================ */

/* -- Reset & Base ------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --tq:        #0D9488;
  --tq-light:  #14B8A6;
  --tq-lighter:#CCFBF1;
  --tq-dark:   #0F766E;
  --tq-50:     #F0FDFA;

  --white:     #FFFFFF;
  --g-50:      #F9FAFB;
  --g-100:     #F3F4F6;
  --g-200:     #E5E7EB;
  --g-300:     #D1D5DB;
  --g-400:     #9CA3AF;
  --g-500:     #6B7280;
  --g-600:     #4B5563;
  --g-700:     #374151;
  --g-800:     #1F2937;
  --g-900:     #111827;

  --green:     #10B981;
  --green-bg:  #ECFDF5;
  --yellow:    #F59E0B;
  --yellow-bg: #FFFBEB;
  --red:       #EF4444;
  --red-bg:    #FEF2F2;
  --blue:      #3B82F6;
  --blue-bg:   #EFF6FF;
  --purple:    #8B5CF6;
  --purple-bg: #F5F3FF;

  --radius:    10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --shadow-xs: 0 1px 2px rgba(0,0,0,.04);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow:    0 4px 12px rgba(0,0,0,.06);
  --shadow-md: 0 6px 20px rgba(0,0,0,.08);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.10);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;

  --sidebar-w: 260px;
  --topbar-h:  64px;
  --ease:      cubic-bezier(.4,0,.2,1);
}

html { font-size: 14px; }
body {
  font-family: var(--font);
  background: var(--g-50);
  color: var(--g-800);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--tq); text-decoration: none; }
a:hover { color: var(--tq-dark); }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; }
::selection { background: var(--tq-lighter); color: var(--tq-dark); }
:focus-visible { outline: 2px solid var(--tq); outline-offset: 2px; }

/* -- Layout ------------------------------------------------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--white);
  border-right: 1px solid var(--g-200);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex; flex-direction: column;
  z-index: 100;
  transition: transform .25s var(--ease);
}
.sidebar-brand {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 20px;
  border-bottom: 1px solid var(--g-100);
  font-size: 1.25rem; font-weight: 800;
  color: var(--tq);
  letter-spacing: -.02em;
}
.sidebar-brand span { color: var(--g-400); font-weight: 400; font-size: .75rem; margin-left: auto; }

.sidebar-nav { flex: 1; padding: 12px; overflow-y: auto; }
.sidebar-section { margin-bottom: 8px; }
.sidebar-label {
  font-size: .65rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--g-400);
  padding: 8px 12px 4px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--g-600);
  font-size: .875rem; font-weight: 500;
  cursor: pointer;
  transition: all .15s var(--ease);
  position: relative;
}
.nav-item:hover { background: var(--g-50); color: var(--g-800); }
.nav-item.active {
  background: var(--tq-50);
  color: var(--tq);
  font-weight: 600;
}
.nav-item.active::before {
  content: '';
  position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px;
  background: var(--tq);
  border-radius: 0 3px 3px 0;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .7; }
.nav-item.active svg { opacity: 1; }
.nav-badge {
  margin-left: auto;
  background: var(--red);
  color: white;
  font-size: .65rem; font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px; text-align: center;
}

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

.topbar {
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--g-200);
  display: flex; align-items: center;
  padding: 0 28px;
  gap: 16px;
  position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-size: 1.1rem; font-weight: 700; color: var(--g-900); }
.topbar-spacer { flex: 1; }
.topbar-user {
  display: flex; align-items: center; gap: 8px;
  font-size: .8rem; color: var(--g-500);
}
.topbar-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--tq-lighter);
  color: var(--tq);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .75rem;
}
.mobile-toggle {
  display: none;
  background: none; border: none;
  color: var(--g-600); cursor: pointer;
  padding: 4px;
}

.content { flex: 1; padding: 28px; }
.content-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 24px; flex-wrap: wrap;
}
.content-header h1 { font-size: 1.5rem; font-weight: 700; color: var(--g-900); }
.content-header-actions { margin-left: auto; display: flex; gap: 8px; }

/* -- Cards -------------------------------------------------- */
.card {
  background: var(--white);
  border: 1px solid var(--g-200);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: box-shadow .2s var(--ease);
}
.card:hover { box-shadow: var(--shadow-sm); }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 8px;
}
.card-title { font-size: .95rem; font-weight: 650; color: var(--g-800); }
.card-subtitle { font-size: .75rem; color: var(--g-400); }

/* -- Stat Cards --------------------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--white);
  border: 1px solid var(--g-200);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex; align-items: flex-start; gap: 14px;
  transition: all .2s var(--ease);
}
.stat-card:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.stat-icon {
  width: 42px; height: 42px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 20px; height: 20px; }
.stat-icon.tq  { background: var(--tq-50); color: var(--tq); }
.stat-icon.grn { background: var(--green-bg); color: var(--green); }
.stat-icon.ylw { background: var(--yellow-bg); color: var(--yellow); }
.stat-icon.red { background: var(--red-bg); color: var(--red); }
.stat-icon.blu { background: var(--blue-bg); color: var(--blue); }
.stat-icon.prp { background: var(--purple-bg); color: var(--purple); }
.stat-info { flex: 1; min-width: 0; }
.stat-label { font-size: .72rem; color: var(--g-400); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.5rem; font-weight: 750; color: var(--g-900); line-height: 1.2; margin-top: 2px; }
.stat-change { font-size: .72rem; font-weight: 600; margin-top: 4px; }
.stat-change.up { color: var(--green); }
.stat-change.down { color: var(--red); }

/* -- Grid layouts ------------------------------------------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 24px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; margin-bottom: 24px; }

/* -- Tables ------------------------------------------------- */
.table-wrap {
  background: var(--white);
  border: 1px solid var(--g-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 24px;
}
.table-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--g-100);
  flex-wrap: wrap;
}
.table-toolbar-title { font-weight: 650; font-size: .9rem; color: var(--g-800); }
.table-toolbar-spacer { flex: 1; }

table {
  width: 100%;
  border-collapse: collapse;
}
thead th {
  text-align: left;
  padding: 10px 16px;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--g-400);
  background: var(--g-50);
  border-bottom: 1px solid var(--g-200);
  white-space: nowrap;
}
tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--g-100);
  font-size: .85rem;
  color: var(--g-700);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--g-50); }

.table-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px;
  border-top: 1px solid var(--g-100);
  font-size: .8rem; color: var(--g-400);
}

/* Cell helpers */
.cell-flex { display: flex; align-items: center; gap: 10px; }
.cell-avatar {
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--g-100);
  flex-shrink: 0;
}
.cell-avatar.round { border-radius: 50%; }
.cell-primary { font-weight: 600; color: var(--g-800); }
.cell-sub { font-size: .75rem; color: var(--g-400); }
.cell-mono { font-family: var(--mono); font-size: .8rem; }
.cell-link { color: var(--tq); cursor: pointer; font-weight: 500; }
.cell-link:hover { text-decoration: underline; }

/* -- Badges ------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center;
  font-size: .7rem; font-weight: 600;
  padding: 2px 8px;
  border-radius: 50px;
  white-space: nowrap;
}
.badge-tq     { background: var(--tq-50); color: var(--tq); }
.badge-green  { background: var(--green-bg); color: var(--green); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-red    { background: var(--red-bg); color: var(--red); }
.badge-blue   { background: var(--blue-bg); color: var(--blue); }
.badge-purple { background: var(--purple-bg); color: var(--purple); }
.badge-gray   { background: var(--g-100); color: var(--g-500); }

/* -- Buttons ------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: .8rem; font-weight: 600;
  border: none; cursor: pointer;
  transition: all .15s var(--ease);
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }

.btn-primary { background: var(--tq); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--tq-dark); }
.btn-secondary { background: var(--g-100); color: var(--g-700); }
.btn-secondary:hover:not(:disabled) { background: var(--g-200); }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover:not(:disabled) { background: #DC2626; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--g-200);
  color: var(--g-600);
}
.btn-outline:hover:not(:disabled) { background: var(--g-50); border-color: var(--g-300); }
.btn-ghost { background: transparent; color: var(--g-500); padding: 6px 10px; }
.btn-ghost:hover:not(:disabled) { background: var(--g-100); color: var(--g-700); }
.btn-sm { padding: 5px 10px; font-size: .75rem; border-radius: var(--radius-sm); }
.btn-icon { padding: 7px; }

/* -- Forms -------------------------------------------------- */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: .75rem; font-weight: 600; color: var(--g-600);
  margin-bottom: 5px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--g-200);
  border-radius: var(--radius);
  font-size: .85rem;
  color: var(--g-800);
  background: var(--white);
  transition: all .15s var(--ease);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--tq);
  box-shadow: 0 0 0 3px rgba(13,148,136,.1);
  outline: none;
}
.form-input::placeholder { color: var(--g-300); }
.form-textarea { min-height: 80px; resize: vertical; }
.form-select { cursor: pointer; }
.form-hint { font-size: .72rem; color: var(--g-400); margin-top: 4px; }
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }

.search-box {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--g-200);
  border-radius: var(--radius);
  background: var(--white);
  transition: border-color .15s;
  min-width: 220px;
}
.search-box:focus-within { border-color: var(--tq); }
.search-box svg { width: 15px; height: 15px; color: var(--g-300); flex-shrink: 0; }
.search-box input {
  border: none; outline: none; background: transparent;
  font-size: .8rem; color: var(--g-800); width: 100%;
}

/* -- Tabs --------------------------------------------------- */
.tabs {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--g-200);
  margin-bottom: 20px;
  overflow-x: auto;
}
.tab {
  padding: 10px 18px;
  font-size: .82rem; font-weight: 500;
  color: var(--g-500);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all .15s var(--ease);
  white-space: nowrap;
}
.tab:hover { color: var(--g-700); }
.tab.active { color: var(--tq); border-color: var(--tq); font-weight: 600; }

/* -- Modal -------------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  opacity: 0; transition: opacity .2s var(--ease);
  padding: 20px;
}
.modal-overlay.show { opacity: 1; }
.modal {
  background: var(--white);
  border-radius: var(--radius-xl);
  width: 100%; max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: scale(.95); transition: transform .2s var(--ease);
}
.modal-overlay.show .modal { transform: scale(1); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 0;
}
.modal-title { font-size: 1.1rem; font-weight: 700; color: var(--g-900); }
.modal-close {
  background: none; border: none;
  color: var(--g-400); cursor: pointer; padding: 4px;
  border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--g-100); color: var(--g-600); }
.modal-body { padding: 20px 24px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--g-100);
}

/* -- Toast -------------------------------------------------- */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: .82rem; font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toastIn .3s var(--ease);
  max-width: 400px;
}
.toast-success { background: var(--green); color: white; }
.toast-error   { background: var(--red); color: white; }
.toast-info    { background: var(--blue); color: white; }
@keyframes toastIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: none; } }

/* -- Pagination --------------------------------------------- */
.pagination {
  display: flex; align-items: center; gap: 4px;
}
.page-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  font-size: .8rem; font-weight: 500;
  color: var(--g-600);
  border: 1px solid var(--g-200);
  background: var(--white);
  cursor: pointer;
  transition: all .15s;
}
.page-btn:hover:not(.active):not(:disabled) { background: var(--g-50); border-color: var(--g-300); }
.page-btn.active { background: var(--tq); color: white; border-color: var(--tq); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* -- Empty State -------------------------------------------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px 24px;
  text-align: center;
}
.empty-state svg { width: 48px; height: 48px; color: var(--g-300); margin-bottom: 16px; }
.empty-state-title { font-size: 1rem; font-weight: 600; color: var(--g-600); margin-bottom: 4px; }
.empty-state-sub { font-size: .82rem; color: var(--g-400); }

/* -- Loading ------------------------------------------------ */
.loading {
  display: flex; align-items: center; justify-content: center;
  padding: 60px 20px;
  color: var(--g-400);
  font-size: .85rem;
}
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--g-200);
  border-top-color: var(--tq);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  margin-right: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* -- Chart -------------------------------------------------- */
.chart-container { position: relative; height: 260px; }

/* -- Misc --------------------------------------------------- */
.text-tq { color: var(--tq); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-muted { color: var(--g-400); }
.text-sm { font-size: .8rem; }
.text-xs { font-size: .72rem; }
.text-right { text-align: right; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.mb-0 { margin-bottom: 0; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }

.divider { height: 1px; background: var(--g-100); margin: 12px 0; }

.detail-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 16px;
  font-size: .85rem;
}
.detail-grid dt { color: var(--g-400); font-weight: 500; }
.detail-grid dd { color: var(--g-800); }

/* -- Ticket detail layout ----------------------------------- */
.ticket-detail-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  align-items: start;
}

/* -- Sidebar overlay ---------------------------------------- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 99;
  opacity: 0;
  transition: opacity .25s var(--ease);
}
.sidebar-overlay.show { display: block; opacity: 1; }

/* -- Responsive --------------------------------------------- */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .main { margin-left: 0; }
  .mobile-toggle { display: flex; }
  .content { padding: 12px; }
  .topbar { padding: 0 12px; }
  .topbar-user span { display: none; }
  .content-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .content-header-actions { margin-left: 0; }
  .table-toolbar { flex-direction: column; align-items: stretch; }
  .search-box { min-width: unset; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-card { padding: 12px; }
  .stat-value { font-size: 1.2rem; }
  table { font-size: .8rem; }
  .ticket-detail-grid { grid-template-columns: 1fr; }
  .modal { max-width: 95vw; margin: 10px; }
  .modal-body { max-height: 70vh; overflow-y: auto; }
}

/* -- Login Page --------------------------------------------- */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--g-50) 0%, var(--tq-50) 100%);
  padding: 20px;
}
.login-card {
  background: var(--white);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%; max-width: 420px;
}
.login-brand {
  text-align: center; margin-bottom: 28px;
}
.login-brand h1 {
  font-size: 2rem; font-weight: 800; color: var(--tq);
  letter-spacing: -.03em;
}
.login-brand p { color: var(--g-400); font-size: .85rem; margin-top: 4px; }
.login-error {
  background: var(--red-bg);
  color: var(--red);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: .82rem;
  margin-bottom: 16px;
  border: 1px solid rgba(239,68,68,.15);
}
