/* =========================================================
   Blog Cá Nhân — Modern Pure CSS
   Clean · Soft · Premium
   ========================================================= */

/* ---------- Design Tokens ---------- */
:root {
  --bg: #f4f6f9;
  --bg-elevated: #ffffff;
  --bg-muted: #f1f5f9;

  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-inverse: #ffffff;

  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;

  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: #fef2f2;

  --success: #059669;
  --success-soft: #ecfdf5;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --container: 820px;

  --transition: 0.18s ease;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--primary-hover);
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

h1, h2, h3 {
  line-height: 1.3;
  color: var(--text);
  font-weight: 700;
}

h1 {
  font-size: 1.65rem;
  margin: 0 0 18px;
}

h2 {
  font-size: 1.25rem;
  margin: 0 0 8px;
}

p {
  margin: 0 0 12px;
}

/* ---------- Layout ---------- */
.container {
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 18px;
}

/* ---------- Header ---------- */
.site-header {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
  background: rgba(255, 255, 255, 0.92);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
}

.brand a {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.brand a:hover {
  color: var(--text);
  text-decoration: none;
}

.main-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 4px;
  font-size: 0.925rem;
  font-weight: 500;
}

.main-nav a {
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
}

.main-nav a:hover {
  color: var(--text);
  background: var(--bg-muted);
  text-decoration: none;
}

/* ---------- Main & Footer ---------- */
.site-main {
  padding: 28px 0 48px;
  min-height: calc(100vh - 140px);
}

.site-main .container {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 3px 3px 9px;
  box-shadow: var(--shadow-sm);
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 20px 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  background: transparent;
}

.site-footer p {
  margin: 0;
}

/* ---------- Buttons ---------- */
.btn,
button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  font-family: inherit;
  font-size: 0.925rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-inverse);
  background: var(--primary);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition), transform 0.12s ease;
  white-space: nowrap;
}

.btn:hover,
button.btn:hover {
  background: var(--primary-hover);
  color: var(--text-inverse);
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--primary);
  border-radius: var(--radius-full);
  padding: 9px 22px;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-muted);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: #e2e8f0;
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-sm {
  padding: 5px 12px;
  font-size: 0.85rem;
  border-radius: 6px;
}

/* ---------- Forms ---------- */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="search"],
textarea,
select {
  width: 100%;
  padding: 11px 14px;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

textarea {
  resize: vertical;
  min-height: 160px;
  line-height: 1.55;
}

.form-actions,
.admin-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.inline-form {
  display: inline-block;
  margin: 0;
}

/* ---------- Alerts ---------- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.925rem;
  line-height: 1.45;
}

.alert-success {
  background: var(--success-soft);
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.alert-error {
  background: var(--danger-soft);
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* ---------- Feed / Post List ---------- */
.feed-header {
  margin-bottom: 22px;
}

.feed-header h1 {
  margin-bottom: 14px;
}

.search-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.search-form input[type="text"] {
  flex: 1 1 220px;
  min-width: 180px;
}

.search-meta {
  margin: 12px 0 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.post-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.post-item {
  padding: 18px 0;
}

.post-item + .post-item,
.post-list > hr + .post-item {
  /* spacing handled by hr or gap if needed */
}

.post-title {
  margin: 0 0 6px;
  font-size: 1.2rem;
  line-height: 1.35;
  font-weight: 700;
}

.post-title a {
  color: var(--text);
}

.post-title a:hover {
  color: var(--primary);
}

.post-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
}

.post-excerpt {
  margin: 8px 0 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* ---------- Post Detail ---------- */
.back-link {
  margin: 0 0 14px;
  font-size: 0.9rem;
}

.post-detail-title {
  margin-bottom: 8px;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
}

.post-body {
  font-size: 1.05rem;
  line-height: 1.8;
  color: var(--text);
  word-wrap: break-word;
  margin-top: 20px;
}

.post-body p {
  margin-bottom: 1em;
}

/* ---------- Badges ---------- */
.badge,
.badge-category,
.badge-published,
.badge-draft {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  line-height: 1.4;
}

.badge-category {
  background: var(--primary-soft);
  color: var(--primary);
}

.badge-category:hover {
  background: #dbeafe;
  text-decoration: none;
}

.badge-published {
  background: var(--success-soft);
  color: var(--success);
}

.badge-draft {
  background: #f1f5f9;
  color: var(--text-secondary);
}

.text-muted {
  color: var(--text-muted);
}

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 28px;
  padding-top: 8px;
}

.pagination a,
.page-current {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  transition: all var(--transition);
}

.pagination a:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
  text-decoration: none;
}

