/* ============================================================
   MTH10203 Sources — Admin Stylesheet
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
  --navy:       #1e3a5f;
  --navy-dark:  #152c48;
  --blue:       #2563eb;
  --blue-light: #dbeafe;
  --amber:      #f59e0b;
  --green:      #059669;
  --red:        #dc2626;
  --red-light:  #fee2e2;
  --text:       #1e293b;
  --text-muted: #64748b;
  --bg:         #f1f5f9;
  --card:       #ffffff;
  --border:     #e2e8f0;
  --sidebar-w:  240px;
  --shadow:     0 2px 8px rgba(0,0,0,0.08);
  --shadow-md:  0 4px 20px rgba(0,0,0,0.15);
  --radius:     12px;
  --radius-sm:  8px;
  --transition: 0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Sarabun', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* ── Login Screen ── */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy-dark), #1d4ed8);
  padding: 1.5rem;
}

.login-card {
  background: white;
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo {
  text-align: center;
  margin-bottom: 1.75rem;
}
.login-logo .logo-icon { font-size: 2.5rem; }
.login-logo h1 { font-size: 1.25rem; font-weight: 700; color: var(--navy); margin-top: 0.5rem; }
.login-logo p { font-size: 0.85rem; color: var(--text-muted); }

.login-error {
  background: var(--red-light);
  color: var(--red);
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 1rem;
  display: none;
}
.login-error.show { display: block; }

/* ── Admin Layout ── */
#admin-app { display: none; min-height: 100vh; }
#admin-app.show { display: flex; }

.admin-sidebar {
  width: var(--sidebar-w);
  background: var(--navy-dark);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 200;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-brand .brand-title { font-size: 0.85rem; font-weight: 700; color: white; }
.sidebar-brand .brand-sub { font-size: 0.75rem; color: rgba(255,255,255,0.5); }

.sidebar-nav { padding: 0.75rem 0; flex: 1; }

.nav-label {
  padding: 0.5rem 1rem 0.25rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: rgba(255,255,255,0.35);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.nav-item {
  width: 100%;
  padding: 0.7rem 1rem;
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  font-family: 'Sarabun', sans-serif;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-align: left;
  transition: all var(--transition);
  border-radius: 0;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: white; }
.nav-item.active { background: var(--blue); color: white; }
.nav-item .icon { font-size: 1rem; width: 1.25rem; text-align: center; }

.sidebar-footer { padding: 1rem; border-top: 1px solid rgba(255,255,255,0.1); }
.logout-btn {
  width: 100%;
  padding: 0.6rem 1rem;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.7);
  font-family: 'Sarabun', sans-serif;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.logout-btn:hover { background: rgba(220,38,38,0.2); color: #fca5a5; border-color: #fca5a5; }

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

.admin-topbar {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-title { font-size: 1rem; font-weight: 600; color: var(--navy); }
.topbar-user { font-size: 0.8rem; color: var(--text-muted); }

.admin-content { padding: 1.5rem; flex: 1; }

/* ── Panel ── */
.panel {
  display: none;
  animation: fadeIn 0.2s ease;
}
.panel.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.panel-title { font-size: 1.35rem; font-weight: 700; color: var(--navy); }

/* ── Data Table ── */
.data-table-wrapper {
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th {
  background: var(--bg);
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg); }

/* ── Status Badge ── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.65rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}
.status-published { background: #d1fae5; color: #059669; }
.status-draft     { background: #f1f5f9; color: #64748b; }
.status-active    { background: #d1fae5; color: #059669; }
.status-inactive  { background: #fee2e2; color: #dc2626; }

/* ── Action Buttons ── */
.actions { display: flex; gap: 0.4rem; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-sm);
  font-family: 'Sarabun', sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { opacity: 0.85; transform: translateY(-1px); }
.btn:active { transform: none; }

.btn-primary  { background: var(--blue); color: white; }
.btn-success  { background: var(--green); color: white; }
.btn-warning  { background: var(--amber); color: var(--navy); }
.btn-danger   { background: var(--red); color: white; }
.btn-outline  { background: transparent; color: var(--blue); border: 1.5px solid var(--blue); }
.btn-ghost    { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-lg { padding: 0.65rem 1.25rem; font-size: 0.95rem; }
.btn-sm { padding: 0.28rem 0.6rem; font-size: 0.78rem; }

/* ── Forms ── */
.form-group { margin-bottom: 1.1rem; }
.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text);
}
.form-hint { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.2rem; }

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Sarabun', sans-serif;
  font-size: 0.9rem;
  color: var(--text);
  background: white;
  transition: border-color var(--transition);
  outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.form-textarea { resize: vertical; min-height: 90px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 500px) { .form-row { grid-template-columns: 1fr; } }

.form-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}
.form-check input[type="checkbox"] { width: 1rem; height: 1rem; accent-color: var(--blue); cursor: pointer; }

/* ── File Upload ── */
.file-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg);
}
.file-upload-area:hover { border-color: var(--blue); background: var(--blue-light); }
.file-upload-area.dragover { border-color: var(--blue); background: var(--blue-light); }
.file-upload-area .upload-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.file-upload-area p { font-size: 0.875rem; color: var(--text-muted); }
.file-upload-area strong { color: var(--blue); }
.file-upload-area input[type="file"] { display: none; }

.upload-progress {
  margin-top: 0.75rem;
  display: none;
}
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 0%;
}
.progress-text { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.3rem; }

