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

:root {
  --sidebar-w: 220px;
  --sidebar-bg: #0f1117;
  --sidebar-text: #c9d1d9;
  --sidebar-active: #58a6ff;
  --primary: #238636;
  --primary-hover: #2ea043;
  --danger: #da3633;
  --danger-hover: #f85149;
  --warning: #d29922;
  --info: #1f6feb;
  --bg: #0d1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  --accent: var(--info);
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
}

/* #46: Skip-to-content ─────────────────────────────────────────────── */
.skip-to-content {
  position: absolute;
  top: -100%;
  left: 0;
  z-index: 1000;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  border-radius: 0 0 var(--radius) 0;
  transition: top .2s;
}
.skip-to-content:focus { top: 0; }

/* #48: Focus-visible ───────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
:focus:not(:focus-visible) { outline: none; }

/* ── Sidebar ───────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s ease;
}

.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.sidebar-header .subtitle {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.nav-links {
  list-style: none;
  padding: 8px 0;
  flex: 1;
}

.nav-links li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s;
}

.nav-links li a:hover {
  background: rgba(255,255,255,.05);
  color: var(--text);
}

.nav-links li a.active {
  color: var(--sidebar-active);
  border-left-color: var(--sidebar-active);
  background: rgba(88,166,255,.08);
  font-weight: 500;
}

.nav-icon { font-size: 15px; width: 18px; text-align: center; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
}

.daemon-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 20px;
  font-weight: 500;
}
.daemon-badge.on  { background: rgba(35,134,54,.2); color: #3fb950; }
.daemon-badge.off { background: rgba(218,54,51,.15); color: #f85149; }
.daemon-badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.btn-logout {
  display: block;
  margin-top: 10px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: color .2s, border-color .2s;
}
.btn-logout:hover {
  color: #f85149;
  border-color: #f85149;
}

/* #39: Hamburger menu ──────────────────────────────────────────────── */
.hamburger {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 110;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 22px;
  width: 40px;
  height: 40px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 99;
}
.sidebar-overlay.active { display: block; }

/* ── Main content ──────────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar h2 { font-size: 18px; font-weight: 600; }
.topbar p  { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

.content { padding: 24px; flex: 1; }

/* ── Alerts / Flash ────────────────────────────────────────────────── */
.alerts { padding: 0 24px; margin-top: 16px; }

