/* ap-portal — minimal stylesheet, no framework */

/* ── Variables ─────────────────────────────────────────────────────────── */
:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.1);

  /* Zone colours */
  --mgt-bg: #e0e7ff; --mgt-text: #3730a3;
  --pro-bg: #dcfce7; --pro-text: #166534;
  --stg-bg: #fef9c3; --stg-text: #854d0e;
  --dev-bg: #f1f5f9; --dev-text: #334155;

  /* Status colours */
  --connected-bg: #dcfce7; --connected-text: #166534;
  --disconnected-bg: #fee2e2; --disconnected-text: #991b1b;
  --waiting-bg: #f1f5f9; --waiting-text: #334155;
  --running-bg: #dbeafe; --running-text: #1e40af;
  --success-bg: #dcfce7; --success-text: #166534;
  --error-bg: #fee2e2; --error-text: #991b1b;
  --revoked-bg: #fee2e2; --revoked-text: #991b1b;
  --active-bg: #dcfce7; --active-text: #166534;

  --bg: #f8fafc;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --link: #2563eb;

  /* Sidebar */
  --sidebar-bg: #0f172a;
  --sidebar-w: 220px;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
a { color: var(--link); }
h1,h2,h3,h4 { margin: 0 0 .5rem; font-weight: 600; }
p { margin: 0 0 1rem; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .5rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
td:last-child { white-space: nowrap; }
button, .btn { cursor: pointer; font-family: var(--font); font-size: .875rem; border: 1px solid var(--border); border-radius: var(--radius); padding: .375rem .875rem; background: var(--card-bg); color: var(--text); transition: background .12s, border-color .12s; text-decoration: none; display: inline-flex; align-items: center; gap: .375rem; }
button:hover, .btn:hover { background: #f1f5f9; border-color: #cbd5e1; }
.btn-sm { font-size: .8125rem; padding: .25rem .625rem; }
.btn-primary { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; }
.btn-danger { background: #ef4444; color: #fff; border-color: #ef4444; }
.btn-danger:hover { background: #dc2626; border-color: #dc2626; }
.btn-secondary { background: var(--card-bg); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f1f5f9; }
input, textarea, select { font-family: var(--font); font-size: .9375rem; border: 1px solid var(--border); border-radius: var(--radius); padding: .375rem .625rem; width: 100%; }
input:focus, textarea:focus, select:focus { outline: 2px solid #2563eb; outline-offset: 1px; border-color: transparent; }
textarea { font-family: var(--mono); font-size: .8125rem; resize: vertical; }
code { font-family: var(--mono); }

/* ── Sidebar layout ─────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 1.125rem 1rem .875rem;
  font-weight: 700;
  font-size: 1.0625rem;
  letter-spacing: -.01em;
  border-bottom: 1px solid #1e293b;
  margin-bottom: .375rem;
}
.sidebar-brand a { color: #f8fafc; text-decoration: none; }
.sidebar-brand a span { color: #60a5fa; }

.sidebar-nav { flex: 1; padding: .25rem 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .4375rem .75rem;
  font-size: .875rem;
  color: #94a3b8;
  text-decoration: none;
  border-radius: var(--radius);
  margin: 1px .5rem;
  transition: background .1s, color .1s;
}
.nav-item svg { flex-shrink: 0; opacity: .7; }
.nav-item:hover { background: #1e293b; color: #e2e8f0; }
.nav-item:hover svg { opacity: 1; }
.nav-item.active { background: #1e3a8a; color: #93c5fd; }
.nav-item.active svg { opacity: 1; }

.nav-section {
  padding: .875rem 1.25rem .25rem;
  font-size: .6875rem;
  font-weight: 700;
  color: #334155;
  text-transform: uppercase;
  letter-spacing: .1em;
}

.nav-sub {
  padding-left: 1.75rem;
  font-size: .8125rem;
  margin-left: .5rem;
}

.sidebar-footer {
  padding: .875rem 1rem;
  border-top: 1px solid #1e293b;
  font-size: .75rem;
  color: #334155;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main { flex: 1; min-width: 0; overflow-x: hidden; }
.main-content { max-width: 1080px; padding: 1.75rem 2rem; }

/* ── Flash messages ─────────────────────────────────────────────────────── */
.flash { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1.25rem; font-size: .875rem; }
.flash-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.flash-ok { background: #dcfce7; color: #166534; border: 1px solid #86efac; }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 1.25rem; box-shadow: var(--shadow); }
.card + .card, .card.mt2 { margin-top: 1rem; }
.card-title { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; }
.page-title { font-size: 1.375rem; font-weight: 700; margin-bottom: 1.5rem; color: var(--text); }

/* ── Zone badges ────────────────────────────────────────────────────────── */
.badge { display: inline-block; font-size: .6875rem; font-weight: 600; border-radius: 999px; padding: .15rem .6rem; letter-spacing: .01em; }
.badge-mgt { background: var(--mgt-bg); color: var(--mgt-text); }
.badge-pro { background: var(--pro-bg); color: var(--pro-text); }
.badge-stg { background: var(--stg-bg); color: var(--stg-text); }
.badge-dev { background: var(--dev-bg); color: var(--dev-text); }
.badge-connected { background: var(--connected-bg); color: var(--connected-text); }
.badge-disconnected { background: var(--disconnected-bg); color: var(--disconnected-text); }
.badge-active { background: var(--active-bg); color: var(--active-text); }
.badge-revoked { background: var(--revoked-bg); color: var(--revoked-text); }
.badge-waiting { background: var(--waiting-bg); color: var(--waiting-text); }
.badge-running { background: var(--running-bg); color: var(--running-text); }
.badge-success { background: var(--success-bg); color: var(--success-text); }
.badge-error { background: var(--error-bg); color: var(--error-text); }

/* ── Services grid ──────────────────────────────────────────────────────── */
.zone-section { margin-bottom: 2rem; }
.zone-header { display: flex; align-items: center; gap: .625rem; margin-bottom: .875rem; }
.zone-header h2 { font-size: 1.0625rem; font-weight: 600; }
.services-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .75rem; }
.service-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: .875rem 1rem; text-decoration: none; color: var(--text); transition: box-shadow .15s, border-color .15s, transform .1s; display: block; }
.service-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.08); border-color: #93c5fd; transform: translateY(-1px); }
.service-card-name { font-weight: 600; font-size: .9375rem; margin-bottom: .25rem; }
.service-card-desc { font-size: .8125rem; color: var(--text-muted); }

/* ── Diagnostics panel ──────────────────────────────────────────────────── */
.diag-section { margin-bottom: 1.25rem; }
.diag-section h4 { font-size: .875rem; font-weight: 600; color: var(--text-muted); margin-bottom: .5rem; }
.diag-cmd { display: flex; align-items: center; gap: .5rem; background: #0f172a; color: #e2e8f0; border-radius: var(--radius); padding: .5rem .75rem; margin-bottom: .375rem; font-family: var(--mono); font-size: .8125rem; }
.diag-cmd-text { flex: 1; white-space: pre; overflow-x: auto; }
.copy-btn { flex-shrink: 0; font-size: .75rem; font-family: var(--font); padding: .2rem .5rem; background: #334155; color: #e2e8f0; border: none; border-radius: 4px; cursor: pointer; transition: background .15s; }
.copy-btn:hover { background: #475569; }
.copy-btn.copied { background: #166534; color: #bbf7d0; }

/* ── Tabs ───────────────────────────────────────────────────────────────── */
.tab-bar { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin: -.25rem -1.25rem 1.25rem; padding: 0 1.25rem; }
.tab-btn { background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0; padding: .625rem 1rem; font-size: .9375rem; font-weight: 500; color: var(--text-muted); cursor: pointer; margin-bottom: -1px; transition: color .12s, border-color .12s; }
.tab-btn:hover { color: var(--text); background: none; }
.tab-btn.active { color: #2563eb; border-bottom-color: #2563eb; }
.tab-panel { }
.ssh-intro { color: var(--text-muted); font-size: .9375rem; margin-bottom: 1rem; }
.ssh-keygen-hint { font-size: .875rem; color: var(--text-muted); line-height: 1.7; background: #f8fafc; border: 1px solid var(--border); border-radius: var(--radius); padding: .875rem 1rem; margin-bottom: 1.25rem; }
.ssh-keygen-hint code:not(.oneliner) { background: #e2e8f0; padding: .1rem .35rem; border-radius: 4px; font-size: .8125rem; }
.os-tab-bar { display: flex; gap: .375rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.os-tab-btn { background: #f1f5f9; border: 1px solid var(--border); border-radius: var(--radius); padding: .375rem .875rem; font-size: .875rem; font-weight: 500; color: var(--text-muted); cursor: pointer; display: inline-flex; align-items: center; gap: .375rem; transition: background .12s, color .12s, border-color .12s; }
.os-tab-btn:hover { background: #e2e8f0; color: var(--text); }
.os-tab-btn.active { background: #2563eb; color: #fff; border-color: #2563eb; }
.oneliner-row { display: flex; align-items: center; gap: .5rem; background: #0f172a; border-radius: var(--radius); padding: .625rem .875rem; }
.oneliner { flex: 1; color: #e2e8f0; font-size: .8125rem; white-space: nowrap; overflow-x: auto; background: none; }

/* ── Network page ───────────────────────────────────────────────────────── */
.vpn-intro { display: flex; gap: .875rem; align-items: flex-start; background: #eff6ff; border: 1px solid #bfdbfe; border-left: 3px solid #2563eb; border-radius: var(--radius); padding: .875rem 1rem; margin-bottom: 1.25rem; color: #1e3a8a; font-size: .9375rem; line-height: 1.5; }
.vpn-intro strong { display: block; font-size: .9375rem; margin-bottom: .2rem; }
.vpn-intro p { margin: 0; color: #1e40af; font-size: .875rem; }
.vpn-intro-ssh { background: #f0fdf4; border-color: #bbf7d0; border-left-color: #16a34a; color: #14532d; }
.vpn-intro-ssh p { color: #166534; }
.setup-section-header { display: flex; align-items: center; gap: .5rem; font-size: .8125rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin: 1.25rem 0 .875rem; padding-bottom: .5rem; border-bottom: 1px solid var(--border); }
.tunnel-table { width: 100%; margin-bottom: .5rem; table-layout: fixed; }
.tunnel-table th { font-size: .75rem; }
.col-device  { width: 110px; }
.col-dns     { width: 150px; }
.col-pubkey  { /* fills remaining space */ }
.col-ipv6    { width: 150px; }
.col-status  { width: 36px; }
.col-actions { width: 100px; }
.tunnel-edit { font-size: .875rem; font-weight: 500; border: 1px solid transparent; border-bottom: 1px dashed var(--border); border-radius: 0; padding: .2rem .4rem; width: 100%; background: transparent; cursor: text; transition: border-color .15s, background .15s, border-radius .15s; }
.tunnel-edit:hover { border: 1px solid var(--border); border-radius: var(--radius); background: var(--card-bg); }
.tunnel-edit:focus { border: 1px solid #2563eb; border-radius: var(--radius); background: var(--card-bg); outline: none; }
.tunnel-edit-slug { font-family: var(--mono); font-size: .8125rem; font-weight: 400; }
.tunnel-edit-error { border-color: #ef4444 !important; background: #fff1f2 !important; }
.pubkey-full { font-size: .7rem; color: var(--text-muted); cursor: pointer; word-break: break-all; display: block; }
.pubkey-full:hover { color: var(--text); }
.mono-xs { font-family: var(--mono); font-size: .7rem; }
.status-cell { text-align: center; padding-left: .25rem; padding-right: .25rem; }
.status-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; }
.status-dot.status-connected { background: #22c55e; box-shadow: 0 0 0 2px #bbf7d0; }
.status-dot.status-seen      { background: #94a3b8; box-shadow: 0 0 0 2px #e2e8f0; }
.status-dot.status-never     { background: #94a3b8; box-shadow: 0 0 0 2px #e2e8f0; }
.tunnel-actions { display: flex; gap: .375rem; align-items: center; justify-content: flex-end; padding-right: .25rem; }
.tunnel-delete-btn { display: flex; align-items: center; justify-content: center; width: 26px; height: 26px; border: none; border-radius: var(--radius); background: transparent; color: var(--text-muted); cursor: pointer; opacity: 0; transition: opacity .15s, color .12s, background .12s; padding: 0; }
.tunnel-row:hover .tunnel-delete-btn { opacity: 1; }
.tunnel-delete-btn:hover { color: #dc2626; background: #fee2e2; }
.tunnel-save-btn { display: flex; align-items: center; justify-content: center; width: 26px; height: 26px; border: none; border-radius: var(--radius); background: transparent; color: var(--text-muted); cursor: default; opacity: 0; pointer-events: none; transition: opacity .15s, color .12s, background .12s; padding: 0; }
.tunnel-save-btn.dirty { opacity: 1; pointer-events: auto; cursor: pointer; color: #2563eb; }
.tunnel-save-btn.dirty:hover { color: #1d4ed8; background: #dbeafe; }
.section-divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0 1rem; }
.section-label { font-size: .8125rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .875rem; }
.vpn-status { display: flex; align-items: center; gap: 1rem; padding: .5rem 0; }
.vpn-status-label { font-size: 1rem; font-weight: 600; }
.download-btns { display: flex; gap: .75rem; flex-wrap: wrap; margin: 1rem 0; }
.download-os-btn { font-size: .9375rem; padding: .5rem 1.1rem; gap: .5rem; }
.dl-ext { font-size: .8rem; opacity: .75; font-weight: 400; }
.download-hint { font-size: .875rem; color: var(--text-muted); line-height: 1.6; }
.download-hint code { background: #f1f5f9; padding: .1rem .35rem; border-radius: 4px; font-size: .8125rem; }
.token-display { margin-top: 1.25rem; padding: .875rem 1rem; background: #f8fafc; border: 1px solid var(--border); border-radius: var(--radius); }
.token-label { font-size: .8125rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.token-row { display: flex; gap: .5rem; margin: .5rem 0 .25rem; align-items: center; }
.token-input { font-family: var(--mono); font-size: .8125rem; background: #fff; flex: 1; min-width: 0; }
.token-hint { font-size: .8rem; color: var(--text-muted); }

/* ── SSH keys ───────────────────────────────────────────────────────────── */
.key-list { list-style: none; margin: 0; padding: 0; }
.key-item { display: flex; align-items: center; gap: .75rem; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.key-item:last-child { border-bottom: none; }
.key-label { font-weight: 500; }
.key-fp { font-family: var(--mono); font-size: .75rem; color: var(--text-muted); }
.key-date { font-size: .8125rem; color: var(--text-muted); margin-left: auto; white-space: nowrap; }
.add-key-form { margin-top: .875rem; display: flex; flex-direction: column; gap: .5rem; }
.form-row { display: flex; gap: .5rem; align-items: flex-end; flex-wrap: wrap; }
.form-row input { flex: 1; min-width: 150px; }

/* ── Table helpers ──────────────────────────────────────────────────────── */
.row-actions { display: flex; gap: .375rem; flex-wrap: wrap; }
.mono-sm { font-family: var(--mono); font-size: .75rem; }

/* ── Playbook run status ─────────────────────────────────────────────────── */
.run-status { display: inline-flex; align-items: center; gap: .5rem; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: #2563eb; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utility ────────────────────────────────────────────────────────────── */
.mt1 { margin-top: .5rem; }
.mt2 { margin-top: 1rem; }
.mt3 { margin-top: 1.5rem; }
.text-muted { color: var(--text-muted); }
.empty-state { text-align: center; padding: 2rem; color: var(--text-muted); font-size: .9375rem; }
.warning-banner { background: #fef9c3; border: 1px solid #fde047; border-radius: var(--radius); padding: .625rem 1rem; font-size: .875rem; color: #854d0e; margin-bottom: 1rem; }
.error-card { background: #fee2e2; border: 1px solid #fca5a5; border-radius: var(--radius); padding: 1rem; color: #991b1b; }

/* ── Mobile ─────────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 0 .5rem; }
  .sidebar-brand { border-bottom: none; padding: .75rem .5rem; }
  .sidebar-nav { display: flex; flex-wrap: wrap; padding: 0 0 .5rem; gap: .125rem; }
  .nav-section { display: none; }
  .nav-sub { padding-left: .75rem; }
  .sidebar-footer { display: none; }
  .main-content { padding: 1.25rem; }
}