.current-file {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}
.current-file a { color: var(--blue); }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.active { display: flex; }

.modal-box {
  background: white;
  border-radius: var(--radius);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: white;
  z-index: 10;
}
.modal-title { font-size: 1rem; font-weight: 700; color: var(--navy); }
.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body { padding: 1.25rem; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  bottom: 0;
}

/* ── Breadcrumb ── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  margin-bottom: 1.25rem;
  color: var(--text-muted);
}
.breadcrumb-link {
  color: var(--blue);
  cursor: pointer;
  background: none;
  border: none;
  font-family: 'Sarabun', sans-serif;
  font-size: 0.875rem;
  padding: 0;
}
.breadcrumb-link:hover { text-decoration: underline; }
.breadcrumb-sep { color: var(--border); }

/* ── Refresh Button Spin ── */
@keyframes spin { to { transform: rotate(360deg); } }
#refresh-btn { font-size: 1.1rem; line-height: 1; transition: color 0.2s; }
#refresh-btn.spinning { animation: spin 0.7s linear infinite; color: var(--blue); }
#analytics-refresh-btn.spinning { animation: spin 0.7s linear infinite; color: var(--blue); }

/* ── Analytics: Chart ── */
.chart-section {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.chart-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--navy);
}
.chart-wrap {
  position: relative;
  height: 260px;
}
.period-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.period-btn {
  background: white;
  border: none;
  border-right: 1px solid var(--border);
  padding: 0.3rem 0.75rem;
  font-size: 0.82rem;
  font-family: 'Sarabun', sans-serif;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.period-btn:last-child { border-right: none; }
.period-btn:hover { background: var(--bg); color: var(--navy); }
.period-btn.active { background: var(--blue); color: white; }

/* ── Analytics: Topic Chips ── */
.topic-chips-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.15rem 0;
}
.topic-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 20px;
  padding: 0.15rem 0.55rem;
  font-size: 0.78rem;
  color: #1e40af;
}
.topic-chip-day {
  background: #1e40af;
  color: white;
  border-radius: 20px;
  padding: 0 0.35rem;
  font-size: 0.7rem;
  font-weight: 600;
  flex-shrink: 0;
}
.topic-chip-count {
  background: #3b82f6;
  color: white;
  border-radius: 20px;
  padding: 0 0.3rem;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}
.visitor-id {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.2rem 0.45rem;
}

/* ── Topics Stats Bar ── */
.topics-stats-bar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  min-height: 1.75rem;
}
.stats-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.2rem 0.75rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ── Divider ── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.25rem 0;
}

/* ── Toast ── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--navy-dark);
  color: white;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: toastIn 0.25s ease;
  max-width: 320px;
}
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }

@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ── Responsive Sidebar ── */
@media (max-width: 768px) {
  .admin-sidebar { transform: translateX(-100%); transition: transform var(--transition); }
  .admin-sidebar.open { transform: none; }
  .admin-main { margin-left: 0; }
  .menu-toggle { display: flex; }
}

.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  padding: 0.25rem;
  color: var(--text);
}
