/* ── Tokens (from codefetch-web-app's real palette — teal/amber, deeper
   dark-mode backgrounds, Inter + IBM Plex Mono) ── */
:root {
  --bg:            #f6f8fa;
  --bg-elevated:   #ffffff;
  --bg-card:       #ffffff;
  --bg-input:      #ffffff;
  --border:        rgba(0,150,120,0.35);
  --border-subtle: rgba(31,41,55,0.12);
  --border-dim:    rgba(0,150,120,0.18);
  --accent:        #b5750f;
  --accent-soft:   rgba(181,117,15,0.10);
  --accent-glow:   rgba(181,117,15,0.20);
  --teal:          #00967a;
  --teal-bright:   #007a63;
  --teal-soft:     rgba(0,150,122,0.08);
  --text:          #1c2530;
  --text-muted:    #57606a;
  --text-dim:      #8b949e;
  --danger:        #d92d2d;
  --danger-soft:   rgba(217,45,45,0.08);
  --success:       #1a7f37;
  --success-soft:  rgba(26,127,55,0.08);
  --sans: 'Inter', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --radius: 6px;
  --radius-lg: 10px;
  --hdr-height: 60px;
  --sb-width: 230px;
  --sb-width-collapsed: 56px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #0d1117;
    --bg-elevated:   #161b22;
    --bg-card:       #1e242e;
    --bg-input:      #161b22;
    --border:        rgba(0,212,168,0.35);
    --border-subtle: rgba(240,246,252,0.12);
    --border-dim:    rgba(0,212,168,0.18);
    --accent:        #f5a623;
    --accent-soft:   rgba(245,166,35,0.12);
    --accent-glow:   rgba(245,166,35,0.25);
    --teal:          #00d4a8;
    --teal-bright:   #3ae6c8;
    --teal-soft:     rgba(0,212,168,0.10);
    --text:          #e6edf3;
    --text-muted:    #8b949e;
    --text-dim:      #484f58;
    --danger:        #ff6b6b;
    --danger-soft:   rgba(255,107,107,0.10);
    --success:       #3fb950;
    --success-soft:  rgba(63,185,80,0.10);
  }
}
:root[data-theme="dark"] {
  --bg:            #0d1117;
  --bg-elevated:   #161b22;
  --bg-card:       #1e242e;
  --bg-input:      #161b22;
  --border:        rgba(0,212,168,0.35);
  --border-subtle: rgba(240,246,252,0.12);
  --border-dim:    rgba(0,212,168,0.18);
  --accent:        #f5a623;
  --accent-soft:   rgba(245,166,35,0.12);
  --accent-glow:   rgba(245,166,35,0.25);
  --teal:          #00d4a8;
  --teal-bright:   #3ae6c8;
  --teal-soft:     rgba(0,212,168,0.10);
  --text:          #e6edf3;
  --text-muted:    #8b949e;
  --text-dim:      #484f58;
  --danger:        #ff6b6b;
  --danger-soft:   rgba(255,107,107,0.10);
  --success:       #3fb950;
  --success-soft:  rgba(63,185,80,0.10);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box }
html { height: 100% }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer }
.mono { font-family: var(--mono) }

/* ── Top bar ── */
header, .top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--hdr-height);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(0,150,122,0.15), 0 4px 24px rgba(0,0,0,0.04);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}
.brand img { height: 32px; width: auto; display: block }
.spacer { flex: 1 }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-family: var(--sans);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
}
.btn:hover { border-color: var(--teal); color: var(--teal-bright); background: var(--teal-soft) }

/* Primary — amber, with CodeFetch's signature glow + hover-lift */
.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--bg-elevated);
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: 0 2px 10px var(--accent-glow);
}
.btn-primary:hover { box-shadow: 0 4px 20px var(--accent-glow); transform: translateY(-1px); color: var(--bg-elevated); border-color: transparent }

