/* ── Design tokens ─────────────────────────────────── */
:root {
  color-scheme: light;

  /* Colors */
  --color-white: #ffffff;
  --color-gray-50: #f8f9fa;
  --color-gray-100: #f1f3f5;
  --color-gray-200: #e9ecef;
  --color-gray-300: #dee2e6;
  --color-gray-400: #ced4da;
  --color-gray-500: #adb5bd;
  --color-gray-600: #868e96;
  --color-gray-700: #495057;
  --color-gray-800: #343a40;
  --color-gray-900: #212529;

  --color-orange: #f98012;
  --color-orange-soft: #f5923a;
  --color-orange-hover: #e07010;
  --color-orange-light: rgba(249, 128, 18, 0.08);
  --color-orange-border: rgba(249, 128, 18, 0.25);

  /* Chrome (navbar + sidebar) on-orange palette */
  --chrome-bg: var(--color-orange-soft);
  --chrome-text: #ffffff;
  --chrome-text-muted: rgba(255, 255, 255, 0.8);
  --chrome-border: rgba(255, 255, 255, 0.2);
  --chrome-hover: rgba(255, 255, 255, 0.15);
  --chrome-active: rgba(255, 255, 255, 0.25);
  --color-danger: #dc3545;
  --color-danger-hover: #c82333;

  /* Semantic */
  --bg-page: var(--color-gray-100);
  --bg-surface: var(--color-white);
  --bg-surface-muted: var(--color-gray-50);
  --bg-input: var(--color-white);
  --border: var(--color-gray-300);
  --border-light: var(--color-gray-200);
  --text: var(--color-gray-800);
  --text-muted: var(--color-gray-600);
  --text-heading: var(--color-gray-900);
  --accent: var(--color-orange);
  --accent-hover: var(--color-orange-hover);

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --shadow-popover: 0 10px 32px rgba(0, 0, 0, 0.14);

  /* Layout */
  --navbar-height: 56px;
  --sidebar-width: 340px;
}

/* ── Reset ────────────────────────────────────────── */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-page);
  overflow: hidden;
}

/* ── Base elements ────────────────────────────────── */
button,
label.import-button,
select,
input {
  font: inherit;
}

button,
label.import-button {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 14px;
  background: var(--bg-surface);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  transition:
    border-color 0.15s,
    background 0.15s,
    box-shadow 0.15s;
}

button:hover,
label.import-button:hover {
  border-color: var(--color-gray-400);
  background: var(--color-gray-50);
}

button:focus-visible,
label.import-button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button.danger {
  color: var(--color-white);
  background: var(--color-danger);
  border-color: transparent;
}

button.danger:hover {
  background: var(--color-danger-hover);
}

/* ── Shell layout ─────────────────────────────────── */
.shell,
.remote-boot {
  width: min(100vw, 100%);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ── Navbar ───────────────────────────────────────── */
.browser-toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-md);
  align-items: center;
  padding: 0 var(--space-lg);
  height: var(--navbar-height);
  background: var(--chrome-bg);
  border-bottom: 1px solid var(--chrome-border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.browser-toolbar__address,
.address-form,
.browser-toolbar__actions,
.panel-tabs,
.panel__row,
.settings-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.address-form {
  width: 100%;
}

.address-form.is-disabled {
  opacity: 0.55;
}

.toolbar-brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.toolbar-brand__logo {
  display: block;
  height: 24px;
  width: auto;
}

.address-form__input {
  flex: 1;
}

.address-form__input input {
  width: 100%;
  padding: 7px 12px;
  border: 1px solid var(--chrome-border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.2);
  color: var(--chrome-text);
  font-size: 13px;
}

.address-form__input input::placeholder {
  color: var(--chrome-text-muted);
}

.address-form__input input:focus {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.5);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.15);
  outline: none;
}

.address-form__input input:disabled,
.toolbar-link:disabled,
.settings-field select:disabled,
.settings-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

