:root {
  --ink: #162033;
  --muted: #68758a;
  --line: #dbe6f5;
  --panel: #ffffff;
  --soft: #f6f8fb;
  --soft-blue: #eaf3ff;
  --brand: #0f6bdc;
  --brand-dark: #084c9f;
  --success: #19a463;
  --warning: #b87912;
  --danger: #b63a3a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--soft);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: var(--brand);
  text-decoration: none;
}

a:hover {
  color: var(--brand-dark);
}

.btn {
  border-radius: 7px;
  font-weight: 700;
}

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
}

.btn-outline-primary {
  border-color: #b9d6fb;
  color: var(--brand-dark);
}

.form-control,
.form-select {
  border-color: #ccd9ea;
  border-radius: 7px;
}

.form-control:focus,
.form-select:focus {
  border-color: #91bdf4;
  box-shadow: 0 0 0 0.2rem rgba(15, 107, 220, 0.12);
}

.smtp-error {
  white-space: pre-wrap;
}

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

.portal-sidebar {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 18px;
  padding: 18px 14px;
  border-right: 1px solid var(--line);
  background: #fbfdff;
}

.portal-brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.portal-brand img {
  display: block;
  width: 210px;
  max-width: 100%;
  height: auto;
}

.portal-nav {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 7px;
  overflow: auto;
}

.portal-nav a {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink);
}

.portal-nav a.active,
.portal-nav a:hover {
  background: #f4f8ff;
  border-color: #d5e5fb;
}

.portal-nav span,
.project-glyph,
.account-avatar {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1px solid #b8d4f8;
  border-radius: 6px;
  color: var(--brand);
  background: #fff;
  font-size: 10px;
  font-weight: 900;
}

.portal-nav strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.portal-account {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.portal-account strong,
.portal-account small {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.portal-account small {
  color: var(--muted);
  font-size: 12px;
}

.portal-account a {
  color: var(--danger);
  font-size: 12px;
  font-weight: 800;
}

.portal-stage {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.portal-topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
}

.portal-kicker {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 2px;
}

.portal-topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.portal-main {
  min-height: 0;
  overflow: auto;
  padding: 22px 24px 28px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: start;
}

.panel-card,
.metric-card,
.auth-card,
.chat-card,
.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(34, 48, 74, 0.04);
}

.panel-card,
.card {
  overflow: hidden;
}

.panel-header,
.card-header {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  font-weight: 800;
}

.panel-header small,
.card-header small {
  color: var(--muted);
  font-weight: 600;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric-card {
  padding: 16px;
}

.metric-card small {
  display: block;
  color: var(--muted);
  font-weight: 800;
  margin-bottom: 6px;
}

.metric-card strong {
  font-size: 28px;
  line-height: 1;
}

.activity-list,
.project-list,
.device-list {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.activity-row,
.project-row,
.device-row,
.history-line {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid #e3eaf4;
  border-radius: 8px;
  background: #fff;
}

.project-row {
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
}

.project-row strong,
.device-row strong,
.activity-row strong,
.history-line strong {
  color: var(--ink);
}

.project-row small,
.device-row small,
.activity-row small,
.history-line small {
  color: var(--muted);
  font-size: 12px;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.liquid-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #d5e5fb;
  border-radius: 999px;
  background: #f4f8ff;
  color: var(--brand-dark);
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 800;
}

.liquid-badge.online,
.liquid-badge.enabled,
.liquid-badge.active {
  border-color: #c6ecd8;
  background: #eefbf4;
  color: #087443;
}

.liquid-badge.offline,
.liquid-badge.off,
.liquid-badge.revoked {
  border-color: #e1e7ef;
  background: #f5f7fa;
  color: #5d6b7f;
}

.liquid-badge.warning {
  border-color: #f1d69c;
  background: #fff8e9;
  color: var(--warning);
}

.table-shell {
  overflow: hidden;
}

.table {
  margin: 0;
}

.table thead th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.remote-chat-layout {
  height: calc(100vh - 128px);
  min-height: 560px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
}

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

.chat-window {
  min-height: 0;
  overflow: auto;
  padding: 18px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
}

.chat-bubble {
  width: min(760px, 100%);
  border: 1px solid #e0e7f1;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
  background: #fff;
}

.chat-bubble.user {
  margin-left: auto;
  background: var(--soft-blue);
  border-color: #bfdbff;
}

.chat-bubble.assistant,
.chat-bubble.tool,
.chat-bubble.system {
  background: #fbfdff;
}

.chat-bubble strong {
  display: block;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11px;
  margin-bottom: 5px;
}

.composer-card {
  border-top: 1px solid var(--line);
  padding: 12px;
  background: #fff;
}

.composer-card textarea {
  min-height: 108px;
  resize: vertical;
}

.side-stack {
  display: grid;
  gap: 12px;
}

.side-stack .panel-card {
  max-height: 38vh;
  overflow: auto;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 360px;
  border: 1px dashed #cfe0f6;
  border-radius: 8px;
  background: #fbfdff;
  text-align: center;
  padding: 28px;
}

.empty-state h2 {
  font-size: 18px;
  margin-bottom: 8px;
}

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

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, #ffffff 0%, #eef6ff 100%);
}

.auth-brand {
  position: fixed;
  top: 24px;
  left: 28px;
}

.auth-card {
  width: min(460px, 100%);
  padding: 24px;
}

.auth-card h1 {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 6px;
}

.auth-card p {
  color: var(--muted);
}

.history-search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-bottom: 14px;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.installer-grid h2 {
  color: #24344d;
}

@media (max-width: 980px) {
  .portal-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .portal-sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    grid-template-rows: auto auto;
  }

  .portal-nav {
    grid-auto-flow: column;
    overflow-x: auto;
  }

  .portal-account {
    display: none;
  }

  .portal-stage {
    min-height: 0;
  }

  .workspace-grid,
  .remote-chat-layout,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .remote-chat-layout {
    height: auto;
  }
}

@media (max-width: 620px) {
  .portal-topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }
}