/* Danger — soft fill + real border by default, fully inverts on hover */
.btn-danger {
  background: var(--danger-soft);
  border: 1px solid rgba(217,45,45,0.4);
  color: var(--danger);
  font-weight: 700;
}
.btn-danger:hover { background: var(--danger); color: var(--bg-elevated); border-color: var(--danger) }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.1s, background 0.1s, border-color 0.1s;
}
.icon-btn svg { width: 17px; height: 17px; flex-shrink: 0 }
.icon-btn:hover { color: var(--teal-bright); background: var(--teal-soft); border-color: var(--border-dim) }
.btn-danger-icon:hover { color: var(--danger); background: var(--danger-soft); border-color: transparent }

/* Theme toggle — small circular button, sun glyph, amber hover */
#theme-toggle {
  font-family: inherit;
  font-size: 13px;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}
#theme-toggle:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft) }

/* ── Sidebar shell ── */
.app-shell { display: flex; min-height: calc(100vh - var(--hdr-height)) }
.sidebar {
  width: var(--sb-width);
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  padding: 14px 10px;
  gap: 2px;
  transition: width 0.18s ease;
  position: sticky;
  top: var(--hdr-height);
  height: calc(100vh - var(--hdr-height));
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar.collapsed { width: var(--sb-width-collapsed) }

.sb-collapse-btn {
  align-self: flex-end;
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  width: 26px; height: 26px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  margin-bottom: 10px;
  transition: all 0.15s;
  flex-shrink: 0;
  font-family: inherit;
}
.sb-collapse-btn:hover { border-color: var(--teal); color: var(--teal-bright); background: var(--teal-soft) }
.sidebar.collapsed .sb-collapse-btn { align-self: center }

.sb-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  border-left: 2px solid transparent;
  background: transparent;
  width: 100%;
  text-align: left;
  font-family: inherit;
  white-space: nowrap;
  overflow: hidden;
  transition: all 0.15s;
}
.sb-item:hover { background: var(--teal-soft); color: var(--teal-bright) }
.sb-item.active { background: var(--teal-soft); border-left-color: var(--teal); color: var(--teal-bright); font-weight: 600 }
.sb-item .sb-icon { width: 16px; height: 16px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; opacity: 0.85 }
.sb-item .sb-icon svg { width: 16px; height: 16px }
.sidebar.collapsed .sb-item span:not(.sb-icon) { display: none }
.sidebar.collapsed .sb-item { justify-content: center; padding: 8px; border-left: none }
.sidebar.collapsed .sb-item.active { border-left: none; box-shadow: inset 2px 0 0 var(--teal) }

.sb-item.danger { color: var(--danger) }
.sb-item.danger:hover { background: var(--danger-soft); color: var(--danger) }
.sb-item.danger.active { background: var(--danger-soft); border-left-color: var(--danger); color: var(--danger) }

.sb-heading {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 14px 10px 4px;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar.collapsed .sb-heading { text-align: center; padding: 14px 2px 4px }
.sidebar.collapsed .sb-heading span { display: none }
.sidebar.collapsed .sb-heading::before { content: '\2022\2022\2022'; letter-spacing: 2px; color: var(--text-dim); font-size: 8px }

.sb-divider { height: 1px; background: var(--border-subtle); margin: 10px 6px }
.sb-spacer { flex: 1 }
.sb-account-email {
  padding: 4px 10px 8px;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar.collapsed .sb-account-email { display: none }
.sb-main { flex: 1; min-width: 0; padding: 28px 28px 60px }

/* ── Layout (non-sidebar pages: login) ── */
.wrap {
  max-width: 1400px;
  margin: 32px auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── Card ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-subtle);
}
.card-hd h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}

/* ── Page heading ── */
.page-heading {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0 0 20px;
  text-wrap: balance;
}

/* ── Search bar ── */
.searchbar {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 13px;
  margin-bottom: 18px;
  max-width: 360px;
}
.searchbar .prompt { color: var(--teal) }
.searchbar input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
}