/* Toolbar icon buttons (on orange background) */
.nav-buttons {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.browser-toolbar .icon-button {
  width: 36px;
  min-width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border-color: transparent;
  border-radius: var(--radius-md);
  color: var(--chrome-text-muted);
  font-size: 16px;
}

.browser-toolbar .icon-button--labeled {
  width: auto;
  padding: 0 12px;
  gap: var(--space-xs);
  text-decoration: none;
}

.browser-toolbar .icon-button__label {
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.browser-toolbar .icon-button:hover {
  background: var(--chrome-hover);
  color: var(--chrome-text);
  border-color: transparent;
}

/* Generic icon button (for non-toolbar contexts) */
.icon-button {
  width: 36px;
  min-width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border-color: transparent;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 16px;
}

.icon-button:hover {
  background: var(--color-gray-100);
  color: var(--text);
  border-color: transparent;
}

.toolbar-link {
  background: transparent;
  border-color: transparent;
  color: var(--chrome-text-muted);
  font-size: 13px;
  font-weight: 500;
}

.toolbar-link:hover {
  color: var(--chrome-text);
  background: var(--chrome-hover);
  border-color: transparent;
}

/* ── Workspace ────────────────────────────────────── */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--sidebar-width);
  height: calc(100vh - var(--navbar-height));
  height: calc(100dvh - var(--navbar-height));
  margin-top: var(--navbar-height);
  overflow: hidden;
}

.workspace > * {
  min-width: 0;
  min-height: 0;
}

.workspace.is-panel-collapsed {
  grid-template-columns: minmax(0, 1fr);
}

/* ── Viewport ─────────────────────────────────────── */
.viewport {
  overflow: hidden;
  background: var(--bg-surface);
}

.viewport iframe,
.remote-boot iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

/* ── Side panel ───────────────────────────────────── */
.side-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  border-left: 1px solid var(--chrome-border);
  background: var(--bg-surface);
  min-height: 0;
  overflow: hidden;
}

.side-panel.is-collapsed {
  display: none;
}

.side-panel__header,
.side-panel__content,
.side-panel__footer {
  padding: var(--space-lg);
}

.panel-tabs {
  padding: var(--space-sm) var(--space-lg);
}

.side-panel__header {
  background: var(--chrome-bg);
  border-bottom: 1px solid var(--chrome-border);
  padding: var(--space-md) var(--space-lg);
}

.side-panel__header strong {
  display: block;
  color: var(--chrome-text);
  font-size: 14px;
}

.remote-boot__card strong {
  display: block;
  color: var(--text-heading);
  font-size: 14px;
}

.side-panel__header span {
  color: var(--chrome-text-muted);
  font-size: 12px;
}

/* ── Panel tabs ───────────────────────────────────── */
.panel-tabs {
  gap: 4px;
  background: var(--chrome-bg);
  border-bottom: 1px solid var(--chrome-border);
}

.panel-tab {
  background: transparent;
  border-color: transparent;
  color: var(--chrome-text-muted);
  font-size: 13px;
  padding: 6px 12px;
  border-radius: var(--radius-md);
}

.panel-tab:hover {
  color: var(--chrome-text);
  background: var(--chrome-hover);
  border-color: transparent;
}

.panel-tab.is-active {
  background: var(--chrome-active);
  border-color: var(--chrome-border);
  color: var(--chrome-text);
  font-weight: 600;
}

/* ── Panel content ────────────────────────────────── */
.side-panel__content {
  overflow: auto;
  min-height: 0;
}

.side-panel__content.is-hidden {
  display: none;
}

.side-panel__content--stack {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

/* ── Panel footer ─────────────────────────────────── */
.side-panel__footer {
  display: grid;
  gap: var(--space-sm);
  border-top: 1px solid var(--chrome-border);
  background: var(--chrome-bg);
  color: var(--chrome-text-muted);
  font-size: 12px;
  padding: var(--space-md) var(--space-lg);
}

.side-panel__footer p {
  margin: 0;
}

.side-panel__footer a {
  color: var(--chrome-text);
  text-decoration: none;
}

.side-panel__footer a:hover {
  color: var(--color-white);
}

.side-panel__footer-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  width: fit-content;
  font-weight: 600;
}

.side-panel__footer-link svg {
  width: 16px;
  height: 16px;
}

/* ── Settings fields (sidebar) ────────────────────── */
.settings-field {
  display: grid;
  gap: var(--space-xs);
  margin-top: var(--space-lg);
}

.settings-field:first-child {
  margin-top: 0;
}

.settings-field span {
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}

.settings-value {
  font-weight: 600;
  color: var(--text-heading);
  font-size: 14px;
  text-transform: none;
  letter-spacing: 0;
}

.settings-field select {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  color: var(--text);
}

