:root {
  color-scheme: dark;
  --bg: #090d11;
  --surface: #11171d;
  --surface-2: #171f27;
  --surface-3: #202a34;
  --line: #28343e;
  --line-strong: #3a4854;
  --text: #edf2f5;
  --muted: #8e9aa5;
  --accent: #f5a623;
  --accent-2: #d9850b;
  --green: #42d392;
  --red: #ff6b6b;
  --blue: #65b7ff;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { min-height: 100vh; margin: 0; background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.auth-screen {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(420px, 0.85fr);
  min-height: 100vh;
}

.auth-hero {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
  padding: clamp(40px, 8vw, 120px);
  background:
    linear-gradient(120deg, rgba(8, 12, 16, 0.94), rgba(8, 12, 16, 0.55)),
    radial-gradient(circle at 70% 30%, rgba(245, 166, 35, 0.2), transparent 32%),
    repeating-linear-gradient(135deg, transparent 0 24px, rgba(255,255,255,.018) 25px 26px);
  border-right: 1px solid var(--line);
}

.auth-hero::after {
  content: "";
  position: absolute;
  right: -180px;
  bottom: -180px;
  width: 520px;
  height: 520px;
  border: 1px solid rgba(245, 166, 35, 0.2);
  border-radius: 50%;
  box-shadow: 0 0 0 70px rgba(245, 166, 35, 0.035), 0 0 0 140px rgba(245, 166, 35, 0.02);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  margin-bottom: 36px;
  border: 1px solid var(--accent);
  border-radius: 16px 4px 16px 4px;
  background: rgba(245, 166, 35, 0.08);
  color: var(--accent);
  font-weight: 900;
  letter-spacing: -0.08em;
}