/* ── Table ── */
.table-wrap { overflow-x: auto }
table { width: 100%; border-collapse: separate; border-spacing: 0 }
thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 11px 18px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
}
tbody td {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
  font-size: 14px;
}
tbody tr:last-child td { border-bottom: none }
tbody tr:hover td { background: var(--teal-soft) }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 13px;
  padding: 3px 10px;
  border-radius: var(--radius);
  background: var(--teal-soft);
  color: var(--teal-bright);
  border: 1px solid transparent;
  font-weight: 500;
}
.badge-amber {
  background: var(--accent-soft);
  color: var(--accent);
}
.muted { color: var(--text-muted) }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center }

/* ── Drawer ── */
.drawer {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 200; /* above the sticky top-bar (100) and sidebar (150 on mobile) */
  background: rgba(0, 0, 0, .45);
  backdrop-filter: blur(3px);
}
.drawer.open { display: block }
.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: min(640px, 92vw);
  background: var(--bg-elevated);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  animation: slide-in .16s ease-out;
  box-shadow: -8px 0 40px rgba(0, 0, 0, .25);
}
@keyframes slide-in {
  from { transform: translateX(16px); opacity: 0 }
  to   { transform: none; opacity: 1 }
}
.drawer-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-card);
}
.drawer-hd strong { font-size: 16px; font-weight: 700; color: var(--text) }
.drawer-bd { padding: 20px; overflow-y: auto; flex: 1 }
.drawer-ft {
  padding: 14px 20px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  background: var(--bg-card);
}

/* ── Form fields ── */
.field { margin-bottom: 16px }
.field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 6px;
}
.field small { display: block; color: var(--text-dim); font-size: 12px; margin-top: 4px }
input[type="text"],
input[type="url"],
input[type="password"],
input[type="email"],
textarea,
select {
  width: 100%;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: var(--sans);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 130px; resize: vertical; font-family: var(--mono) }
input:focus, textarea:focus, select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-soft);
}
input:disabled, textarea:disabled, select:disabled {
  background: var(--bg);
  color: var(--text-dim);
  cursor: not-allowed;
}
.help { font-size: 12px; color: var(--text-dim); font-family: var(--mono) }

/* ── Modal ── */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  z-index: 210; /* above .drawer (200), matching the original stacking order */
  background: rgba(0, 0, 0, .5);
  backdrop-filter: blur(2px);
}
.modal.open { display: grid }
.modal-card {
  width: min(680px, 96vw);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0, 0, 0, .35);
}
.modal-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-card);
}
.modal-hd strong { font-size: 16px; font-weight: 700; color: var(--text) }
.modal-bd { padding: 20px }
.modal-ft {
  padding: 14px 20px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  background: var(--bg-card);
}

/* ── Cron builder ── */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px }
.chip {
  height: 32px;
  padding: 0 13px;
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--sans);
}
.chip:hover { border-color: var(--teal); color: var(--teal-bright) }
.chip.active { background: var(--teal-soft); color: var(--teal-bright); border-color: transparent }

.section {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
  margin: 0 0 12px;
}
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px }
@media (max-width: 520px) {
  .row-2, .row-3 { grid-template-columns: 1fr }
}

.preview {
  margin-top: 10px;
  padding: 10px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: var(--bg-input);
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-dim);
}
.preview .cron { font-weight: 700; color: var(--text) }

/* ── Toast ── */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 13px;
  display: none;
  z-index: 220; /* above .modal (210) — toasts fire from actions inside drawers/modals */
  box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
}

/* ── Scrollbars ── */
.drawer-bd, .modal-bd, .sidebar {
  scrollbar-width: thin;
  scrollbar-color: var(--border-subtle) transparent;
}
.drawer-bd::-webkit-scrollbar,
.modal-bd::-webkit-scrollbar,
.sidebar::-webkit-scrollbar { width: 6px }
.drawer-bd::-webkit-scrollbar-track,
.modal-bd::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track { background: transparent }
.drawer-bd::-webkit-scrollbar-thumb,
.modal-bd::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb { background: var(--border-subtle); border-radius: 3px }

/* ── Empty state ── */
.empty {
  padding: 40px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
}

/* ── Mobile ── */
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: var(--hdr-height); z-index: 150 }
}
@media (max-width: 640px) {
  .wrap { margin: 16px auto }
  .btn-row { flex-direction: column }
  .sb-main { padding: 20px 16px 40px }
}
