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

:root {
  /* Modern Premium Color Palette */
  --primary:        #6366f1;
  --primary-h:      #4f46e5;
  --primary-glow:   rgba(99, 102, 241, 0.4);
  --gradient-btn:   linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --success:        #10b981;
  --danger:         #ef4444;
  --secondary:      #475569;
  
  --bg-gradient:    linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  --card-bg:        rgba(255, 255, 255, 0.95);
  --card-border:    rgba(255, 255, 255, 0.4);
  
  --border:         #e2e8f0;
  --text:           #0f172a;
  --text-muted:     #64748b;
  
  --radius:         16px;
  --radius-sm:      10px;
  
  --shadow-sm:      0 2px 4px rgba(0, 0, 0, 0.02), 0 1px 2px rgba(0, 0, 0, 0.03);
  --shadow-card:    0 10px 30px rgba(0, 0, 0, 0.04), 0 4px 6px rgba(0, 0, 0, 0.02);
  --shadow-hover:   0 15px 35px rgba(0, 0, 0, 0.07), 0 5px 15px rgba(0, 0, 0, 0.04);
}

*, *::before, *::after { 
  box-sizing: border-box; 
  margin: 0; 
  padding: 0; 
}

body {
  font-family: 'Inter', 'Noto Sans Thai', sans-serif;
  background: var(--bg-gradient);
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6, .logo {
  font-family: 'Outfit', 'Noto Sans Thai', sans-serif;
  color: var(--text);
}

a { 
  color: var(--primary); 
  text-decoration: none; 
  transition: color 0.2s ease;
}
a:hover { 
  color: var(--primary-h);
}

/* ─── Header (Glassmorphism) ─────────────────── */
.site-header {
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  height: auto;
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.logo {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: var(--gradient-btn);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.logo a { 
  -webkit-text-fill-color: transparent; /* Keep gradient on link */
}
nav { 
  display: flex; 
  gap: 0.5rem; 
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.nav-link {
  color: var(--secondary);
  padding: 0.4rem 0.9rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.nav-link:hover {
  background: rgba(99, 102, 241, 0.08);
  color: var(--primary);
}
.nav-link.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px var(--primary-glow);
}

/* ─── Layout ─────────────────────────────────── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.25rem;
}
.main-layout { 
  padding-top: 2rem; 
  padding-bottom: 4rem; 
  display: flex; 
  flex-direction: column; 
  gap: 1.5rem; 
}

/* ─── Card ───────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow-card);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  backdrop-filter: blur(20px);
}
.card:hover {
  box-shadow: var(--shadow-hover);
}
.table-card { padding: 0; overflow: hidden; } /* Removes padding for full-width tables */

/* ─── Form ───────────────────────────────────── */
.form-group { margin-bottom: 1.25rem; }
.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  color: var(--secondary);
}
input[type="text"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: all 0.2s ease;
  outline: none;
  box-shadow: 0 1px 2px rgba(0,0,0,0.02) inset;
}
input[type="text"]:focus,
input[type="password"]:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
  background: #fff;
}
input::placeholder, textarea::placeholder {
  color: #94a3b8;
}
textarea { resize: vertical; line-height: 1.6; }

/* ─── Buttons ─────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  border: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  user-select: none;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

.btn-primary { 
  background: var(--gradient-btn); 
  color: #fff; 
  box-shadow: 0 4px 12px var(--primary-glow);
}
.btn-primary:hover { 
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.5);
  color: #fff;
}

.btn-secondary { 
  background: #334155; 
  color: #fff; 
  box-shadow: 0 4px 12px rgba(51, 65, 85, 0.3);
}
.btn-secondary:hover { 
  background: #1e293b; 
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(30, 41, 59, 0.4);
  color: #fff; 
}

.btn-success { 
  background: var(--success); 
  color: #fff; 
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}
.btn-success:hover { 
  background: #059669; 
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
  color: #fff; 
}

.btn-danger { 
  background: var(--danger); 
  color: #fff; 
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}
.btn-danger:hover { 
  background: #dc2626; 
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(239, 68, 68, 0.4);
  color: #fff; 
}

.btn-ghost {
  background: transparent;
  color: var(--secondary);
  border: 1.5px solid var(--border);
}
.btn-ghost:hover { 
  background: #f1f5f9; 
  color: var(--text); 
  border-color: #cbd5e1;
}

.btn-sm { padding: 0.4rem 0.85rem; font-size: 0.82rem; border-radius: 8px; }

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

/* ─── Section titles ──────────────────────────── */
.section-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  color: var(--text);
  letter-spacing: -0.3px;
}

/* ─── Output ─────────────────────────────────── */
.output-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.output-header .section-title { margin-bottom: 0; }
.output-box {
  background: #f8fafc;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: 'Inter', 'Noto Sans Thai', sans-serif; /* Clean font for text, not monospace unless requested */
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text);
  min-height: 100px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}
.output-input { 
  background: #f1f5f9; 
  color: var(--secondary);
  font-style: italic;
}

/* ─── Status & Flash Messages ────────────────── */
.save-status {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  min-height: 1.4em;
  font-weight: 500;
  animation: fadeIn 0.3s ease;
}
.save-status.success { color: var(--success); }
.save-status.error   { color: var(--danger); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}

