@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --bg: #14110e;
  --surface: #1d1815;
  --surface-raised: #241e19;
  --line: #332b23;
  --text: #ede6dc;
  --text-muted: #9c9184;
  --copper: #e3672b;
  --copper-dim: #7a3c1c;
  --steel: #7c93a6;
  --ember: #6fa86a;
  --rust: #b23b2e;
  --radius: 6px;
  --font-ui: 'Space Grotesk', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Consolas', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
}

body {
  background-image:
    radial-gradient(ellipse 900px 500px at 15% -10%, rgba(227,103,43,0.08), transparent 60%),
    radial-gradient(ellipse 700px 500px at 100% 0%, rgba(124,147,166,0.06), transparent 60%);
  background-attachment: fixed;
}

a { color: inherit; }

button {
  font-family: var(--font-ui);
  cursor: pointer;
}

::selection { background: var(--copper-dim); color: #fff; }

/* ---------- scrollbars ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--copper-dim); }

/* ================= LOGIN ================= */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 28px;
  position: relative;
  overflow: hidden;
}

.login-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--copper), transparent 80%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.brand-mark {
  width: 34px; height: 34px;
  border-radius: 4px;
  background: linear-gradient(145deg, var(--copper), var(--copper-dim));
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-weight: 600;
  color: #1a1310;
  font-size: 15px;
}

.brand-name {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.2px;
}
.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: 1px;
}

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
}
.field input:focus {
  outline: none;
  border-color: var(--copper);
}

.btn {
  border: 1px solid var(--line);
  background: var(--surface-raised);
  color: var(--text);
  border-radius: 4px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  transition: border-color .12s ease, transform .05s ease;
}
.btn:hover { border-color: var(--copper); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--steel); outline-offset: 2px; }

.btn-primary {
  width: 100%;
  background: linear-gradient(145deg, var(--copper), var(--copper-dim));
  border: none;
  color: #1a1310;
  font-weight: 700;
  padding: 11px 16px;
}
.btn-primary:hover { filter: brightness(1.08); }

.login-error {
  margin-top: 14px;
  font-size: 13px;
  color: var(--rust);
  display: none;
}

/* ================= DASHBOARD SHELL ================= */

.shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
}

.sidebar .brand { padding: 0 6px 24px; margin: 0; border-bottom: 1px solid var(--line); margin-bottom: 18px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  margin-bottom: 2px;
}
.nav-item:hover { color: var(--text); }
.nav-item.active {
  color: var(--copper);
  background: rgba(227,103,43,0.08);
  border-color: rgba(227,103,43,0.25);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--text-muted);
}
.sidebar-footer .who { color: var(--text); font-weight: 500; margin-bottom: 8px; }
.sidebar-footer button { width: 100%; }

.main {
  padding: 22px 28px;
  overflow-y: auto;
  max-height: 100vh;
}

.view { display: none; }
.view.active { display: block; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.status-pill.online .status-dot { background: var(--ember); box-shadow: 0 0 8px var(--ember); }
.status-pill.offline .status-dot { background: var(--rust); }
.status-pill.starting .status-dot, .status-pill.stopping .status-dot {
  background: var(--copper); animation: pulse 1s infinite;
}
@keyframes pulse { 50% { opacity: .35; } }

.stat-row {
  display: flex;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}
.stat-row b { color: var(--text); }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.ctrl-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 4px;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.03);
}
.ctrl-btn:hover:not(:disabled) { border-color: var(--copper); }
.ctrl-btn:active:not(:disabled) { transform: translateY(1px); }
.ctrl-btn:disabled { opacity: .35; cursor: not-allowed; }
.ctrl-btn .dot { width: 7px; height: 7px; border-radius: 2px; }
.ctrl-btn.start .dot { background: var(--ember); }
.ctrl-btn.stop .dot { background: var(--steel); }
.ctrl-btn.restart .dot { background: var(--copper); }
.ctrl-btn.kill .dot { background: var(--rust); }
.ctrl-btn.port .dot { background: var(--text-muted); }

/* ---------- console ---------- */

.console-wrap {
  background: #0f0d0b;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.console-log {
  height: 58vh;
  overflow-y: auto;
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.console-log .l-panel { color: var(--copper); }
.console-log .l-cmd { color: var(--steel); }
.console-log .l-err { color: var(--rust); }
.console-log .l-line { color: var(--text); opacity: 0.92; }

.console-input-row {
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.console-input-row .prompt {
  padding: 10px 12px;
  color: var(--copper);
  font-family: var(--font-mono);
}
.console-input-row input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 10px 8px 10px 0;
}
.console-input-row input:focus { outline: none; }
.console-input-row button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 0 16px;
  font-size: 12px;
}
.console-input-row button:hover { color: var(--copper); }

