:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-hover: #256abf;
  --accent-wash: rgba(42, 120, 214, 0.10);
  --track: #cde2fb;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --critical-wash: rgba(208, 59, 59, 0.08);
  --warning-wash: rgba(250, 178, 25, 0.12);
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "DejaVu Sans Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-hover: #5598e7;
    --accent-wash: rgba(57, 135, 229, 0.14);
    --track: #184f95;
    --critical-wash: rgba(208, 59, 59, 0.14);
    --warning-wash: rgba(250, 178, 25, 0.10);
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-hover: #5598e7;
  --accent-wash: rgba(57, 135, 229, 0.14);
  --track: #184f95;
  --critical-wash: rgba(208, 59, 59, 0.14);
  --warning-wash: rgba(250, 178, 25, 0.10);
  --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* Düğmeler ve form */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 9px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn.danger { background: var(--critical); color: #fff; }
.btn.danger-ghost { background: transparent; color: var(--critical); border-color: var(--border); }
.btn.danger-ghost:hover { background: var(--critical-wash); }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; height: 42px; }
.btn:focus-visible, .icon-btn:focus-visible, input:focus-visible, textarea:focus-visible, .seg button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink); cursor: pointer; font: inherit;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); }
.icon-btn.small { width: 30px; height: 30px; border-color: transparent; background: transparent; color: var(--ink-2); }
.icon-btn.small:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#theme-btn svg { fill: currentColor; stroke: none; }
.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.field { display: grid; gap: 6px; margin: 0 0 14px; border: 0; padding: 0; min-width: 0; }
.field > span, .field legend { font-size: 13px; font-weight: 600; color: var(--ink-2); padding: 0; margin-bottom: 6px; }
.field > span { margin-bottom: 0; }
.field em { font-style: normal; font-weight: 400; color: var(--muted); }
input, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--page);
  border: 1px solid var(--axis); border-radius: 9px; padding: 9px 11px;
}
textarea { font-family: var(--mono); font-size: 12px; resize: vertical; min-height: 100px; }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--critical); }
.err { color: var(--critical); font-size: 12px; min-height: 0; }
.err:empty { display: none; }
.hint { color: var(--muted); font-size: 12px; }
.form-error { background: var(--critical-wash); color: var(--ink); border-left: 3px solid var(--critical); padding: 9px 12px; border-radius: 6px; margin-bottom: 14px; font-size: 13px; }

/* Segmentli kontrol */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: 10px; border: 1px solid var(--border); }
.seg button, .seg label span {
  display: inline-block; border: 0; background: transparent; color: var(--ink-2); font: inherit; font-weight: 550;
  padding: 6px 12px; border-radius: 7px; cursor: pointer;
}
.seg button[aria-selected="true"], .seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Üst çubuk */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 34px; height: 34px; padding: 6px; border-radius: 9px; background: var(--accent); fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.brand-name { font-weight: 650; font-size: 16px; letter-spacing: -0.01em; }
.brand-name span { color: var(--muted); font-weight: 500; }
.brand-sub { color: var(--ink-2); font-size: 12px; }
.top-right { display: flex; align-items: center; gap: 10px; }
.user { display: flex; align-items: center; gap: 10px; padding-left: 10px; border-left: 1px solid var(--border); }
.user-mail { color: var(--ink-2); font-size: 13px; }