.flash { 
  padding: 1rem 1.25rem; 
  border-radius: var(--radius-sm); 
  margin-bottom: 1.5rem; 
  font-weight: 600; 
  font-size: 0.95rem; 
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-sm);
}
.flash.success { background: #dcfce7; color: #166534; border-left: 4px solid #22c55e; }
.flash.error   { background: #fee2e2; color: #991b1b; border-left: 4px solid #ef4444; }

/* ─── Tables ─────────────────────────────────── */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.table th {
  background: #f8fafc;
  padding: 1rem 1.25rem;
  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);
}
.table td {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  transition: background 0.15s ease;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #f8fafc; }

.id-cell      { color: var(--text-muted); font-size: 0.85rem; width: 40px; }
.date-cell    { color: var(--text-muted); font-size: 0.85rem; white-space: nowrap; }
.preview-cell { color: var(--text-muted); font-size: 0.9rem; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.action-cell  { white-space: nowrap; }

/* ─── Badges ─────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: #f1f5f9;
  color: #475569;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
/* Vibrant dynamic badge colors */
.badge-analyze            { background: #ede9fe; color: #5b21b6; }
.badge-swot               { background: #e0e7ff; color: #3730a3; }
.badge-planning           { background: #ffe4e6; color: #9f1239; }
.badge-code               { background: #dbeafe; color: #1e40af; }
.badge-content            { background: #dcfce7; color: #166534; }
.badge-social_media       { background: #fce7f3; color: #9d174d; }
/* Add more as needed, others will fallback to default badge style safely */

/* ─── Recent / Page headers ───────────────────── */
.recent-header, .page-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.link-more { 
  font-size: 0.9rem; 
  font-weight: 600;
  color: var(--primary); 
  display: inline-flex;
  align-items: center;
  transition: transform 0.2s ease;
}
.link-more:hover { transform: translateX(3px); }
.page-title { font-size: 1.5rem; font-weight: 800; margin: 0; letter-spacing: -0.5px; }
.total-count { 
  font-size: 0.85rem; 
  font-weight: 600;
  color: var(--secondary); 
  background: #f1f5f9;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
}
.meta-row { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.5rem; flex-wrap: wrap; }
.meta-date { font-size: 0.85rem; color: var(--text-muted); font-weight: 500; }
.link-view { font-size: 0.9rem; color: var(--primary); font-weight: 600; }
.inline-form { display: inline; }
.back-link { 
  font-size: 0.9rem; 
  font-weight: 500;
  color: var(--text-muted); 
  display: inline-flex; 
  align-items: center;
  margin-bottom: 0.5rem; 
  transition: color 0.2s;
}
.back-link:hover { color: var(--primary); text-decoration: none; }

/* ─── Search bar ──────────────────────────────── */
.search-bar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  background: var(--card-bg);
}
.search-input  { flex: 1 1 250px; }
.search-select { flex: 0 1 180px; }

/* ─── Pagination ──────────────────────────────── */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.25rem;
  margin-top: 2rem;
  font-size: 0.95rem;
}
.page-link { 
  color: var(--primary); 
  font-weight: 600; 
  padding: 0.5rem 1rem;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}
.page-link:hover {
  background: var(--primary);
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--primary-glow);
  text-decoration: none;
}
.page-info { color: var(--text-muted); font-weight: 500; }

/* ─── View grid ───────────────────────────────── */
.view-grid { display: flex; flex-direction: column; gap: 1.5rem; margin-top: 1.5rem; }

/* ─── Empty state ─────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--secondary);
}
.empty-state p { margin-bottom: 1.5rem; font-size: 1.1rem; font-weight: 500; }

.nav-logout {
  margin-left: 0.5rem;
  color: var(--danger);
  font-weight: 600;
  background: rgba(239, 68, 68, 0.05);
}
.nav-logout:hover { 
  background: var(--danger);
  color: #fff;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* Checkbox alignment */
.checkbox-row { display: flex; gap: 2rem; align-items: center; margin-bottom: 1.25rem; }
.checkbox-row label { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; font-size: 0.95rem; cursor: pointer; color: var(--secondary); }
.checkbox-row input[type=checkbox] { width: 18px; height: 18px; cursor: pointer; accent-color: var(--primary); }

.status-active   { color: var(--success); font-weight: 700; background: #dcfce7; padding: 0.25rem 0.6rem; border-radius: 12px; font-size: 0.8rem; display: inline-block; }
.status-inactive { color: var(--secondary); font-weight: 700; background: #f1f5f9; padding: 0.25rem 0.6rem; border-radius: 12px; font-size: 0.8rem; display: inline-block; }

/* ─── Responsive ──────────────────────────────── */
@media (max-width: 768px) {
  .site-header .container { gap: 0.5rem; flex-wrap: wrap; height: auto; padding: 0.75rem 1rem; }
  nav { flex-wrap: wrap; justify-content: center; width: 100%; margin-top: 0.5rem; }
  .logo { margin: 0 auto; }
  .nav-link { padding: 0.4rem 0.6rem; font-size: 0.85rem; }
  .card { padding: 1.25rem; }
  .output-header { flex-direction: column; }
  .page-title-row { flex-direction: column; align-items: flex-start; }
  .table th:nth-child(4), .table td:nth-child(4) { display: none; } /* Hide preview on small screens */
}
