:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --panel: #ffffff;
  --line: #d7dde3;
  --text: #20262d;
  --muted: #65717f;
  --accent: #14746f;
  --accent-strong: #0f5d59;
  --danger: #b3261e;
  --terminal: #101418;
  --terminal-text: #d6f2df;
  --self: #e7f4ef;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
}

.hidden {
  display: none !important;
}

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 40px rgb(32 38 45 / 10%);
}

.login-panel h1,
.sidebar h1,
.terminal-header h2 {
  margin: 0;
}

.login-panel label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.login-panel input,
.create-form input,
.input-form input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}

.login-panel input:focus,
.create-form input:focus,
.input-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(20 116 111 / 15%);
}

.login-panel button,
.input-form button,
.create-form button {
  border-radius: 6px;
  background: var(--accent);
  color: white;
  padding: 11px 14px;
  font-weight: 650;
}

.login-panel button:hover,
.input-form button:hover,
.create-form button:hover {
  background: var(--accent-strong);
}

.error-text {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

.workspace {
  position: relative;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  z-index: 20;
  display: flex;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  flex-direction: column;
  gap: 16px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 20px;
}

.sidebar-backdrop {
  display: none;
}

.sidebar-header,
.terminal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.sidebar-header p,
.terminal-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: #eef2f5;
  color: var(--text);
  font-size: 20px;
}

.menu-button,
.mobile-label {
  display: none;
}

.create-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
}

.create-form button {
  height: 44px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.session-list {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 0;
  overflow: auto;
}

.session-item {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--text);
  background: transparent;
  text-align: left;
}

.session-item:hover {
  background: #eef2f5;
}

.session-item.active {
  background: var(--self);
  color: #123f3b;
  font-weight: 700;
}

.session-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.terminal-pane {
  display: grid;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  min-width: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.terminal-header {
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  padding: 18px 22px;
}

.terminal-header > div {
  min-width: 0;
}

.terminal-title {
  display: grid;
  gap: 3px;
}

.terminal-header h2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.danger-button {
  border: 1px solid #f0c4c0;
  border-radius: 6px;
  background: #fff5f3;
  color: var(--danger);
  padding: 9px 12px;
  font-weight: 650;
}

.danger-button:hover {
  background: #ffe7e3;
}

.terminal-screen {
  min-height: 0;
  min-width: 0;
  margin: 0;
  border: 0;
  background: var(--terminal);
  color: var(--terminal-text);
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, "Apple SD Gothic Neo",
    "Malgun Gothic", monospace;
  font-size: 13px;
  line-height: 1.45;
  overflow: auto;
  padding: 20px 22px;
  white-space: pre-wrap;
  word-break: break-word;
}

.empty-state {
  margin: auto;
  color: var(--muted);
}

.input-form {
  display: grid;
  grid-template-columns: minmax(0, 8fr) minmax(48px, 1fr) minmax(48px, 1fr);
  gap: 10px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 16px 22px;
}

.input-form button {
  display: inline-grid;
  min-width: 0;
  place-items: center;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

#stop-button {
  background: #b3261e;
}

#stop-button:hover {
  background: #8f1e18;
}

@media (max-width: 760px) {
  body {
    overscroll-behavior: none;
  }

  .login-view {
    align-items: start;
    min-height: 100dvh;
    padding: 14px;
    padding-top: max(14px, env(safe-area-inset-top));
  }

  .login-panel {
    gap: 10px;
    width: min(420px, calc(100vw - 28px));
    padding: 14px;
  }

  .login-panel h1 {
    font-size: 20px;
  }

  .login-panel input,
  .login-panel button,
  .create-form input,
  .create-form button,
  .input-form input,
  .input-form button {
    min-height: 38px;
    font-size: 16px;
  }

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

  .sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    width: min(88vw, 340px);
    height: 100dvh;
    max-height: none;
    min-height: 0;
    gap: 8px;
    padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
    border-right: 1px solid var(--line);
    border-bottom: 0;
    box-shadow: 10px 0 28px rgb(32 38 45 / 18%);
    transform: translateX(-105%);
    transition: transform 160ms ease;
  }

  .workspace.sessions-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: absolute;
    inset: 0;
    z-index: 15;
    display: block;
    pointer-events: none;
    background: rgb(16 20 24 / 0%);
    transition: background 160ms ease;
  }

  .workspace.sessions-open .sidebar-backdrop {
    pointer-events: auto;
    background: rgb(16 20 24 / 40%);
  }

  .sidebar-header h1 {
    font-size: 17px;
  }

  .sidebar-header p {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
  }

  .create-form {
    grid-template-columns: minmax(0, 1fr) 38px;
    gap: 6px;
  }

  .create-form button {
    height: 38px;
    font-size: 20px;
  }

  .session-list {
    grid-auto-flow: row;
    gap: 4px;
    overflow: auto;
  }

  .session-item {
    min-height: 36px;
    padding: 7px 9px;
    font-size: 13px;
  }

  .terminal-pane {
    height: 100%;
    min-height: 0;
  }

  .terminal-header {
    gap: 7px;
    min-height: 44px;
    padding: max(6px, env(safe-area-inset-top)) 8px 6px;
  }

  .terminal-header h2 {
    max-width: 50vw;
    font-size: 14px;
    line-height: 1.15;
  }

  .terminal-header p {
    font-size: 10px;
    line-height: 1.1;
  }

  .menu-button {
    display: inline-grid;
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    font-size: 18px;
  }

  .desktop-label {
    display: none;
  }

  .mobile-label {
    display: inline;
  }

  .danger-button {
    display: inline-grid;
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    place-items: center;
    padding: 0;
    font-size: 16px;
  }

  .terminal-screen {
    padding: 8px 9px;
    font-size: 11px;
    line-height: 1.38;
    word-break: break-word;
  }

  .input-form {
    grid-template-columns: minmax(0, 8fr) minmax(38px, 1fr) minmax(38px, 1fr);
    gap: 6px;
    padding: 7px 8px max(7px, env(safe-area-inset-bottom));
  }

  .input-form input {
    padding: 7px 9px;
  }

  .input-form button {
    font-size: 15px;
  }
}

@media (max-width: 380px) {
  .terminal-header h2 {
    max-width: 40vw;
    font-size: 13px;
  }

  .terminal-screen {
    font-size: 10.5px;
    line-height: 1.35;
  }
}