.settings-field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--color-orange-light);
}

.settings-actions {
  flex-wrap: wrap;
  margin-top: var(--space-lg);
  gap: var(--space-sm);
}

/* ── Panel rows (logs/phpinfo/blueprint headers) ──── */
.panel__row {
  justify-content: space-between;
  margin-bottom: var(--space-sm);
  font:
    600 11px / 1.2 ui-monospace,
    "SFMono-Regular",
    monospace;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.panel__row-actions {
  display: flex;
  gap: var(--space-xs);
}

/* ── Log panel ────────────────────────────────────── */
.log-panel {
  margin: 0;
  min-height: 220px;
  border-radius: var(--radius-md);
  padding: var(--space-md);
  background: var(--color-gray-900);
  color: #e4e8ec;
  font:
    12px / 1.6 ui-monospace,
    "SFMono-Regular",
    monospace;
  overflow: auto;
}

.log-panel .error {
  color: #f87171;
}

/* ── PHP info frame ───────────────────────────────── */
.panel-frame {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: #fff;
  display: block;
}

/* ── Blueprint textarea ───────────────────────────── */
.panel-textarea {
  width: 100%;
  min-height: 240px;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  background: var(--color-gray-900);
  color: #e4e8ec;
  font:
    12px / 1.5 ui-monospace,
    "SFMono-Regular",
    monospace;
  overflow: auto;
}

.panel-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--color-orange-light);
}

/* ── Progress bar (remote boot) ───────────────────── */
.progress-bar {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--color-gray-200);
  overflow: hidden;
}

.progress-bar__fill {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.3s ease-out;
}

.progress-percent {
  display: block;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.loading-copy {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

/* ── Remote boot card ─────────────────────────────── */
.remote-boot {
  width: 100%;
  min-height: 100vh;
  position: relative;
}

.remote-boot__card {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl);
  background: var(--bg-surface);
  pointer-events: all;
}

.remote-boot__card > strong {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-heading);
  margin-bottom: 20px;
}

.remote-boot__progress {
  width: min(480px, 100%);
  display: grid;
  gap: 14px;
}

.remote-boot__progress .loading-copy {
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
}

.remote-boot__card.is-hidden {
  display: none;
}

@keyframes shell-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Settings popover (replaces modal) ────────────── */
.settings-popover {
  position: fixed;
  top: calc(var(--navbar-height) + var(--space-sm));
  right: var(--space-lg);
  z-index: 100;
  width: 360px;
  max-width: calc(100vw - 32px);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-popover);
  padding: var(--space-xl);
  display: none;
}

.settings-popover.is-open {
  display: block;
}

.settings-popover__title {
  margin: 0 0 var(--space-lg);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-heading);
}

.settings-popover__field {
  display: grid;
  gap: var(--space-xs);
  margin-bottom: var(--space-lg);
}

.settings-popover__field span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}

.settings-popover__field select {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
}

.settings-popover__field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--color-orange-light);
}

.settings-popover__warning {
  padding: var(--space-md);
  border-radius: var(--radius-md);
  background: var(--color-orange-light);
  border: 1px solid var(--color-orange-border);
  color: var(--color-orange-hover);
  font-size: 13px;
  line-height: 1.45;
  margin-bottom: var(--space-lg);
}

.settings-popover__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
}

/* Overlay behind popover for outside-click dismiss */
.settings-popover-overlay {
  position: fixed;
  inset: 0;
  z-index: 99;
  display: none;
}

.settings-popover-overlay.is-open {
  display: block;
}

/* ── Responsive ───────────────────────────────────── */
@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .workspace:not(.is-panel-collapsed) {
    grid-template-rows: 1fr 1fr;
  }

  .side-panel {
    border-left: 0;
    border-top: 1px solid var(--border-light);
  }
}

@media (max-width: 720px) {
  .browser-toolbar {
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 0 var(--space-md);
    gap: var(--space-sm);
  }

  .address-form__input {
    display: none;
  }

  .browser-toolbar .icon-button--labeled {
    width: 36px;
    min-width: 36px;
    padding: 0;
  }

  .browser-toolbar .icon-button__label {
    display: none;
  }

  .browser-toolbar__actions {
    justify-content: flex-end;
  }

  .settings-popover {
    right: var(--space-sm);
    left: var(--space-sm);
    width: auto;
  }
}
