/* ══════════════════════════════════════════════════════
   Reddit Community Tracker — Design System
   ══════════════════════════════════════════════════════ */

/* ── 1. Custom Properties ── */
:root {
  /* Font (set by JS from localStorage) */
  --font-main: "DM Sans";

  /* Spacing (8px scale) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  /* Neutrals */
  --gray-50:  #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* Accent */
  --accent: #ff4500;
  --accent-hover: #e03d00;

  /* Semantic */
  --success-bg: #ecfdf5;  --success-border: #a7f3d0;  --success-text: #065f46;
  --error-bg:   #fef2f2;  --error-border:   #fecaca;  --error-text:   #991b1b;
  --warning-bg: #fffbeb;  --warning-border: #fde68a;  --warning-text: #92400e;

  /* Surfaces */
  --surface: #ffffff;
  --bg:      #f9fafb;
  --border:  #e5e7eb;
  --border-strong: #d1d5db;

  /* Radii */
  --radius-sm:   4px;
  --radius-md:   8px;
  --radius-lg:  12px;
  --radius-pill: 999px;

  /* Font size multiplier (set by JS from localStorage) */
  --font-scale: 1;

  /* Typography */
  --text-xs:   calc(12px * var(--font-scale));
  --text-sm:   calc(13px * var(--font-scale));
  --text-base: calc(14px * var(--font-scale));
  --text-md:   calc(16px * var(--font-scale));
  --text-lg:   calc(20px * var(--font-scale));
  --text-xl:   calc(24px * var(--font-scale));

  --olive: #5A5A40;
  --olive-light: #A8A878;
  --olive-dark: #4A4A30;
  --bg: #F5F2ED;
  --dark: #1A1A1A;
  --muted: #6B6B6B;
  --card-bg: rgba(255,255,255,0.6);
  --border: rgba(90,90,64,0.15);

}

/* ── 2. Reset / Base ── */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  padding: var(--space-5);
  background: var(--bg);
  color: var(--gray-800);
  font-family: var(--font-main), sans-serif;
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.centered {
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

a { color: var(--gray-700); }
a:hover { color: var(--gray-900); }

/* ── 3. Typography ── */
h1, h2, h3 { margin: 0; line-height: 1.3; }
.muted { color: var(--gray-500); }
.mini { font-size: var(--text-sm); }
.meta-sub { font-size: var(--text-xs); color: var(--gray-400); margin-top: 2px; }

/* ── 4. Form Elements ── */
label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--gray-600);
  margin: var(--space-3) 0 var(--space-1);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="datetime-local"],
input[inputmode="numeric"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  font-family: var(--font-main), sans-serif;
  color: var(--gray-800);
  background: var(--surface);
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--gray-400);
  outline: none;
  box-shadow: 0 0 0 2px rgba(107, 114, 128, 0.1);
}

textarea { min-height: 90px; resize: vertical; }

/* ── 5. Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--gray-700);
  font-size: var(--text-sm);
  font-weight: 500;
  font-family: var(--font-main), sans-serif;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s;
  line-height: 1.4;
  white-space: nowrap;
}
.btn:hover {
  background: var(--gray-50);
  border-color: var(--border-strong);
  color: var(--gray-700);
  text-decoration: none;
}

.btn--primary {
  background: var(--gray-800);
  color: #fff;
  border-color: var(--gray-800);
}
.btn--primary:hover {
  background: var(--gray-700);
  border-color: var(--gray-700);
  color: #fff;
}

.btn--accent {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn--accent:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

.btn--ghost {
  border-color: transparent;
  color: var(--gray-500);
}
.btn--ghost:hover {
  background: var(--gray-100);
  color: var(--gray-700);
}

.btn--sm {
  padding: 4px 10px;
  font-size: var(--text-xs);
}

.btn--block {
  display: block;
  width: 100%;
  text-align: center;
  justify-content: center;
  padding: 12px;
  margin-top: var(--space-4);
}

.btn--outline {
  background: var(--surface);
  color: var(--gray-700);
  margin-left: var(--space-2);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--gray-400);
  cursor: pointer;
  transition: all 0.12s;
  padding: 0;
}
.btn-icon:hover {
  background: var(--gray-100);
  color: var(--gray-600);
}
.btn-icon--danger:hover {
  background: var(--error-bg);
  color: var(--error-text);
  border-color: var(--error-border);
}

/* ── 6. Alerts ── */
.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
  border: 1px solid;
}
.alert a { font-weight: 600; }

