* {
  box-sizing: border-box;
}

:root {
  --bg: #f3f5f1;
  --surface: #ffffff;
  --surface-2: #eef2eb;
  --ink: #1b221f;
  --muted: #68736c;
  --line: #d8dfd6;
  --line-strong: #bac7bd;
  --accent: #0f7b6c;
  --accent-strong: #075f55;
  --accent-soft: #d9efea;
  --blue: #245bdb;
  --amber: #c87810;
  --rose: #b9415e;
  --shadow: 0 18px 45px rgba(27, 34, 31, 0.1);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  letter-spacing: 0;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html {
  height: 100%;
  min-width: 320px;
  background: var(--bg);
}

body {
  min-width: 320px;
  height: 100%;
  min-height: 100svh;
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(27, 34, 31, 0.04) 1px, transparent 1px) 0 0 / 40px 40px,
    linear-gradient(0deg, rgba(27, 34, 31, 0.035) 1px, transparent 1px) 0 0 / 40px 40px,
    var(--bg);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(15, 123, 108, 0.28);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

h1,
h2,
p {
  margin: 0;
}

.app-shell {
  display: grid;
  height: 100svh;
  min-height: 0;
  overflow: hidden;
  grid-template-columns: 300px minmax(0, 1fr);
}

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

.login-card {
  display: grid;
  width: min(410px, 100%);
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  padding: 24px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 2rem;
  line-height: 1.05;
}

.login-card p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 630;
}

.sidebar {
  display: flex;
  height: 100svh;
  min-height: 0;
  flex-direction: column;
  gap: 22px;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.74);
  padding: 22px;
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #f8fbf8;
  font-size: 1.18rem;
  font-weight: 850;
}

.brand strong {
  display: block;
  font-size: 1rem;
  line-height: 1.05;
}

.brand span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.create-inline {
  display: flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid var(--accent-strong);
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(15, 123, 108, 0.18);
  transition:
    background 160ms ease,
    transform 160ms ease;
}

.create-inline:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.create-inline span {
  font-size: 1.28rem;
  line-height: 1;
}

.console-inline {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  font-weight: 820;
  transition:
    background 160ms ease,
    transform 160ms ease;
}

.console-inline:hover {
  background: #2a332f;
  transform: translateY(-1px);
}

.console-inline span {
  font-family: "JetBrains Mono", "Cascadia Code", "Fira Code", monospace;
  font-size: 0.85rem;
}

.sidebar-section {
  display: grid;
  flex: 1;
  min-height: 0;
  gap: 11px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.section-title small {
  display: grid;
  min-width: 25px;
  height: 22px;
  place-items: center;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 0.72rem;
}

.site-list {
  display: grid;
  min-height: 0;
  gap: 8px;
  overflow: auto;
  padding-right: 3px;
}

.site-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
}

.site-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}

.site-item {
  display: grid;
  width: 100%;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  padding: 12px;
  text-align: left;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.site-item:hover {
  background: rgba(15, 123, 108, 0.07);
}

.site-item.is-active {
  border-color: var(--line-strong);
  background: var(--surface);
  box-shadow: 0 10px 26px rgba(27, 34, 31, 0.07);
}

.site-delete {
  align-self: stretch;
  min-height: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--rose);
  padding: 0 9px;
  font-size: 0.72rem;
  font-weight: 850;
}

.site-delete:hover {
  border-color: #f1b6c4;
  background: #ffe7ed;
}

.site-delete:disabled {
  color: var(--muted);
  opacity: 0.55;
}

.site-item__name {
  overflow: hidden;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 820;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-item__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
}

.site-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.site-status::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--amber);
  content: "";
}

.site-item.is-published .site-status::before {
  background: var(--accent);
}

.site-item.is-error .site-status::before {
  background: var(--rose);
}

.site-item.is-planning .site-status::before,
.site-item.is-building .site-status::before {
  background: var(--blue);
}

.workspace {
  display: grid;
  height: 100svh;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 26px;
}

