/* ── Reset & tokens ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Palette */
  --bg:           #f1f5f9;
  --surface:      #ffffff;
  --surface-2:    #f8fafc;
  --border:       #e2e8f0;
  --border-focus: #6366f1;
  --text:         #0f172a;
  --muted:        #64748b;
  --muted-light:  #94a3b8;
  --primary:      #4f46e5;
  --primary-dark: #4338ca;
  --primary-bg:   #eef2ff;
  --danger:       #dc2626;
  --danger-dark:  #b91c1c;
  --danger-bg:    #fef2f2;
  --success:      #16a34a;
  --success-bg:   #f0fdf4;
  --warning-bg:   #fffbeb;
  --warning:      #d97706;

  /* Layout */
  --sidebar-w:  240px;
  --topbar-h:   52px;

  /* Shapes */
  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(15,23,42,.06);
  --shadow:    0 1px 4px rgba(15,23,42,.08), 0 4px 12px rgba(15,23,42,.04);
  --shadow-md: 0 4px 16px rgba(15,23,42,.10);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  font-size: 14.5px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
body.has-nav { padding-top: var(--topbar-h); }

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

/* ── Topbar ── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .75rem;
  padding: 0 1.1rem;
  z-index: 200;
  box-shadow: var(--shadow-sm);
}
.topbar-brand {
  font-weight: 700; font-size: .95rem;
  background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hamburger {
  background: none; border: none; font-size: 1.15rem;
  cursor: pointer; color: var(--muted); padding: .3rem .4rem; line-height: 1;
  border-radius: var(--radius-sm); transition: background .12s, color .12s;
}
.hamburger:hover { background: var(--bg); color: var(--text); }

/* ── Sidebar ── */
.sidebar {
  position: fixed; top: var(--topbar-h); left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transform: translateX(-100%); transition: transform .2s cubic-bezier(.4,0,.2,1);
  z-index: 300; overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(15,23,42,.4);
  z-index: 299; backdrop-filter: blur(2px);
}
.sidebar-overlay.open { display: block; }
.sidebar-close {
  background: none; border: none; cursor: pointer; color: var(--muted);
  font-size: .85rem; padding: .25rem .45rem; border-radius: var(--radius-sm);
  transition: background .12s; display: none;
}
.sidebar-close:hover { background: var(--bg); }

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1rem .8rem;
}
.sidebar-header .brand {
  font-weight: 700; font-size: .95rem;
  background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-section { padding: .375rem .625rem; }
.sidebar-section + .sidebar-section {
  border-top: 1px solid var(--border);
  margin-top: .25rem; padding-top: .625rem;
}
.sidebar-label {
  font-size: .67rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .09em; color: var(--muted-light);
  padding: .2rem .5rem .35rem;
}
.sidebar-item {
  display: flex; align-items: center; gap: .55rem;
  padding: .42rem .6rem; font-size: .875rem; color: var(--muted);
  border-radius: var(--radius-sm); text-decoration: none;
  transition: background .12s, color .12s;
  white-space: nowrap; overflow: hidden;
}
.sidebar-item:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.sidebar-item.active {
  background: var(--primary-bg); color: var(--primary); font-weight: 600;
}
.sidebar-icon { font-size: .82rem; flex-shrink: 0; width: 1rem; text-align: center; opacity: .75; }
.sidebar-item.active .sidebar-icon { opacity: 1; }
.sidebar-text { overflow: hidden; text-overflow: ellipsis; }
.sidebar-add { color: var(--muted-light); font-size: .82rem; }
.sidebar-add:hover { color: var(--primary); }

.sidebar-footer {
  margin-top: auto; padding: .625rem .625rem .75rem;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem;
}
.sidebar-user {
  display: flex; align-items: center; gap: .5rem;
  padding: .38rem .55rem; border-radius: var(--radius-sm);
  color: var(--muted); font-size: .83rem; font-weight: 500;
  transition: background .12s, color .12s; flex: 1; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-user:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.sidebar-user.active { background: var(--primary-bg); color: var(--primary); }
.sidebar-avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
  color: #fff; font-size: .65rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; text-transform: uppercase;
}
.sidebar-logout {
  padding: .38rem .55rem; border-radius: var(--radius-sm);
  color: var(--muted); font-size: .83rem;
  transition: background .12s, color .12s;
}
.sidebar-logout:hover { background: var(--danger-bg); color: var(--danger); text-decoration: none; }

/* Desktop sidebar always visible */
@media (min-width: 768px) {
  .sidebar { transform: translateX(0); }
  .sidebar-close { display: none !important; }
  .sidebar-overlay { display: none !important; }
  .page-wrap { margin-left: var(--sidebar-w); }
  .hamburger { display: none; }
}
@media (max-width: 767px) {
  .sidebar-close { display: block; }
}

/* ── Main ── */
main {
  max-width: 900px;
  margin: 2.25rem auto;
  padding: 0 1.5rem;
}

/* ── Flash messages ── */
.flash {
  display: flex; align-items: flex-start; gap: .65rem;
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: .875rem;
  border: 1px solid transparent;
}
.flash::before { font-size: 1rem; flex-shrink: 0; }
.flash-success {
  background: var(--success-bg); color: var(--success);
  border-color: #bbf7d0;
}
.flash-success::before { content: "✓"; }
.flash-error {
  background: var(--danger-bg); color: var(--danger);
  border-color: #fecaca;
}
.flash-error::before { content: "✕"; }

/* ── Page header ── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.75rem; gap: 1rem;
}
.page-header h2 {
  font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; color: var(--text);
}

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .48rem 1rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: .85rem; font-weight: 600;
  cursor: pointer; text-decoration: none;
  transition: background .15s, box-shadow .15s, transform .1s;
  white-space: nowrap; line-height: 1.4;
  box-shadow: 0 1px 2px rgba(79,70,229,.25);
}
.btn:hover {
  background: var(--primary-dark); color: #fff; text-decoration: none;
  box-shadow: 0 2px 6px rgba(79,70,229,.35);
}
.btn:active { transform: scale(.98); }
.btn-sm { padding: .3rem .65rem; font-size: .78rem; }
.btn-ghost {
  background: transparent; color: var(--muted); box-shadow: none;
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); color: var(--text); box-shadow: none; }
.btn-secondary {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.btn-secondary:hover { background: var(--bg); color: var(--text); box-shadow: var(--shadow-sm); }
.btn-danger { background: var(--danger); box-shadow: 0 1px 2px rgba(220,38,38,.2); }
.btn-danger:hover { background: var(--danger-dark); box-shadow: 0 2px 6px rgba(220,38,38,.3); }

/* ── Cards ── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.35rem 1.1rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s, transform .15s;
}
.card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.card h3 { font-size: .97rem; font-weight: 600; margin-bottom: .2rem; }
.card .slug {
  color: var(--muted); font-size: .78rem; margin-bottom: .9rem;
  font-family: ui-monospace, monospace;
}

/* ── Auth card ── */
.auth-card {
  max-width: 380px;
  margin: 5rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.25rem 2rem;
  box-shadow: var(--shadow-md);
  text-align: center;
}
.auth-card .auth-logo {
  width: 48px; height: 48px; border-radius: 14px; margin: 0 auto 1rem;
  background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
}
.auth-card h1 { font-size: 1.45rem; font-weight: 700; letter-spacing: -.02em; margin-bottom: .2rem; }
.auth-card .tagline { color: var(--muted); font-size: .875rem; margin-bottom: 1.75rem; }
.auth-card form { text-align: left; }

/* ── Forms ── */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.35rem 1.5rem;
  max-width: 620px;
  box-shadow: var(--shadow-sm);
}
.form-card + .form-card { margin-top: .875rem; }