.alert--success { background: var(--success-bg); border-color: var(--success-border); color: var(--success-text); }
.alert--success a { color: var(--success-text); }
.alert--error   { background: var(--error-bg);   border-color: var(--error-border);   color: var(--error-text); }
.alert--warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-text); }

/* ── 7. Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  width: 100%;
  max-width: 400px;
}
.card h1 { font-size: var(--text-lg); font-weight: 700; margin: 0 0 var(--space-1); }
.card p  { font-size: var(--text-sm); color: var(--gray-500); margin: 0 0 var(--space-5); }

.card--wide { max-width: 800px; }
.card--form { max-width: 720px; }

/* ── 8. Page Shell ── */
.page-shell {
    max-width: 1948px;
    margin: 0 auto;
    width: 100%;
}

/* ── 9. Top Bar ── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-5);
}

.top-bar__title {
  font-size: var(--text-lg);
  font-weight: 700;
  margin: 0;
}

.top-bar__subtitle {
  font-size: var(--text-sm);
  color: var(--gray-500);
}

.top-bar__right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.stats-pills {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  font-size: var(--text-sm);
}
.pill__label { color: var(--gray-500); }
.pill__value { font-weight: 600; color: var(--gray-800); }

/* ── 10. Filter Bar ── */
.filter-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-5);
}

.filter-bar__form {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.filter-group label {
  margin: 0;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.filter-select {
  width: auto;
  min-width: 140px;
  padding: 6px 10px;
  font-size: var(--text-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

/* ── 11. Section Blocks ── */
.sections {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.section-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--gray-50);
}

.section-header__title {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--gray-800);
}

.section-header__count {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--gray-400);
  background: var(--gray-100);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}

.empty-state {
  padding: var(--space-5);
  text-align: center;
  color: var(--gray-400);
  font-size: var(--text-sm);
}

/* ── 12. Data Tables ── */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: left;
  background: var(--gray-50);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background: var(--gray-50);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.cell-link {
  color: var(--gray-400);
  text-decoration: none;
  font-size: var(--text-xs);
}
.cell-link:hover { color: var(--accent); }

/* ── 13. Inline Editing ── */
.inline-input, .inline-select {
  width: 100%;
  padding: 5px 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-family: var(--font-main), sans-serif;
  background: transparent;
  color: var(--gray-800);
  transition: border-color 0.15s, background 0.15s;
}

.inline-input:hover, .inline-select:hover {
  border-color: var(--border);
  background: var(--gray-50);
}

.inline-input:focus, .inline-select:focus {
  border-color: var(--gray-400);
  background: var(--surface);
  outline: none;
  box-shadow: 0 0 0 2px rgba(107, 114, 128, 0.1);
}

.inline-input.saved, .inline-select.saved {
  background: var(--success-bg);
  border-color: var(--success-border);
  transition: none;
}

.inline-input--score,
.inline-input--views {
  max-width: 80px;
  text-align: right;
}

.inline-input--date {
  min-width: 160px;
}

.inline-select--community {
  min-width: 120px;
}

.inline-input--title {
  min-width: 160px;
}

/* Hide number input spinners */
.inline-input[type="number"]::-webkit-inner-spin-button,
.inline-input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.inline-input[type="number"] { -moz-appearance: textfield; }

/* ── 14. Font Switcher ── */
.font-switcher {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.font-btn {
  padding: 6px 12px;
  font-size: var(--text-xs);
  border: none;
  background: var(--surface);
  cursor: pointer;
  border-right: 1px solid var(--border);
  color: var(--gray-500);
  font-weight: 500;
  font-family: var(--font-main), sans-serif;
  transition: background 0.12s;
}
.font-btn:last-child { border-right: none; }

.font-btn[aria-checked="true"] {
  background: var(--gray-800);
  color: #fff;
}
.font-btn:hover:not([aria-checked="true"]) {
  background: var(--gray-50);
}

/* Size switcher */
.size-switcher {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.size-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  border: none;
  background: var(--surface);
  cursor: pointer;
  border-right: 1px solid var(--border);
  color: var(--gray-500);
  font-weight: 700;
  font-family: var(--font-main), sans-serif;
  transition: background 0.12s;
  line-height: 1;
}
.size-btn:last-child { border-right: none; }

.size-btn--sm  { font-size: 11px; }
.size-btn--md  { font-size: 15px; }
.size-btn--lg  { font-size: 19px; }

.size-btn[aria-checked="true"] {
  background: var(--gray-800);
  color: #fff;
}
.size-btn:hover:not([aria-checked="true"]) {
  background: var(--gray-50);
}

/* ── 15. Utilities ── */
.divider { height: 1px; background: var(--border); margin: var(--space-4) 0; }
.inline-form { display: inline; }

/* ── 16. Form Page Layouts ── */
.wrap { max-width: 980px; margin: 0 auto; }
.form-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.form-top .page-title { font-size: var(--text-lg); font-weight: 700; }

.row  { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--space-3); }

/* ── 17. Honeypot ── */
.honeypot {
  position: absolute;
  left: -9999px;
}

/* ── 18. Admin Table (sync history, admin list) ── */
.admin-table { width: 100%; border-collapse: collapse; margin: var(--space-2) 0; }
.admin-table th,
.admin-table td { padding: var(--space-2) var(--space-3); text-align: left; border-bottom: 1px solid var(--border); }
.admin-table th { font-size: var(--text-xs); color: var(--gray-500); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }

/* ── 19. Responsive ── */
@media (max-width: 900px) {
  body { padding: var(--space-3); }

  .top-bar { flex-direction: column; align-items: flex-start; }
  .top-bar__right { width: 100%; }
  .stats-pills { width: 100%; }

  .row, .row3 { grid-template-columns: 1fr; }

  .filter-bar__form { flex-direction: column; align-items: stretch; }
  .filter-group { flex-direction: column; align-items: stretch; }
  .filter-select { width: 100%; }

  /* Tables → cards */
  .data-table,
  .data-table thead,
  .data-table tbody,
  .data-table th,
  .data-table td,
  .data-table tr {
    display: block;
    width: 100%;
  }

  .data-table thead { display: none; }

  .data-table tbody tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-3);
    padding: var(--space-3);
    background: var(--surface);
  }

  .data-table td {
    border: none;
    padding: var(--space-1) 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-3);
  }

  .data-table td::before {
    font-weight: 600;
    color: var(--gray-400);
    font-size: var(--text-xs);
    text-transform: uppercase;
    flex: 0 0 80px;
  }

  .data-table td:nth-child(1)::before  { content: "Community"; }
  .data-table td:nth-child(2)::before  { content: "Title"; }
  .data-table td:nth-child(3)::before  { content: "Score"; }
  .data-table td:nth-child(4)::before  { content: "Views"; }
  .data-table td:nth-child(5)::before  { content: "Subs"; }
  .data-table td:nth-child(6)::before  { content: "Weekly"; }
  .data-table td:nth-child(7)::before  { content: "Date"; }
  .data-table td:nth-child(8)::before  { content: "Status"; }
  .data-table td:nth-child(9)::before  { content: "Project"; }
  .data-table td:nth-child(10)::before { content: "Category"; }
  .data-table td:nth-child(11)::before { content: "Tags"; }
  .data-table td:nth-child(12)::before { content: ""; }

  .inline-input, .inline-select {
    max-width: 100%;
    flex: 1;
  }

  .inline-input--score, .inline-input--views {
    max-width: 100%;
    text-align: left;
  }

  .font-switcher { width: 100%; }
  .font-btn { flex: 1; text-align: center; }
}

