/* OpenRSC panel: one dark workspace, no external assets. */

:root {
  color-scheme: dark;
  --bg: #0e1013;
  --bg-raised: #16191e;
  --bg-sunken: #0a0c0f;
  --sidebar: #131619;
  --line: #262b32;
  --line-soft: #1d2229;
  --ink: #e8eaed;
  --ink-muted: #9aa3ad;
  --ink-faint: #6b7480;
  --accent: #4f9cf9;
  --accent-strong: #2f7fe0;
  --accent-ink: #06121f;
  --danger: #f2555a;
  --danger-strong: #d63b40;
  --ok: #3fbf7f;
  --radius: 10px;
  --radius-sm: 7px;
  --sidebar-width: 268px;
  --topbar-height: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, "Liberation Mono", monospace;
  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

/* The panel toggles views with the hidden attribute, and several of those
   elements also carry display: grid/flex.  Without this rule that display
   wins and a "hidden" panel keeps taking up layout space, which pushed the
   topbar wider than the viewport. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

button, input, textarea { font: inherit; color: inherit; }

/* ---------- boot + gate ---------- */

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
}

.spinner {
  width: 26px;
  height: 26px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
}

.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
}

.gate-card {
  width: min(380px, 100%);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 26px 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.gate-title {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.01em;
}

.gate-subtitle {
  margin: 4px 0 22px;
  color: var(--ink-muted);
  font-size: 13px;
}

.field { display: block; margin-bottom: 16px; }

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.field-input {
  width: 100%;
  padding: 11px 12px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
}

.field-input:focus-visible,
.composer-input:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 156, 249, 0.22); }

/* ---------- buttons ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.button:hover { background: #1e2229; }
.button:active { transform: translateY(1px); }
.button:disabled { opacity: 0.5; cursor: not-allowed; }

.button.primary {
  background: var(--accent);
  border-color: var(--accent-strong);
  color: var(--accent-ink);
  font-weight: 600;
}

.button.primary:hover { background: var(--accent-strong); color: #fff; }
.button.ghost { background: transparent; }
.button.subtle { min-height: 34px; padding: 0 11px; font-size: 13px; background: transparent; }
.button.subtle:hover { background: #1e2229; }
.button.danger { color: var(--danger); border-color: #3a2427; }
.button.danger:hover { background: #2a1a1c; }
.button.block { width: 100%; }

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  font-size: 16px;
}

.icon-button:hover { background: #1e2229; color: var(--ink); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- shell ---------- */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  height: 100%;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: calc(14px + var(--safe-top)) 12px calc(14px + var(--safe-bottom)) calc(12px + var(--safe-left));
  background: var(--sidebar);
  border-right: 1px solid var(--line);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
}

.brand { font-weight: 600; letter-spacing: 0.04em; }
.sidebar-close { display: none; }

.tabs {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-right: 2px;
}

.tab {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 40px;
  padding: 0 8px 0 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  text-align: left;
}

.tab:hover { background: #1b1f25; color: var(--ink); }
.tab[aria-current="true"] { background: #1e242c; border-color: var(--line); color: var(--ink); }

.tab-dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: var(--ok);
}

.tab-dot.stopped { background: var(--ink-faint); }

.tab-name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.tab-close {
  flex: none;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--ink-faint);
  cursor: pointer;
}

.tab-close:hover { background: #2a2f37; color: var(--ink); }

.views { display: flex; gap: 6px; }

.view-link {
  flex: 1 1 0;
  min-height: 34px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  font-size: 13px;
}

.view-link[aria-current="true"] { background: #1e242c; color: var(--ink); border-color: var(--line); }

.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line-soft);
}

.meta { margin: 0; font-size: 12px; color: var(--ink-faint); overflow-wrap: anywhere; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid #2f4a2f;
  border-radius: 999px;
  background: #14251a;
  color: var(--ok);
  font-size: 11px;
  letter-spacing: 0.04em;
}

/* ---------- workspace ---------- */

.workspace {
  display: grid;
  /* minmax(0, 1fr) on both axes: without it the auto-sized column is measured
     from the file table's min-content width and the whole workspace grows
     wider than the viewport on a phone. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: var(--topbar-height) minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 calc(12px + var(--safe-right)) 0 12px;
  padding-top: var(--safe-top);
  height: calc(var(--topbar-height) + var(--safe-top));
  border-bottom: 1px solid var(--line);
  background: var(--bg-raised);
}

#menu { display: none; }

.topbar-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* min-width: 0 lets the button row shrink and scroll inside itself instead of
   pushing the topbar past the viewport on a narrow window. */
.topbar-actions { display: flex; min-width: 0; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.topbar-actions::-webkit-scrollbar { display: none; }

.panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
}

.terminal-empty {
  display: none;
  place-content: center;
  justify-items: center;
  gap: 14px;
  color: var(--ink-muted);
}

.panel[data-empty="true"] .terminal-empty { display: grid; }
.panel[data-empty="true"] .terminal-output,
.panel[data-empty="true"] .composer { display: none; }

.terminal-output {
  margin: 0;
  padding: 16px calc(18px + var(--safe-right)) 16px 18px;
  overflow: auto;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.55;
  background: var(--bg);
  color: #d7dde5;
  tab-size: 4;
}

.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
  padding: 10px calc(14px + var(--safe-right)) calc(12px + var(--safe-bottom)) 14px;
  border-top: 1px solid var(--line);
  background: var(--bg-raised);
}