.alert {
  position: relative;
  padding: 10px 36px 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  font-size: 13px;
  border: 1px solid;
}
.alert-success { background: rgba(35,134,54,.15); border-color: #238636; color: #3fb950; }
.alert-error   { background: rgba(218,54,51,.15);  border-color: #da3633; color: #f85149; }
.alert-info    { background: rgba(31,111,235,.15);  border-color: #1f6feb; color: #58a6ff; }
.alert-warning { background: rgba(210,153,34,.15);  border-color: #d29922; color: #e3b341; }

/* #43: Flash close button + auto-dismiss */
.alert-close {
  position: absolute;
  top: 6px;
  right: 6px;
  background: none;
  border: none;
  color: inherit;
  font-size: 18px;
  cursor: pointer;
  opacity: .5;
  line-height: 1;
  padding: 2px 6px;
  border-radius: var(--radius);
}
.alert-close:hover { opacity: 1; }

@keyframes alertFadeOut {
  to { opacity: 0; transform: translateY(-8px); }
}
.alert-dismiss { animation: alertFadeOut .4s ease forwards; }

/* ── Cards ─────────────────────────────────────────────────────────── */
.cards { display: grid; gap: 16px; }
.cards-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.cards-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.card-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}

.card-sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* Daemon status card */
.status-big {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
}

.dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-green { background: #3fb950; box-shadow: 0 0 8px #3fb950; }
.dot-red   { background: #f85149; }
.dot-gray  { background: var(--text-muted); }

/* ── Account cards ──────────────────────────────────────────────────── */
.account-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.account-name { font-weight: 600; font-size: 15px; }
.account-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.account-meta { font-size: 12px; color: var(--text-muted); margin-top: 8px; }
.account-meta span { margin-right: 12px; }

.account-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── Badges ─────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
}
.badge-green { background: rgba(35,134,54,.2); color: #3fb950; }
.badge-red   { background: rgba(218,54,51,.15); color: #f85149; }
.badge-gray  { background: rgba(139,148,158,.15); color: var(--text-muted); }
.badge-blue  { background: rgba(31,111,235,.15); color: #58a6ff; }

/* ── Buttons ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-secondary:hover { background: rgba(255,255,255,.05); }

.btn-sm { padding: 4px 10px; font-size: 12px; }

/* #42: Button loading state */
.btn.loading {
  pointer-events: none;
  opacity: .6;
}
.btn.loading::after {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: btnSpin .6s linear infinite;
  margin-left: 6px;
}
@keyframes btnSpin { to { transform: rotate(360deg); } }

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

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}

.label-hint { font-size: 11px; color: var(--text-muted); font-weight: 400; margin-left: 6px; }

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  transition: border-color .15s;
  appearance: none;
}

/* #53: Select dropdown arrow after appearance:none */
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b949e' d='M6 8.825L1.175 4 2.238 2.938 6 6.7l3.763-3.763L10.825 4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--info);
  box-shadow: 0 0 0 3px rgba(31,111,235,.2);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* Inline add form */
.inline-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
}

.inline-form-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.inline-form-row .form-group { flex: 1; margin-bottom: 0; }

/* ── Table ──────────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

table { width: 100%; border-collapse: collapse; }

th {
  background: rgba(255,255,255,.03);
  padding: 10px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 16px;
  font-size: 13px;
  border-bottom: 1px solid rgba(48,54,61,.5);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.02); }

/* ── Logs panel ─────────────────────────────────────────────────────── */
.log-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

#log-output {
  background: #0a0a0a;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  height: 520px;
  overflow-y: auto;
  color: #c9d1d9;
}

.log-line { display: flex; gap: 10px; }
.log-time  { color: #6e7681; flex-shrink: 0; }
.log-level { width: 52px; flex-shrink: 0; font-weight: 600; }
.log-level.INFO    { color: #58a6ff; }
.log-level.WARNING { color: #e3b341; }
.log-level.ERROR   { color: #f85149; }
.log-level.DEBUG   { color: #6e7681; }
.log-msg   { color: #e6edf3; }

.log-empty { color: var(--text-muted); font-style: italic; padding: 8px 0; }

/* ── Info box ───────────────────────────────────────────────────────── */
.info-box {
  background: rgba(31,111,235,.1);
  border: 1px solid rgba(31,111,235,.3);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 20px;
}

.info-box strong { color: #58a6ff; }
.info-box code {
  background: rgba(255,255,255,.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 12px;
}

/* ── Section header ─────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}

.section-header h3 { font-size: 15px; font-weight: 600; }

/* ── Stats row ──────────────────────────────────────────────────────── */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 24px; }

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}

.stat-value { font-size: 24px; font-weight: 700; }
.stat-label { font-size: 11px; color: var(--text-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: .4px; }

/* #49: Status icons beyond color ───────────────────────────────────── */
.status-icon { font-size: 14px; margin-right: 2px; }

/* #51: Fetch error indicator ───────────────────────────────────────── */
.fetch-error {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: rgba(218,54,51,.15);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  color: #f85149;
  font-size: 12px;
}

/* #45: Sync history ────────────────────────────────────────────────── */
.sync-history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(48,54,61,.5);
  font-size: 13px;
  gap: 12px;
  flex-wrap: wrap;
}
.sync-history-item:last-child { border-bottom: none; }

/* ── Utilities ──────────────────────────────────────────────────────── */
.mt-0  { margin-top: 0; }
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-10 { margin-top: 10px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }
.mt-30 { margin-top: 30px; }
.mb-0  { margin-bottom: 0; }
.mb-8  { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }
.gap-8  { gap: 8px; }
.gap-10 { gap: 10px; }
.gap-20 { gap: 20px; }
.flex   { display: flex; }
.flex-gap { gap: 10px; }
.flex-wrap { flex-wrap: wrap; }
.text-center { text-align: center; }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.fw-600  { font-weight: 600; }
.d-block { display: block; }
.d-inline { display: inline; }
.p-40   { padding: 40px; }
.muted  { color: var(--text-muted); }
.text-green  { color: #3fb950; }
.text-red    { color: #f85149; }
.text-yellow { color: #e3b341; }
.color-link  { color: #58a6ff; }

/* ── Responsive ─────────────────────────────────────────────────────── */

/* #39/#40: Mobile ≤640px */
@media (max-width: 640px) {
  .hamburger { display: flex; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .topbar { padding: 14px 16px 14px 56px; }
  .content { padding: 16px; }
  .alerts { padding: 0 16px; }
  .form-row { grid-template-columns: 1fr; }
  .inline-form-row { flex-direction: column; }
  .cards-2 { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .status-big { flex-direction: column; align-items: flex-start; }
  .account-card { flex-direction: column; }

  /* #40: Table → cards on mobile */
  .table-wrap { background: none; border: none; border-radius: 0; }
  .table-wrap table,
  .table-wrap thead,
  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap th,
  .table-wrap td { display: block; }
  .table-wrap thead { display: none; }
  .table-wrap tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 10px;
  }
  .table-wrap td {
    padding: 4px 0;
    border-bottom: none;
  }
  .table-wrap td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    display: block;
    margin-bottom: 2px;
  }
  .table-wrap td:last-child { margin-top: 8px; }
  #log-output { height: 360px; }
}

/* #41: Tablet 641px–1024px */
@media (min-width: 641px) and (max-width: 1024px) {
  :root { --sidebar-w: 190px; }
  .content { padding: 20px; }
  .cards-2 { grid-template-columns: 1fr; }
}

/* #41: Wide desktop ≥1400px */
@media (min-width: 1400px) {
  .content { max-width: 1200px; }
  .cards-2 { grid-template-columns: 1fr 1fr; }
}