/* Yerleşim */
.wrap { max-width: 1320px; margin: 0 auto; padding: 24px 24px 40px; display: grid; gap: 18px; }
.grid { display: grid; gap: 16px; }
.summary { grid-template-columns: repeat(4, 1fr); }
.card { position: relative; min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px; box-shadow: var(--shadow); }
.tile .label { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 13px; }
.tile .value { font-size: 30px; font-weight: 640; letter-spacing: -0.02em; margin-top: 4px; }
.label { color: var(--ink-2); font-size: 13px; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.toolbar-right { display: flex; gap: 10px; flex: 1; justify-content: flex-end; min-width: 240px; }
.search { max-width: 300px; background: var(--surface); height: 36px; }

/* Durum rozeti */
.status { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.status i { display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; color: #fff; font-style: normal; font-size: 11px; font-weight: 700; flex: none; }
.status.good i { background: var(--good); }
.status.warning i { background: var(--warning); color: #0b0b0b; }
.status.critical i { background: var(--critical); }
.status.pending i { background: var(--axis); color: var(--ink); }

/* Sunucu kartları */
.servers { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.server { display: flex; flex-direction: column; gap: 4px; padding: 16px 18px 18px; }
.server.off { border-color: color-mix(in srgb, var(--critical) 35%, var(--border)); }
.server-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.server-actions { display: flex; gap: 2px; margin-right: -6px; }
.server-name { font-size: 17px; font-weight: 640; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.server-addr { font-family: var(--mono); font-size: 12.5px; color: var(--ink-2); overflow-wrap: anywhere; }
.server-meta { font-size: 12px; min-height: 18px; }
.server-meta .note { color: var(--ink-2); margin-top: 2px; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 12px; }
.metric-top { display: flex; justify-content: space-between; align-items: baseline; gap: 4px; font-size: 12px; color: var(--ink-2); }
.metric-top b { color: var(--ink); font-size: 15px; font-weight: 640; }
.metric-sub { font-size: 11px; color: var(--muted); margin-top: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meter { margin-top: 6px; height: 6px; border-radius: 999px; background: var(--track); overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--accent); transition: width 0.5s ease; }
.meter span.warning { background: var(--warning); }
.meter span.critical { background: var(--critical); }
.spark-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; font-size: 11px; }
.spark-row > span { white-space: nowrap; }
.card-spark { flex: 1; height: 28px; min-width: 0; }
.card-spark path { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.spark-empty { flex: 1; font-size: 11px; }
.card-msg { margin-top: 12px; padding: 10px 12px; border-radius: 8px; font-size: 13px; background: var(--surface-2); color: var(--ink); border-left: 3px solid var(--axis); }
.card-msg.warning { background: var(--warning-wash); border-left-color: var(--warning); }
.card-msg.critical { background: var(--critical-wash); border-left-color: var(--critical); }
.card-msg.muted { color: var(--muted); }
.facts { display: flex; gap: 18px; margin: 14px 0 14px; padding-top: 12px; border-top: 1px solid var(--grid); flex-wrap: wrap; }
.facts div { min-width: 0; }
.facts dt { font-size: 11px; color: var(--muted); }
.facts dd { margin: 0; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.btn.connect { margin-top: auto; height: 42px; background: var(--accent); color: var(--accent-ink); letter-spacing: 0.06em; font-weight: 700; }
.btn.connect:hover { background: var(--accent-hover); }
.btn.connect svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.btn.connect.disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }

.empty { display: grid; justify-items: center; gap: 10px; text-align: center; padding: 48px 20px; }
.empty svg { width: 56px; height: 56px; fill: none; stroke: var(--accent); stroke-width: 2; }
.empty svg circle { fill: var(--accent); stroke: none; }
.empty p { max-width: 420px; margin: 0 0 6px; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 4px 0; }

/* Diyaloglar */
.dialog {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0;
  border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--ink);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
}
.dialog.narrow { width: min(420px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(10, 10, 10, 0.45); backdrop-filter: blur(2px); }
.dialog form { display: flex; flex-direction: column; max-height: calc(100dvh - 34px); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--grid); }
.dlg-head h2, .dialog h2 { font-size: 17px; }
.dlg-head .icon-btn { border-color: transparent; }
.dlg-body { padding: 18px 20px 4px; overflow-y: auto; }
.dlg-body > h2 { margin-bottom: 8px; }
.dlg-foot { display: flex; gap: 10px; align-items: center; padding: 14px 20px; border-top: 1px solid var(--grid); }
.dialog.narrow .dlg-foot { border-top: 0; padding-top: 8px; }
.spacer { flex: 1; }
.row { display: flex; gap: 12px; }
.row .grow { flex: 1; }
.row .port { width: 100px; }
.hostkey { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px; margin-bottom: 14px; border-radius: 9px; background: var(--surface-2); }
.hostkey code { font-family: var(--mono); font-size: 11.5px; color: var(--ink-2); overflow-wrap: anywhere; }
.small-note { font-size: 12px; margin: 0 0 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 100;
  background: var(--ink); color: var(--page); padding: 10px 16px; border-radius: 10px; font-size: 13px; font-weight: 550;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); max-width: calc(100vw - 32px);
}

/* Giriş sayfası */
.login-body { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--accent-wash), transparent 70%), var(--page); }
.login-wrap { width: 100%; max-width: 400px; display: grid; gap: 20px; }
.login-brand { display: flex; align-items: center; gap: 12px; justify-content: center; }
.login-card { padding: 28px; }
.login-card h1 { font-size: 22px; letter-spacing: -0.02em; }
.login-card > p { margin: 4px 0 22px; }
.pw { position: relative; }
.pw input { padding-right: 76px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: transparent; color: var(--accent); font: inherit; font-size: 12px; font-weight: 600; padding: 6px 8px; cursor: pointer; border-radius: 6px; }
.login-foot { text-align: center; font-size: 12px; margin: 0; }

/* Terminal sayfası */
.term-body { height: 100dvh; display: flex; flex-direction: column; background: #0d0d0d; color: #e8e7e1; overflow: hidden; }
.term-bar {
  display: flex; align-items: center; gap: 12px; flex: none;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 16px 8px; background: #1a1a19; border-bottom: 1px solid #2c2c2a;
}
.term-back { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; color: #c3c2b7; }
.term-back:hover { background: #2c2c2a; color: #fff; }
.term-back svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.term-title { min-width: 0; flex: 1; }
.term-name { font-weight: 640; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.term-addr { font-family: var(--mono); font-size: 12px; color: #898781; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.term-state { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: #c3c2b7; padding: 4px 10px; border: 1px solid #383835; border-radius: 999px; white-space: nowrap; }
.term-state i { width: 8px; height: 8px; border-radius: 50%; background: #898781; }
.term-state.on i { background: var(--good); }
.term-state.wait i { background: var(--warning); animation: blink 1s infinite; }
.term-state.off i { background: var(--critical); }
@keyframes blink { 50% { opacity: 0.3; } }
.term-tools { display: flex; gap: 6px; }
.term-btn { height: 30px; padding: 0 10px; border-radius: 8px; border: 1px solid #383835; background: #232321; color: #e8e7e1; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; }
.term-btn:hover { background: #2c2c2a; }
.term-wrap { flex: 1; min-height: 0; padding: 10px 6px calc(6px + env(safe-area-inset-bottom, 0px)) 12px; }
#terminal { height: 100%; }

@media (max-width: 900px) {
  .summary { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .topbar, .wrap { padding-left: 16px; padding-right: 16px; }
  .brand-sub, .user-mail { display: none; }
  .user { padding-left: 0; border-left: 0; }
  .servers { grid-template-columns: 1fr; }
  .toolbar-right { min-width: 0; width: 100%; }
  .search { max-width: none; }
  .seg { width: 100%; overflow-x: auto; }
  .seg button { flex: 1; padding: 6px 8px; }
  #add-btn { padding: 0 10px; }
  .term-addr { display: none; }
  .term-bar { gap: 8px; padding-left: 8px; padding-right: 8px; }
}
@media (max-width: 380px) {
  .metrics { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .spin, .term-state.wait i { animation: none; }
  .meter span { transition: none; }
}
