:root {
  --ink: #1f2523;
  --muted: #69726d;
  --line: #d8ded7;
  --paper: #f4f6f7;
  --panel: #ffffff;
  --accent: #126b5f;
  --accent-2: #d77f2f;
  --blue: #315f9f;
  --danger: #a64035;
  --shadow: 0 18px 50px rgba(36, 42, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(31, 37, 35, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(31, 37, 35, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  font-family: Avenir Next, PingFang SC, Hiragino Sans GB, Helvetica Neue, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  min-height: 40px;
  padding: 0 16px;
  cursor: pointer;
}

button:hover {
  background: var(--accent);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  min-height: 40px;
  padding: 9px 10px;
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 42px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 0 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.05;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 18px;
}

.status-pill,
.panel-head span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 246, 0.78);
  color: var(--muted);
  padding: 7px 11px;
  font-size: 13px;
  white-space: nowrap;
}

.panel-head span.online {
  border-color: rgba(18, 107, 95, 0.28);
  background: rgba(18, 107, 95, 0.12);
  color: var(--accent);
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-panel {
  max-width: 760px;
  padding: 22px;
}

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

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  padding: 18px;
  align-items: end;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 350px;
  grid-template-rows: auto auto 1fr;
  gap: 16px;
  align-items: start;
}

.device-panel,
.device-detail-panel,
.conversation-panel {
  grid-column: 1;
}

.device-panel { grid-row: 1; }
.device-detail-panel { grid-row: 2; }
.conversation-panel { grid-row: 3; }

.side-grid {
  display: grid;
  gap: 16px;
  grid-column: 2;
  grid-row: 1 / span 3;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 14px;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.row-actions {
  display: flex;
  gap: 8px;
  min-width: 132px;
}

.row-actions button {
  min-height: 34px;
  padding: 0 10px;
}

.state {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: #ece7d5;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.state.online {
  background: rgba(18, 107, 95, 0.14);
  color: var(--accent);
}

.pair-code {
  margin: 16px 18px 0;
  border: 1px dashed var(--accent-2);
  border-radius: 8px;
  background: #fff8e7;
  color: var(--accent-2);
  padding: 16px;
  font-size: 34px;
  font-weight: 800;
  text-align: center;
}

.pair-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 12px;
  padding: 16px 18px 0;
  align-items: end;
}

.setup-list,
.ai-status,
.widget-list,
.ota-list,
.conversation-list,
.stack-form {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 16px;
}

.detail-item {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 12px;
}

.detail-item span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.detail-item strong {
  overflow-wrap: anywhere;
  font-size: 14px;
}

.widget-item,
.ota-item,
.conversation-item {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 12px;
}

.widget-item strong,
.ota-item strong,
.conversation-item strong {
  display: block;
  margin-bottom: 5px;
}

.widget-item p,
.ota-item p,
.conversation-item p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: 320px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

.provider-status { display: flex; justify-content: space-between; gap: 12px; }
.check-label { display: flex; align-items: center; }
.check-label input { width: 18px; min-height: 18px; }
#providerResult { font-size: 13px; overflow-wrap: anywhere; }
button:disabled { opacity: .55; cursor: wait; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
.conversation-item .row-actions { margin-top: 12px; }
dialog { width: min(600px, calc(100vw - 32px)); max-height: 85vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 20px; }
dialog::backdrop { background: rgb(0 0 0 / 30%); }
dialog form { display: flex; justify-content: flex-end; }
dialog section { padding: 16px 0; border-bottom: 1px solid var(--line); }
dialog p { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; }
dialog details { margin-top: 12px; }
dialog summary { cursor: pointer; font-weight: 600; }
dialog pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; line-height: 1.6; }

@media (max-width: 860px) {
  .topbar,
  .form-grid,
  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .topbar {
    display: grid;
  }

  .workspace { grid-template-rows: auto; }

  .device-panel,
  .device-detail-panel,
  .conversation-panel,
  .side-grid {
    grid-column: auto;
    grid-row: auto;
  }

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

  .pair-form {
    grid-template-columns: 1fr;
  }
}
