/* ============ Common styles ============ */
:root {
  --primary: #1e3a5f;
  --primary-light: #2c5282;
  --primary-dark: #142740;
  --accent: #c9a227;
  --accent-light: #e8c94a;
  --bg: #f7f8fc;
  --card: #ffffff;
  --text: #1a202c;
  --text-secondary: #4a5568;
  --text-muted: #718096;
  --border: #e2e8f0;
  --border-light: #edf2f7;
  --danger: #e53e3e;
  --success: #38a169;
  --warning: #d69e2e;
  --info: #3182ce;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1), 0 6px 10px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ Header / Nav ============ */
.site-header {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
  color: white;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}
.site-header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.site-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  color: white;
  text-decoration: none;
}
.site-logo:hover { text-decoration: none; }
.logo-icon {
  width: 38px; height: 38px;
  background: var(--accent);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 800;
  color: var(--primary-dark);
}
.logo-title { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.logo-sub { font-size: 11px; opacity: 0.75; }
.site-nav { display: flex; align-items: center; gap: 4px; }
.nav-link {
  color: rgba(255,255,255,0.85);
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  transition: var(--transition);
  text-decoration: none;
}
.nav-link:hover { background: rgba(255,255,255,0.12); color: white; text-decoration: none; }
.nav-admin {
  background: var(--accent);
  color: var(--primary-dark);
  font-weight: 700;
}
.nav-admin:hover { background: var(--accent-light); color: var(--primary-dark); }
.nav-user {
  display: flex; align-items: center; gap: 8px;
  padding-left: 12px;
  margin-left: 4px;
  border-left: 1px solid rgba(255,255,255,0.2);
}
.nav-username { font-size: 13px; color: rgba(255,255,255,0.9); font-weight: 500; }
.nav-btn {
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  transition: var(--transition);
  text-decoration: none;
  border: none;
  cursor: pointer;
  display: inline-block;
}
.nav-btn-ghost {
  color: rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.08);
}
.nav-btn-ghost:hover { background: rgba(255,255,255,0.18); color: white; text-decoration: none; }
.nav-btn-primary {
  background: var(--accent);
  color: var(--primary-dark);
}
.nav-btn-primary:hover { background: var(--accent-light); text-decoration: none; }

/* ============ Page main ============ */
.page-main {
  flex: 1;
  max-width: 480px;
  margin: 0 auto;
  padding: 40px 20px;
  width: 100%;
}
.page-main-wide { max-width: 1200px; }

/* ============ Footer ============ */
.site-footer {
  border-top: 1px solid var(--border-light);
  padding: 24px 20px;
  margin-top: 40px;
  background: white;
}
.site-footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.7;
}
.site-footer .copyright { margin-top: 8px; color: var(--text-muted); }

/* ============ Auth forms ============ */
.auth-box {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
}
.auth-box h1 {
  font-size: 24px;
  color: var(--primary);
  margin-bottom: 6px;
}
.auth-sub { color: var(--text-muted); font-size: 14px; margin-bottom: 24px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px; font-weight: 600; color: var(--text-secondary);
}
.auth-form label.checkbox {
  flex-direction: row; align-items: center; gap: 8px;
  font-weight: 400; color: var(--text-secondary);
}
.auth-form input[type=email],
.auth-form input[type=text],
.auth-form input[type=password] {
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  outline: none;
  transition: var(--transition);
  background: white;
  font-family: inherit;
}
.auth-form input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.1);
}
.auth-form input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }
.auth-alt {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border-light);
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
}

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center; justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  font-family: inherit;
  line-height: 1.4;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); color: white; }
.btn-accent { background: var(--accent); color: var(--primary-dark); }
.btn-accent:hover { background: var(--accent-light); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c53030; color: white; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text-secondary); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-lg { padding: 13px 20px; font-size: 15px; margin-top: 6px; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { display: flex; width: 100%; }

/* ============ Flash messages ============ */
.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 14px;
  line-height: 1.5;
  border: 1px solid;
}
.flash-success { background: #f0fff4; border-color: #9ae6b4; color: #22543d; }
.flash-error { background: #fff5f5; border-color: #feb2b2; color: #742a2a; }
.flash-info { background: #ebf8ff; border-color: #90cdf4; color: #2c5282; }
.flash-warning { background: #fffaf0; border-color: #fbd38d; color: #744210; }

/* ============ Tables (admin, history) ============ */
.data-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}
.data-card h2 { font-size: 18px; margin-bottom: 14px; color: var(--primary); }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table th, .data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
}
.data-table th {
  background: var(--bg);
  font-weight: 700;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.data-table tbody tr:hover { background: #fafbfc; }
.data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .muted { color: var(--text-muted); font-size: 12px; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.badge-success { background: #c6f6d5; color: #22543d; }
.badge-danger { background: #fed7d7; color: #742a2a; }
.badge-warning { background: #feebc8; color: #744210; }
.badge-info { background: #bee3f8; color: #2c5282; }
.badge-neutral { background: var(--border-light); color: var(--text-secondary); }

/* ============ Page Title ============ */
.page-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-title h1 { font-size: 22px; color: var(--primary); }
.page-title .sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ============ Stats cards ============ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
}
.stat-card.accent { border-left-color: var(--accent); }
.stat-card.success { border-left-color: var(--success); }
.stat-card.warning { border-left-color: var(--warning); }
.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.stat-delta { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ============ Forms (admin edit) ============ */
.form-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 14px 16px;
  align-items: center;
}
.form-grid .form-label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.form-grid input[type=text],
.form-grid input[type=email],
.form-grid select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  outline: none;
  background: white;
  font-family: inherit;
}
.form-grid input:focus, .form-grid select:focus { border-color: var(--primary); }
.form-actions { margin-top: 20px; display: flex; gap: 8px; }

/* ============ Pagination ============ */
.pager {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin: 24px 0 8px;
  flex-wrap: wrap;
}
.pager a, .pager span {
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  background: white;
  min-width: 34px;
  text-align: center;
  text-decoration: none;
}
.pager a:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.pager .current { background: var(--primary); color: white; border-color: var(--primary); }
.pager .disabled { opacity: 0.4; pointer-events: none; }

/* ============ Responsive ============ */
@media (max-width: 768px) {
  .site-header-inner { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }
  .logo-sub { display: none; }
  .logo-title { font-size: 15px; }
  .nav-link { padding: 6px 10px; font-size: 13px; }
  .nav-user { padding-left: 8px; margin-left: 0; }
  .nav-username { display: none; }
  .page-main { padding: 20px 14px; }
  .auth-box { padding: 24px 20px; }
  .data-table th:nth-child(n+4), .data-table td:nth-child(n+4) { display: none; }
  .form-grid { grid-template-columns: 1fr; gap: 6px; }
  .form-grid .form-label { margin-top: 8px; }
}

/* ============ History list ============ */
.history-item {
  background: white;
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  border-left: 3px solid var(--accent);
  transition: var(--transition);
}
.history-item:hover { box-shadow: var(--shadow-md); }
.history-item .h-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text-muted);
  gap: 8px;
}
.history-item .h-type {
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 700;
  background: var(--border-light);
  color: var(--primary);
}
.history-item .h-query { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.history-item .h-preview { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