h1.page-title {
  font-size: 18px;
  margin: 0 0 4px;
}
.page-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 20px;
  font-family: var(--font-mono);
}

/* ---------- users view ---------- */

.panel-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
}

table.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.users-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
table.users-table td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.role-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 3px;
  border: 1px solid var(--line);
}
.role-badge.admin { color: var(--copper); border-color: var(--copper-dim); }
.role-badge.user { color: var(--steel); }

.perm-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.perm-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  border: 1px solid var(--line);
  padding: 2px 6px;
  border-radius: 3px;
}
.perm-tag.on { color: var(--ember); border-color: var(--ember); }

.row-actions { display: flex; gap: 8px; }
.link-btn {
  background: none; border: none; color: var(--steel);
  font-size: 12px; padding: 0;
}
.link-btn.danger { color: var(--rust); }
.link-btn:hover { text-decoration: underline; }

/* ---------- modal ---------- */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(10,8,6,0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: 100%; max-width: 420px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}
.modal h3 { margin: 0 0 16px; font-size: 15px; }
.modal .field input, .modal .field select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 9px 10px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
}
.modal .perm-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 14px;
  margin: 12px 0 18px;
}
.perm-check {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-muted);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

.toast-stack {
  position: fixed;
  bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 60;
}
.toast {
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-left: 3px solid var(--steel);
  padding: 10px 14px;
  border-radius: 4px;
  font-size: 12.5px;
  max-width: 320px;
}
.toast.error { border-left-color: var(--rust); }
.toast.success { border-left-color: var(--ember); }

/* ================= MOBILE ================= */
/* Sidebar → fixed top bar (brand + logout) + fixed bottom tab bar for nav.
   Modal → bottom sheet anchored to the viewport, not a floating centered box. */

.mobile-topbar,
.tabbar {
  display: none;
}

@media (max-width: 780px) {
  .shell { display: block; }

  .sidebar { display: none; }

  .mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 56px;
    padding: 0 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    z-index: 40;
  }
  .mobile-topbar .brand { margin: 0; }
  .mobile-topbar .brand-mark { width: 28px; height: 28px; font-size: 12px; }
  .mobile-topbar .brand-name { font-size: 14px; }
  .mobile-topbar .brand-sub { display: none; }
  .mobile-topbar button {
    border: 1px solid var(--line);
    background: var(--surface-raised);
    color: var(--text-muted);
    border-radius: 4px;
    padding: 7px 12px;
    font-size: 12px;
  }

  .tabbar {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
    z-index: 40;
    gap: 4px;
  }
  .tabbar .nav-item {
    flex: 1;
    justify-content: center;
    text-align: center;
    margin: 0;
    padding: 9px 6px;
  }

  .main {
    max-height: none;
    padding: 70px 14px calc(78px + env(safe-area-inset-bottom, 0px));
  }

  .topbar { gap: 10px; }
  .stat-row {
    width: 100%;
    justify-content: space-between;
    font-size: 11px;
  }

  .controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .ctrl-btn { justify-content: center; }

  .console-log { height: 48vh; font-size: 12px; }

  table.users-table { font-size: 12px; }
  table.users-table th:nth-child(3),
  table.users-table td:nth-child(3) { display: none; } /* права — только в карточке редактирования */
  .users-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* ---- modal as a bottom sheet ---- */
  .modal-backdrop {
    align-items: flex-end;
    background: rgba(10,8,6,0.78);
  }
  .modal {
    max-width: none;
    width: 100%;
    max-height: 88vh;
    overflow-y: auto;
    border-radius: 14px 14px 0 0;
    border-bottom: none;
    padding: 20px 18px calc(20px + env(safe-area-inset-bottom, 0px));
  }
  .modal .perm-grid { grid-template-columns: 1fr; }
  .modal::before {
    content: '';
    display: block;
    width: 36px; height: 4px;
    background: var(--line);
    border-radius: 2px;
    margin: -6px auto 14px;
  }
  .modal-actions {
    position: sticky;
    bottom: 0;
    background: var(--surface-raised);
    padding-top: 12px;
    margin-top: 4px;
  }
  .modal-actions .btn { flex: 1; }

  .toast-stack {
    left: 14px; right: 14px; bottom: 84px;
  }
  .toast { max-width: none; }
}