.composer-caret {
  padding-bottom: 10px;
  color: var(--accent);
  font-family: var(--mono);
}

.composer-input {
  min-height: 42px;
  max-height: 180px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-sunken);
  font-family: var(--mono);
  font-size: 13.5px;
  resize: none;
  outline: none;
}

.composer-send { min-height: 42px; }

/* ---------- files ---------- */

.files { grid-template-rows: auto minmax(0, 1fr) auto auto; }

.crumbs {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
  color: var(--ink-muted);
}

.crumb {
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
}

.crumb:hover { background: #1b2028; }
.crumb-sep { color: var(--ink-faint); }

.dropzone { overflow: auto; min-width: 0; min-height: 0; position: relative; }
.dropzone.dragging { outline: 2px dashed var(--accent); outline-offset: -8px; }

.file-table { width: 100%; border-collapse: collapse; font-size: 14px; }

.file-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 9px 12px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}

.file-table td { padding: 8px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.file-table tr:hover td { background: #14181d; }

.cell-check { width: 38px; }
.cell-size { width: 110px; text-align: right; white-space: nowrap; }
.cell-time { width: 170px; white-space: nowrap; color: var(--ink-muted); }
.cell-actions { width: 190px; text-align: right; white-space: nowrap; }

.name-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  padding: 2px 0;
  overflow-wrap: anywhere;
}

.name-button:hover { color: var(--accent); }
.glyph { flex: none; color: var(--ink-faint); font-family: var(--mono); }

.empty-note { padding: 24px 14px; color: var(--ink-faint); }

.file-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: var(--bg-raised);
}

.file-bar .meta { flex: 1 1 auto; }

.uploads {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 14px calc(10px + var(--safe-bottom));
  background: var(--bg-raised);
}

.uploads:empty { display: none; }

.upload {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 10px;
  padding: 8px 0;
  font-size: 13px;
}

.upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-state { color: var(--ink-muted); font-size: 12px; }
.upload-state.failed { color: var(--danger); }

.progress {
  grid-column: 1 / -1;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.progress-value {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.2s ease;
}

/* ---------- modal, toasts ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: calc(20px + var(--safe-top)) 16px calc(20px + var(--safe-bottom));
  background: rgba(4, 6, 9, 0.7);
}

.modal-card {
  display: flex;
  flex-direction: column;
  width: min(760px, 100%);
  max-height: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 10px 12px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-title { margin: 0; font-size: 15px; overflow-wrap: anywhere; }
.modal-body { padding: 16px; overflow: auto; min-height: 0; }

.modal-body pre {
  margin: 0;
  font-family: var(--mono);
  font-size: 13px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.modal-body img { max-width: 100%; border-radius: var(--radius-sm); }
.modal-body .field { margin: 0; }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

.notice { margin: 14px 0 0; font-size: 13px; }
.notice.error { color: var(--danger); }

.toasts {
  position: fixed;
  z-index: 50;
  right: calc(14px + var(--safe-right));
  bottom: calc(14px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 28px));
}

.toast {
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  font-size: 13px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  overflow-wrap: anywhere;
}

.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }

.scrim {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(4, 6, 9, 0.6);
}

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    position: fixed;
    z-index: 30;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(300px, 86vw);
    transform: translateX(-102%);
    transition: transform 0.2s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
  }

  .shell[data-menu="open"] .sidebar { transform: translateX(0); }
  .sidebar-close { display: inline-grid; }
  #menu { display: inline-grid; }

  .cell-time { display: none; }
  .cell-actions { width: auto; }
  .cell-actions .button { padding: 0 8px; }
}

@media (max-width: 620px) {
  .cell-size { display: none; }
  .topbar-title { font-size: 14px; }
  .button.subtle { min-height: 36px; }
  .composer { grid-template-columns: auto minmax(0, 1fr); }
  .composer-send { grid-column: 2; }
  .composer-caret { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .progress-value { transition: none; }
}

@media (min-width: 1800px) {
  .terminal-output, .crumbs, .file-table, .file-bar, .uploads { max-width: 1600px; }
  .terminal-output, .composer { justify-self: stretch; }
}