.brand-mark.small { width: 42px; height: 42px; margin: 0; border-radius: 10px 3px 10px 3px; font-size: .8rem; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: .68rem; font-weight: 800; letter-spacing: .18em; }
.auth-hero h1 { max-width: 760px; margin: 0; font-size: clamp(2.6rem, 6vw, 5.8rem); line-height: .95; letter-spacing: -.06em; }
.auth-copy { max-width: 620px; margin: 28px 0; color: #b8c1c8; font-size: clamp(1rem, 1.7vw, 1.25rem); line-height: 1.65; }
.auth-features { display: flex; flex-wrap: wrap; gap: 10px; }
.auth-features span { padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: 999px; background: rgba(17,23,29,.72); color: #cbd3d8; font-size: .78rem; }
.auth-panel { display: grid; place-items: center; padding: clamp(24px, 6vw, 80px); background: var(--surface); }
.auth-card { width: min(100%, 430px); }
.auth-card h2 { margin: 0 0 8px; font-size: 2rem; letter-spacing: -.04em; }
.auth-card .muted { margin-bottom: 32px; }

label { display: grid; gap: 8px; margin-bottom: 18px; color: #b8c2ca; font-size: .78rem; font-weight: 700; letter-spacing: .02em; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
  background: #0c1116;
  color: var(--text);
  transition: border-color .2s, box-shadow .2s;
}
input, select { height: 46px; padding: 0 13px; }
textarea { min-height: 110px; padding: 13px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(245,166,35,.12); }
small { color: var(--muted); font-weight: 400; }
.muted { color: var(--muted); }
.form-error { min-height: 20px; margin: 8px 0; color: var(--red); font-size: .8rem; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 800;
  font-size: .78rem;
  cursor: pointer;
  transition: transform .15s, background .2s, border-color .2s;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.button.primary { background: var(--accent); color: #171008; }
.button.primary:hover { background: #ffb53b; }
.button.ghost { border-color: var(--line); background: var(--surface-2); color: var(--text); }
.button.danger { border-color: rgba(255,107,107,.35); background: rgba(255,107,107,.1); color: #ff9a9a; }
.button.full { width: 100%; margin-top: 10px; }
.button.compact { min-height: 36px; padding: 0 13px; }
.icon-button { border: 0; background: transparent; color: var(--muted); font-size: .74rem; font-weight: 800; cursor: pointer; }
.icon-button:hover { color: var(--text); }

.app-shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  border-right: 1px solid var(--line);
  background: #0b1015;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; height: 82px; padding: 0 22px; border-bottom: 1px solid var(--line); }
.sidebar-brand strong, .sidebar-brand span { display: block; }
.sidebar-brand strong { font-size: .92rem; }
.sidebar-brand span { margin-top: 2px; color: var(--muted); font-size: .62rem; letter-spacing: .14em; }
.main-nav { display: grid; gap: 5px; padding: 24px 12px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 45px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #929da6;
  text-align: left;
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { border-color: rgba(245,166,35,.22); background: rgba(245,166,35,.09); color: var(--accent); }
.nav-icon { display: grid; place-items: center; width: 24px; height: 24px; border: 1px solid currentColor; border-radius: 5px; font-size: .55rem; }
.sidebar-user { display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 10px; margin-top: auto; padding: 17px; border-top: 1px solid var(--line); }
.sidebar-user strong, .sidebar-user span { display: block; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user strong { font-size: .78rem; }
.sidebar-user span { margin-top: 2px; color: var(--muted); font-size: .65rem; }
.avatar { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; background: var(--surface-3); color: var(--accent); font-weight: 900; }

.workspace { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 82px;
  padding: 14px clamp(18px, 3vw, 42px);
  border-bottom: 1px solid var(--line);
  background: rgba(9, 13, 17, .92);
  backdrop-filter: blur(12px);
}
.topbar h1 { margin: 0; font-size: 1.35rem; letter-spacing: -.03em; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.connection-pill { display: inline-flex; align-items: center; gap: 8px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: .7rem; }
.connection-pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.connection-pill.online i { background: var(--green); box-shadow: 0 0 12px var(--green); }
.view-container { min-height: calc(100vh - 82px); padding: clamp(18px, 3vw, 42px); outline: none; }
.view-header { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.view-header h2 { margin: 0; font-size: 1.45rem; letter-spacing: -.035em; }
.view-header p { margin: 6px 0 0; color: var(--muted); font-size: .82rem; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.metric-card, .panel, .server-card, .item-card {
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(255,255,255,.02) inset;
}
.metric-card { position: relative; overflow: hidden; min-height: 132px; padding: 19px; }
.metric-card::after { content: ""; position: absolute; right: -25px; bottom: -30px; width: 90px; height: 90px; border: 1px solid rgba(245,166,35,.14); transform: rotate(45deg); }
.metric-card span { color: var(--muted); font-size: .7rem; font-weight: 800; letter-spacing: .08em; }
.metric-card strong { display: block; margin-top: 20px; font-size: 2rem; letter-spacing: -.05em; }
.metric-card small { display: block; margin-top: 4px; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, .7fr); gap: 14px; margin-top: 14px; }
.panel { min-width: 0; padding: 20px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.panel-header h3 { margin: 0; font-size: .92rem; }
.quick-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.action-card { min-height: 98px; padding: 15px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); text-align: left; cursor: pointer; }
.action-card:hover { border-color: var(--accent); }
.action-card strong, .action-card span { display: block; }
.action-card strong { margin-bottom: 8px; font-size: .82rem; }
.action-card span { color: var(--muted); font-size: .7rem; line-height: 1.5; }

.activity-list { display: grid; gap: 1px; }
.activity-row { display: grid; grid-template-columns: 10px minmax(0,1fr) auto; gap: 10px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.activity-row:last-child { border-bottom: 0; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.status-dot.failed { background: var(--red); }
.activity-row strong, .activity-row span { display: block; }
.activity-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .76rem; }
.activity-row span, .activity-row time { color: var(--muted); font-size: .65rem; }

.toolbar { display: grid; grid-template-columns: minmax(240px, 1fr) minmax(180px, 260px) auto; gap: 10px; margin-bottom: 18px; }
.search-field { position: relative; }
.search-field input { padding-left: 38px; }
.search-field::before { content: ""; position: absolute; left: 14px; top: 15px; width: 10px; height: 10px; border: 2px solid var(--muted); border-radius: 50%; }
.search-field::after { content: ""; position: absolute; left: 25px; top: 27px; width: 7px; height: 2px; background: var(--muted); transform: rotate(45deg); }
.result-count { align-self: center; color: var(--muted); font-size: .72rem; white-space: nowrap; }
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.item-card { display: flex; flex-direction: column; min-width: 0; overflow: hidden; transition: transform .18s, border-color .18s; }
.item-card:hover { transform: translateY(-2px); border-color: var(--line-strong); }
.item-image { --item-image-pad: 14px; --item-image-pad-double: 28px; position: relative; display: grid; flex: 0 0 160px; place-items: center; height: 160px; overflow: hidden; background: #0c1116; }
.item-image::after { content: ""; position: absolute; inset: 8px; border: 1px solid rgba(255,255,255,.025); pointer-events: none; }
.item-image img { position: absolute; inset: var(--item-image-pad); width: calc(100% - var(--item-image-pad-double)); height: calc(100% - var(--item-image-pad-double)); object-fit: contain; filter: drop-shadow(0 12px 15px rgba(0,0,0,.35)); }
.no-image { color: #56616a; font-size: .72rem; }
.item-body { display: flex; flex: 1; flex-direction: column; padding: 14px; }
.item-category { color: var(--accent); font-size: .6rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.item-body h3 { min-height: 38px; margin: 7px 0 5px; overflow-wrap: anywhere; font-size: .9rem; line-height: 1.35; }
.item-body code { overflow: hidden; color: var(--muted); font-size: .67rem; text-overflow: ellipsis; white-space: nowrap; }
.item-actions { display: flex; gap: 7px; margin-top: 14px; }
.item-actions .button { flex: 1; min-height: 36px; }
.warning-badge { position: absolute; top: 10px; right: 10px; padding: 4px 6px; border: 1px solid rgba(245,166,35,.28); border-radius: 5px; background: rgba(9,13,17,.82); color: var(--accent); font-size: .55rem; font-weight: 800; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 24px; }
.pagination span { color: var(--muted); font-size: .72rem; }

.server-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 13px; }
.server-card { padding: 18px; }
.server-top { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.server-card h3 { margin: 0 0 5px; font-size: 1rem; }
.server-address { color: var(--muted); font-family: ui-monospace, monospace; font-size: .7rem; }
.server-status { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: .62rem; text-transform: uppercase; }
.server-status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.server-status.online { color: var(--green); }
.server-status.offline { color: var(--red); }
.server-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 20px 0; }
.server-meta div { padding: 10px; border-radius: 7px; background: var(--surface-2); }
.server-meta span, .server-meta strong { display: block; }
.server-meta span { color: var(--muted); font-size: .6rem; }
.server-meta strong { margin-top: 4px; font-size: .72rem; }
.server-actions { display: flex; flex-wrap: wrap; gap: 7px; }

.terminal { overflow: hidden; border: 1px solid var(--line); border-radius: 11px; background: #070a0d; box-shadow: var(--shadow); }
.terminal-bar { display: flex; align-items: center; justify-content: space-between; padding: 11px 14px; border-bottom: 1px solid var(--line); background: var(--surface); }
.terminal-dots { display: flex; gap: 6px; }
.terminal-dots i { width: 8px; height: 8px; border-radius: 50%; background: #505b64; }
.terminal-dots i:first-child { background: var(--red); }
.terminal-dots i:nth-child(2) { background: var(--accent); }
.terminal-dots i:last-child { background: var(--green); }
.terminal-output { min-height: 360px; max-height: 56vh; overflow: auto; padding: 18px; color: #b9c5cd; font: .78rem/1.65 ui-monospace, "Cascadia Code", monospace; white-space: pre-wrap; }
.terminal-output .prompt { color: var(--accent); }
.terminal-output .error { color: var(--red); }
.terminal-form { display: grid; grid-template-columns: 220px minmax(0, 1fr) auto; gap: 8px; padding: 12px; border-top: 1px solid var(--line); background: #0b1014; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: .74rem; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: .62rem; letter-spacing: .08em; text-transform: uppercase; }
td code { color: var(--accent); }
tr:last-child td { border-bottom: 0; }
.role-badge { padding: 4px 7px; border: 1px solid var(--line); border-radius: 999px; color: var(--blue); font-size: .6rem; text-transform: uppercase; }

.empty-state { display: grid; place-items: center; min-height: 300px; padding: 40px; border: 1px dashed var(--line-strong); border-radius: 11px; color: var(--muted); text-align: center; }
.empty-state strong { display: block; margin-bottom: 8px; color: var(--text); }
.loading { display: grid; place-items: center; min-height: 300px; color: var(--muted); font-size: .8rem; }

.modal {
  width: min(720px, calc(100vw - 30px));
  max-height: calc(100vh - 30px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(2,5,8,.78); backdrop-filter: blur(4px); }
.modal-card { padding: clamp(18px, 4vw, 30px); }
.modal-card.narrow { max-width: 560px; }
.modal-header { display: flex; align-items: start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.modal-header h2 { margin: 0 0 5px; letter-spacing: -.03em; }
.modal-header code { color: var(--muted); font-size: .72rem; }
.modal-header .close-dialog { font-size: .9rem; }
.spawn-item-preview { display: grid; grid-template-columns: 90px minmax(0,1fr); align-items: center; gap: 15px; margin-bottom: 22px; padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: #0c1116; }
.preview-image { display: grid; place-items: center; height: 76px; }
.preview-image img { width: auto; height: auto; max-width: 100%; max-height: 100%; object-fit: contain; }
.spawn-item-preview code { display: block; margin-top: 7px; overflow-wrap: anywhere; color: var(--accent); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.coordinate-grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }
.security-note { margin: 4px 0 16px; padding: 11px; border-left: 3px solid var(--green); background: rgba(66,211,146,.07); color: #a9cbbc; font-size: .7rem; line-height: 1.5; }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: grid; gap: 8px; width: min(380px, calc(100vw - 36px)); }
.toast { padding: 13px 15px; border: 1px solid var(--line-strong); border-left: 3px solid var(--green); border-radius: 8px; background: #172019; box-shadow: var(--shadow); font-size: .76rem; animation: toast-in .2s ease-out; }
.toast.error { border-left-color: var(--red); background: #221719; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.mobile-nav { display: none; }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 82px minmax(0,1fr); }
  .sidebar-brand { justify-content: center; padding: 0; }
  .sidebar-brand > div:last-child, .nav-item span:last-child, .sidebar-user > div:nth-child(2), .sidebar-user .icon-button { display: none; }
  .main-nav { padding-inline: 10px; }
  .nav-item { justify-content: center; padding: 0; }
  .sidebar-user { display: flex; justify-content: center; padding: 17px 0; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  body { padding-bottom: 68px; }
  .auth-screen { grid-template-columns: 1fr; }
  .auth-hero { min-height: 36vh; padding: 34px 24px; border-right: 0; border-bottom: 1px solid var(--line); }
  .auth-hero .brand-mark { width: 48px; height: 48px; margin-bottom: 22px; font-size: .75rem; }
  .auth-hero h1 { font-size: clamp(2.2rem, 13vw, 3.7rem); }
  .auth-copy { margin: 18px 0; font-size: .9rem; }
  .auth-panel { padding: 32px 24px 50px; }
  .app-shell { display: block; }
  .sidebar { display: none; }
  .topbar { min-height: 72px; padding: 12px 16px; }
  .topbar .eyebrow { display: none; }
  .topbar h1 { font-size: 1.1rem; }
  .connection-pill { display: none; }
  .spawn-shortcut { min-height: 36px; font-size: .68rem; }
  .view-container { min-height: calc(100vh - 140px); padding: 17px 14px 28px; }
  .view-header { align-items: start; margin-bottom: 18px; }
  .view-header h2 { font-size: 1.2rem; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .metric-card { min-height: 110px; padding: 14px; }
  .metric-card strong { margin-top: 15px; font-size: 1.55rem; }
  .panel { padding: 15px; }
  .toolbar { grid-template-columns: 1fr; }
  .toolbar select { width: 100%; }
  .item-grid { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
  .item-image { --item-image-pad: 10px; --item-image-pad-double: 20px; flex-basis: 122px; height: 122px; }
  .item-body { padding: 11px; }
  .item-body h3 { min-height: 34px; font-size: .78rem; }
  .item-actions .button { font-size: .68rem; padding: 0 8px; }
  .server-grid { grid-template-columns: 1fr; }
  .terminal-output { min-height: 300px; }
  .terminal-form { grid-template-columns: 1fr; }
  .form-grid, .coordinate-grid { grid-template-columns: 1fr; }
  .modal { width: calc(100vw - 16px); max-height: calc(100vh - 16px); }
  .spawn-item-preview { grid-template-columns: 68px minmax(0,1fr); }
  .modal-actions { position: sticky; bottom: -18px; margin-inline: -18px; padding: 12px 18px 18px; background: var(--surface); }
  .mobile-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    height: 68px;
    border-top: 1px solid var(--line);
    background: rgba(9,13,17,.97);
    backdrop-filter: blur(12px);
  }
  .mobile-nav button { display: grid; place-items: center; align-content: center; gap: 4px; border: 0; background: transparent; color: var(--muted); font-size: .58rem; font-weight: 800; }
  .mobile-nav button span { display: grid; place-items: center; width: 22px; height: 22px; border: 1px solid currentColor; border-radius: 5px; font-size: .5rem; }
  .mobile-nav button.active { color: var(--accent); }
}

@media (max-width: 430px) {
  .metric-grid { grid-template-columns: 1fr; }
  .quick-actions { grid-template-columns: 1fr; }
  .item-grid { grid-template-columns: 1fr 1fr; }
  .item-image { flex-basis: 108px; height: 108px; }
  .item-category { font-size: .52rem; }
  .item-body code { font-size: .58rem; }
}