label {
  display: block; font-size: .82rem; font-weight: 600;
  margin-bottom: .3rem; margin-top: 1rem; color: var(--text);
}
label:first-child { margin-top: 0; }

input[type=text], input[type=url], input[type=email],
input[type=password], input[type=number], select, textarea {
  width: 100%;
  padding: .5rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
input[disabled] { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
textarea { font-family: inherit; resize: vertical; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: .75rem;
}
.form-row label { margin-top: 0; }
.form-row > div { margin-top: 1rem; }
.checkbox-label {
  display: flex; align-items: center; gap: .55rem;
  font-size: .875rem; font-weight: 400; margin-top: .9rem;
  cursor: pointer;
}
.checkbox-label input[type=checkbox] {
  width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer;
}
.hint { font-size: .8rem; color: var(--muted); margin-top: .3rem; line-height: 1.45; }
form .btn { margin-top: 1.35rem; }

fieldset {
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.1rem;
  margin-bottom: 1rem;
}
legend {
  font-size: .75rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
  padding: 0 .4rem;
}

/* ── Tabs ── */
.tabs {
  display: flex; gap: .25rem; flex-wrap: wrap;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .3rem;
  margin-bottom: 1.5rem;
}
.tab {
  padding: .42rem .85rem;
  font-size: .83rem; font-weight: 500;
  color: var(--muted);
  border-radius: var(--radius-sm);
  cursor: pointer; text-decoration: none;
  transition: background .12s, color .12s;
  white-space: nowrap;
}
.tab:hover { color: var(--text); background: var(--surface); text-decoration: none; }
.tab.active {
  color: var(--primary); background: var(--surface);
  box-shadow: var(--shadow-sm); font-weight: 600;
}
.tab-panel.hidden { display: none; }

/* ── Section header ── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: .875rem;
}
.section-header h3 { font-size: .95rem; font-weight: 600; }

/* ── Tables ── */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
th {
  text-align: left;
  padding: .6rem 1rem;
  font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
td {
  padding: .65rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbff; }
.url-cell {
  max-width: 280px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

code {
  font-family: ui-monospace, "Cascadia Code", "Fira Code", monospace;
  font-size: .8rem; background: var(--surface-2);
  border: 1px solid var(--border);
  padding: .1em .4em; border-radius: 4px; color: var(--primary);
}

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center;
  padding: .18em .6em;
  border-radius: 99px;
  font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
}
.badge-include, .badge-active {
  background: var(--success-bg); color: var(--success);
  border: 1px solid #bbf7d0;
}
.badge-exclude {
  background: var(--danger-bg); color: var(--danger);
  border: 1px solid #fecaca;
}
.badge-disabled {
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border);
}

/* ── Feed URL box ── */
.feed-url-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  margin-bottom: 1rem;
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  font-size: .85rem;
}
.feed-url-box strong { color: var(--muted); font-weight: 600; white-space: nowrap; }
.feed-url-box code {
  background: none; border: none; flex: 1;
  min-width: 180px; word-break: break-all; color: var(--text);
}

/* ── Empty state ── */
.empty-state {
  text-align: center; padding: 3.5rem 1rem;
  color: var(--muted);
}
.empty-state p { font-size: .9rem; }
.empty {
  color: var(--muted); font-size: .875rem; padding: .6rem 0;
  display: flex; align-items: center; gap: .4rem;
}

/* ── Danger zone ── */
.danger-zone {
  background: var(--danger-bg);
  border: 1.5px solid #fecaca;
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
}
.danger-zone h3 { font-size: .95rem; font-weight: 600; color: var(--danger); margin-bottom: .35rem; }
.danger-zone p { font-size: .85rem; color: #991b1b; margin-bottom: .9rem; }

/* ── Sharing form ── */
.form-card-title {
  font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); margin-bottom: .75rem;
}
.link-row { display: flex; gap: .5rem; margin-bottom: .4rem; }
.link-row input { flex: 1; margin-top: 0; }

/* ── Row actions ── */
.row-actions { display: flex; gap: .35rem; align-items: center; }

/* ── Inline info box ── */
.info-box {
  background: var(--primary-bg);
  border: 1px solid #c7d2fe;
  border-radius: var(--radius);
  padding: .65rem .9rem;
  font-size: .83rem;
  color: #3730a3;
  margin-top: .5rem;
  display: flex; align-items: flex-start; gap: .5rem;
}

/* ── Stat / counter chip ── */
.count-chip {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.35rem; height: 1.35rem;
  background: var(--primary-bg); color: var(--primary);
  border-radius: 99px; font-size: .7rem; font-weight: 700;
  margin-left: .35rem;
}