.empty-state {
  display: grid;
  height: calc(100svh - 52px);
  min-height: 0;
  place-items: center;
}

.create-tile {
  display: grid;
  width: min(310px, 84vw);
  aspect-ratio: 1;
  place-items: center;
  align-content: center;
  gap: 18px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: clamp(1.28rem, 4vw, 1.72rem);
  font-weight: 880;
  box-shadow: var(--shadow);
  transition:
    border-color 170ms ease,
    box-shadow 170ms ease,
    transform 170ms ease;
}

.create-tile:hover {
  border-color: var(--accent);
  box-shadow: 0 24px 60px rgba(15, 123, 108, 0.16);
  transform: translateY(-2px);
}

.create-tile__icon {
  display: grid;
  width: 72px;
  height: 72px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 3rem;
  font-weight: 500;
  line-height: 1;
}

.project-view {
  display: grid;
  height: calc(100svh - 52px);
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 16px;
}

.project-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
}

.project-heading {
  min-width: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  background: #fff3dd;
  color: #7b4a05;
  padding: 0 10px;
  font-size: 0.74rem;
  font-weight: 850;
}

.status-pill.is-published {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.status-pill.is-error {
  background: #ffe7ed;
  color: #8f2842;
}

.status-pill.is-planning,
.status-pill.is-building,
.status-pill.is-awaiting_confirmation {
  background: #e3ebff;
  color: #1f48a8;
}

.project-heading h1 {
  max-width: min(720px, 72vw);
  overflow-wrap: anywhere;
  margin-top: 8px;
  font-size: clamp(1.7rem, 4vw, 2.7rem);
  font-weight: 890;
  line-height: 1.02;
}

.project-heading p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.94rem;
  font-weight: 620;
}

.finish-button,
.primary-button,
.ghost-button,
.chat-form button {
  min-height: 42px;
  border-radius: 8px;
  font-weight: 830;
}

.finish-button {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid #a93450;
  background: var(--rose);
  color: #ffffff;
  padding: 0 15px;
}

.finish-button:disabled {
  border-color: var(--line-strong);
  background: var(--surface-2);
  color: var(--muted);
}

.work-panels {
  display: grid;
  min-height: 0;
  overflow: hidden;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 16px;
}

.chat-panel,
.logs-panel {
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 18px 44px rgba(27, 34, 31, 0.08);
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
}

.logs-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: rgba(238, 242, 235, 0.9);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 17px 18px;
}

.panel-header strong,
.panel-header span {
  display: block;
}

.panel-header strong {
  font-size: 1rem;
}

.panel-header span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 610;
}

.message-list {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
  padding: 18px;
}

.message {
  display: grid;
  width: min(680px, 88%);
  gap: 6px;
}

.message.is-user {
  align-self: flex-end;
}

.message.is-iara {
  align-self: flex-start;
}

.message__meta {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.message.is-user .message__meta {
  text-align: right;
}

.message__bubble {
  border-radius: 8px;
  padding: 12px 13px;
  font-size: 0.94rem;
  font-weight: 560;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message.is-user .message__bubble {
  background: var(--accent);
  color: #ffffff;
}

.message.is-iara .message__bubble {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 12px;
}

.chat-actions {
  display: flex;
  min-height: 58px;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--line);
  background: rgba(238, 242, 235, 0.72);
  padding: 10px 12px;
}

.chat-actions span {
  margin-right: auto;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 820;
}

.chat-action-button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 0 13px;
  font-size: 0.85rem;
  font-weight: 850;
  text-decoration: none;
}

.chat-action-button.is-primary {
  background: var(--accent);
  color: #ffffff;
}

.chat-action-button.is-secondary {
  border: 1px solid var(--line-strong);
  background: #ffffff;
  color: var(--ink);
}

.chat-action-button:disabled {
  background: var(--line-strong);
  color: var(--muted);
}

.chat-form input,
.field input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
}

.chat-form input {
  min-height: 44px;
  padding: 0 13px;
}