.page-current {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--text-inverse);
  font-weight: 600;
}

/* ---------- Auth / Login ---------- */
.auth-box {
  max-width: 400px;
  margin: 12px auto;
}

.auth-box h1 {
  text-align: center;
  margin-bottom: 20px;
}

/* ---------- Admin ---------- */
.admin-dashboard {
  /* inherits container */
}

.admin-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.admin-toolbar h1 {
  margin: 0;
}

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

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

.admin-table th,
.admin-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.admin-table th {
  background: var(--bg-muted);
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.admin-table tr:last-child td {
  border-bottom: none;
}

.admin-table tr:hover td {
  background: #f8fafc;
}

.actions-cell {
  white-space: nowrap;
}

.actions-cell .btn,
.actions-cell .inline-form {
  margin-right: 4px;
}

.actions-cell .inline-form:last-child {
  margin-right: 0;
}

.editor-section h1 {
  margin-bottom: 8px;
}

.editor-section > p {
  margin-bottom: 18px;
}

.post-form {
  max-width: 100%;
}

/* ---------- STORIE ---------- */
.stories-section {
  max-width: var(--container-stories);
  margin: 0 auto;
}

.stories-title {
  font-size: 1.4rem;
  margin-bottom: 20px;
  text-align: center;
  letter-spacing: -0.02em;
}

/* Compose box */
.story-compose {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.story-compose textarea {
  width: 100%;
  border: none;
  resize: none;
  min-height: 76px;
  font-size: 1rem;
  padding: 4px 0;
  background: transparent;
  color: var(--text);
  box-shadow: none;
}

.story-compose textarea:focus {
  outline: none;
  border: none;
  box-shadow: none;
}

.story-compose textarea::placeholder {
  color: var(--text-muted);
}

.compose-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
  padding-top: 4px;
}

/* Story cards */
.story-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.story-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  position: relative;
  transition: box-shadow var(--transition);
}

.story-card:hover {
  box-shadow: var(--shadow);
}

.story-body {
  flex: 1;
  min-width: 0;
}

.story-content {
  font-size: 0.98rem;
  line-height: 1.6;
  color: var(--text);
  word-break: break-word;
  white-space: pre-wrap;
}

.story-meta {
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: right;
}

.story-actions {
  flex-shrink: 0;
  align-self: flex-start;
}

.story-menu {
  position: relative;
}

.story-menu-btn {
  background: none;
  border: none;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background var(--transition), color var(--transition);
}

.story-menu-btn:hover {
  background: var(--bg-muted);
  color: var(--text-secondary);
}

.story-menu-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  min-width: 110px;
  z-index: 30;
  overflow: hidden;
}

.story-menu-dropdown a,
.story-menu-dropdown .menu-delete {
  display: block;
  width: 100%;
  padding: 10px 14px;
  text-align: left;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition);
}

.story-menu-dropdown a:hover {
  background: var(--bg-muted);
  color: var(--text);
}

.story-menu-dropdown .menu-delete {
  color: var(--danger);
}

.story-menu-dropdown .menu-delete:hover {
  background: var(--danger-soft);
}

.empty-stories {
  text-align: center;
  color: var(--text-muted);
  padding: 36px 0;
  font-size: 0.95rem;
}

/* ---------- Utilities ---------- */
.fa {
  /* fallback if Font Awesome not loaded */
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .site-main {
    padding: 16px 0 32px;
  }

  .site-main .container {
    padding: 20px 16px;
    border-radius: var(--radius);
  }

  h1 {
    font-size: 1.4rem;
  }

  .post-detail-title {
    font-size: 1.45rem;
  }

  .main-nav {
    gap: 2px;
  }

  .main-nav a {
    padding: 6px 10px;
    font-size: 0.875rem;
  }

  .admin-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .admin-table th,
  .admin-table td {
    padding: 10px 12px;
  }

  .stories-section {
    max-width: 100%;
  }

  .story-card {
    padding: 14px 14px;
  }
}

@media (max-width: 400px) {
  .site-header .container {
    flex-direction: column;
    align-items: flex-start;
  }
}