/* ── 10. Community Info Tooltip ── */
.community-cell {
  display: flex;
  align-items: center;
  gap: 4px;
}

.community-info-btn {
  cursor: pointer;
  font-size: calc(14px * var(--font-scale));
  color: var(--muted);
  flex-shrink: 0;
  user-select: none;
  line-height: 1;
}
.community-info-btn:hover {
  color: var(--accent);
}

.community-tooltip {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 100;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  padding: var(--space-3);
  min-width: 280px;
  max-width: 360px;
  font-size: calc(12px * var(--font-scale));
}

.ct-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.ct-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ct-title {
  font-size: calc(11px * var(--font-scale));
  color: var(--muted);
}

.ct-stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-3);
  margin-bottom: var(--space-2);
  font-size: calc(11px * var(--font-scale));
  color: var(--text-secondary, #555);
}

.ct-desc {
  font-size: calc(11px * var(--font-scale));
  color: var(--muted);
  line-height: 1.4;
  border-top: 1px solid var(--border);
  padding-top: var(--space-2);
}

/* ── 11. Stats Table & Scroll (shared with fetch_stats_browser) ── */
.stats-scroll {
  overflow-x: auto;
  max-height: 70vh;
  overflow-y: auto;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: calc(12px * var(--font-scale));
}

.stats-table th,
.stats-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.stats-table th {
  background: var(--bg-page);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}

.stats-table tr:hover {
  background: var(--bg-hover, #f5f5f5);
}

.icon-cell img {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  vertical-align: middle;
}