.chat-form input:disabled {
  background: var(--surface-2);
  color: var(--muted);
}

.chat-form button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--ink);
  color: #ffffff;
  padding: 0 16px;
}

.chat-form button:disabled {
  background: var(--line-strong);
}

.log-list {
  display: grid;
  gap: 0;
  margin: 0;
  overflow: auto;
  padding: 0;
  list-style: none;
}

.log-item {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 15px 18px;
}

.log-item time {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 790;
}

.log-item strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
  font-size: 0.84rem;
}

.log-item p {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.site-modal {
  width: min(430px, calc(100vw - 32px));
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0;
  box-shadow: 0 30px 80px rgba(27, 34, 31, 0.26);
}

.site-modal::backdrop {
  background: rgba(27, 34, 31, 0.38);
  backdrop-filter: blur(4px);
}

.console-modal {
  width: min(1180px, calc(100vw - 28px));
  height: min(760px, calc(100svh - 28px));
  border: 1px solid rgba(216, 223, 214, 0.2);
  border-radius: 8px;
  background: #0c1110;
  color: #e7efe9;
  padding: 0;
  box-shadow: 0 30px 90px rgba(12, 17, 16, 0.45);
}

.console-modal::backdrop {
  background: rgba(27, 34, 31, 0.62);
  backdrop-filter: blur(5px);
}

.console-shell {
  display: grid;
  height: 100%;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
}

.console-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid rgba(216, 223, 214, 0.14);
  padding: 13px 14px;
}

.console-header strong,
.console-header span {
  display: block;
}

.console-header strong {
  font-size: 0.96rem;
}

.console-header span {
  margin-top: 3px;
  color: #9cafaa;
  font-size: 0.78rem;
  font-weight: 760;
}

.console-header span.is-connected {
  color: #80ead8;
}

.console-terminal {
  min-height: 0;
  overflow: hidden;
  padding: 10px;
}

.console-terminal .xterm {
  height: 100%;
}

.console-terminal .xterm-viewport {
  overflow-y: auto;
}

.site-form {
  display: grid;
  gap: 18px;
  padding: 22px;
}

.site-form h2 {
  font-size: 1.45rem;
  line-height: 1.08;
}

.site-form p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 820;
}

.field input {
  min-height: 46px;
  padding: 0 12px;
}

.form-error {
  color: var(--rose) !important;
  font-weight: 760;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.ghost-button {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink);
  padding: 0 14px;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
  padding: 0 16px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

@media (max-width: 840px) {
  .app-shell {
    height: 100svh;
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .sidebar {
    height: auto;
    max-height: 184px;
    min-height: auto;
    overflow: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .site-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 3px;
  }

  .site-item {
    min-width: 210px;
  }

  .site-row {
    min-width: 292px;
  }

  .workspace {
    height: auto;
    min-height: 0;
    padding: 18px;
  }

  .empty-state,
  .project-view {
    height: calc(100svh - 221px);
    min-height: 0;
  }

  .project-header {
    flex-direction: column;
  }

  .project-heading h1 {
    max-width: 100%;
  }

  .finish-button {
    width: 100%;
  }

  .work-panels {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(130px, 180px);
  }

  .chat-panel {
    min-height: 0;
  }

  .logs-panel {
    min-height: 0;
  }
}

@media (max-width: 560px) {
  .sidebar,
  .workspace {
    padding: 14px;
  }

  .create-tile {
    width: min(260px, 86vw);
  }

  .message {
    width: 100%;
  }

  .chat-form {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .chat-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .chat-actions span {
    grid-column: 1 / -1;
    margin-right: 0;
  }

  .chat-form button {
    width: auto;
  }

  .chat-action-button {
    width: 100%;
  }

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

  .logs-panel {
    display: none;
  }

  .log-item {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .console-modal {
    width: calc(100vw - 18px);
    height: calc(100svh - 18px);
  }

  .console-header {
    align-items: stretch;
    flex-direction: column;
  }

  .modal-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}
