:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --border: #dde1e8;
  --text: #161a22;
  --muted: #5f6878;
  --accent: #1f8f55;
  --accent-text: #ffffff;
  --danger: #c4372f;
  --ok: #1f8f55;
  --warn: #b7791f;
  --term-bg: #0f1218;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1016;
    --surface: #161a22;
    --surface-2: #1e2430;
    --border: #2a3140;
    --text: #e8ebf1;
    --muted: #949db0;
    --accent: #3fbf7a;
    --accent-text: #08130d;
    --danger: #ef6a61;
    --ok: #3fbf7a;
    --warn: #e0a84a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1016; --surface: #161a22; --surface-2: #1e2430; --border: #2a3140;
  --text: #e8ebf1; --muted: #949db0; --accent: #3fbf7a; --accent-text: #08130d;
  --danger: #ef6a61; --ok: #3fbf7a; --warn: #e0a84a; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: .92em; }

/* ---------- layout */
.page {
  max-width: 760px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 32px);
}
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 18px; letter-spacing: -.01em; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 8px; background: #181c25;
  display: grid; place-items: center; color: #7ee0a1; font: 700 14px var(--mono);
}
.spacer { flex: 1; }
.section-title {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 28px 0 10px; font-size: 13px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
}

/* ---------- surfaces */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.stack > * + * { margin-top: 10px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

/* ---------- buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px;
  border-radius: 11px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 550;
  transition: transform .06s ease, background .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 9px; }
.btn.block { width: 100%; }
.btn.big { min-height: 54px; font-size: 17px; border-radius: 14px; }

label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 550; }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  outline: none;
}
.input:focus { border-color: var(--accent); }
textarea.input { min-height: 90px; font-family: var(--mono); font-size: 13px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

/* ---------- auth screens */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth .card { width: 100%; max-width: 380px; padding: 28px 22px; }
.auth h1 { margin: 14px 0 6px; font-size: 24px; letter-spacing: -.02em; }
.auth .logo.big { width: 56px; height: 56px; border-radius: 15px; font-size: 22px; margin: 0 auto; }

/* ---------- sandbox list */
.sb { display: flex; flex-direction: column; gap: 12px; }
.sb-head { display: flex; align-items: center; gap: 10px; }
.sb-name { font-weight: 620; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-id { font: 12px var(--mono); color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.running { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.dot.restarting, .dot.created { background: var(--warn); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 12.5px; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.sb-actions { display: flex; gap: 8px; }
.sb-actions .btn.primary { flex: 1; }
.empty { padding: 34px 16px; text-align: center; }
.meter { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent); }

/* ---------- sheet (modal) */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(5, 8, 14, .45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
  animation: fade .15s ease;
}
.sheet {
  width: 100%; max-width: 520px; max-height: 92vh; overflow: auto;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(env(safe-area-inset-bottom) + 18px);
  animation: up .2s ease;
}
@media (min-width: 640px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 20px; }
}
.sheet h2 { margin: 2px 0 14px; font-size: 19px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); opacity: .6; } }

.menu { display: flex; flex-direction: column; }
.menu .btn { justify-content: flex-start; border: 0; border-radius: 10px; }

/* ---------- copy box */
.copybox {
  display: flex; gap: 8px; align-items: stretch;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 6px;
}
.copybox code { flex: 1; padding: 6px 6px; overflow-x: auto; white-space: nowrap; align-self: center; }
.copybox.wrap code { white-space: pre-wrap; word-break: break-all; }

/* ---------- toast */
#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-weight: 550; max-width: calc(100% - 32px); transition: all .2s ease; z-index: 100;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); color: #fff; }

/* ---------- terminal */
.term-page {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  background: var(--term-bg); color: #e8ebf1;
  height: 100dvh;
}
.term-bar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 6px) 10px 6px;
  border-bottom: 1px solid #1f2533; background: #12161e;
}
.term-bar .btn { background: transparent; border-color: #2a3140; color: #e8ebf1; min-height: 36px; }
.term-title { font: 600 14px var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-status { font-size: 12px; color: #949db0; }
.term-wrap { flex: 1; min-height: 0; padding: 6px 4px 0 8px; }
.term-wrap .xterm { height: 100%; }
.keybar {
  display: flex; gap: 6px; overflow-x: auto; padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  background: #12161e; border-top: 1px solid #1f2533; scrollbar-width: none;
}
.keybar::-webkit-scrollbar { display: none; }
.key {
  flex: none; min-width: 44px; height: 38px; padding: 0 10px;
  border-radius: 9px; border: 1px solid #2a3140; background: #1b212c; color: #e8ebf1;
  font: 600 14px var(--mono); cursor: pointer;
}
.key.on { background: #3fbf7a; color: #08130d; border-color: #3fbf7a; }
@media (hover: hover) and (pointer: fine) { .keybar { display: none; } }
