:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #f0f3f7;
  --line: #d7dde6;
  --text: #17202c;
  --muted: #647084;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --green: #07865f;
  --green-soft: #dff7ed;
  --amber: #b7791f;
  --amber-soft: #fff3d7;
  --red: #b42318;
  --red-soft: #ffe4df;
  --ink: #111827;
  --shadow: 0 12px 36px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

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

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  background: #111827;
  color: #e5edf8;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 6px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: white;
  background: #2563eb;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 3px;
  color: #aab4c3;
  font-size: 0.84rem;
}

.nav {
  display: grid;
  gap: 4px;
}

.nav-btn {
  height: 42px;
  border: 0;
  border-radius: 7px;
  color: #c7d2e2;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  text-align: left;
}

.nav-btn:hover,
.nav-btn.active {
  color: white;
  background: rgba(255, 255, 255, 0.1);
}

.nav-btn svg,
.btn svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.connection {
  margin-top: auto;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 9px;
  color: #aab4c3;
  font-size: 0.88rem;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--amber);
}

.dot.ok {
  background: var(--green);
}

.dot.bad {
  background: var(--red);
}

.main {
  min-width: 0;
  padding: 22px;
}

.topbar {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.6rem, 2.5vw, 2.15rem);
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
}

h3 {
  font-size: 0.95rem;
}

.top-actions,
.button-row,
.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

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

textarea {
  resize: vertical;
  line-height: 1.45;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.btn {
  min-height: 40px;
  border: 1px solid var(--blue);
  border-radius: 7px;
  background: var(--blue);
  color: #fff;
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
  white-space: nowrap;
}

.btn:hover {
  filter: brightness(0.96);
}

.btn.ghost {
  background: #fff;
  color: var(--blue);
}

.btn.compact {
  min-height: 34px;
  padding: 0 10px;
}

.btn.danger {
  background: var(--red);
  border-color: var(--red);
}

.btn.success {
  background: var(--green);
  border-color: var(--green);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.panel {
  padding: 16px;
}

.panel-head {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(330px, 0.75fr);
  gap: 16px;
}

.compose-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
}

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

.wide {
  grid-column: 1 / -1;
}

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

.stat {
  min-height: 94px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 14px;
  display: grid;
  align-content: space-between;
  box-shadow: var(--shadow);
}

.stat span {
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 700;
}

.stat strong {
  font-size: 1.8rem;
}

.pill {
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  padding: 5px 9px;
  font-size: 0.78rem;
  font-weight: 800;
}

.pill.ok {
  background: var(--green-soft);
  color: var(--green);
}

.pill.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.pill.bad {
  background: var(--red-soft);
  color: var(--red);
}

.item-list {
  display: grid;
  gap: 10px;
}

.item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  display: grid;
  gap: 9px;
}

.item-header,
.item-actions,
.meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.item-header {
  justify-content: space-between;
}

.item-title {
  font-weight: 800;
}

.item-text {
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.meta-row {
  color: var(--muted);
  font-size: 0.82rem;
}

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

.guardrail-box {
  min-height: 86px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--muted);
  background: var(--surface-soft);
  white-space: pre-wrap;
}

.preview {
  margin-top: 16px;
}

#draftPreview {
  min-height: 190px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fdfdfd;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.5;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.segment {
  border: 0;
  background: transparent;
  color: var(--muted);
  min-height: 34px;
  padding: 0 10px;
  font-weight: 750;
}

.segment.active {
  background: var(--blue-soft);
  color: var(--blue);
}

.setup-list {
  display: grid;
  gap: 12px;
}

.setup-list div {
  display: grid;
  gap: 3px;
}

.setup-list strong {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.setup-list span {
  overflow-wrap: anywhere;
}

.calendar-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.calendar-day {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  min-height: 130px;
  padding: 12px;
}

.calendar-day strong {
  display: block;
  margin-bottom: 9px;
}

.audit-list {
  display: grid;
  gap: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

.audit-row {
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
  display: grid;
  grid-template-columns: 170px 160px minmax(0, 1fr);
  gap: 10px;
}

.checkline {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.checkline input {
  width: 18px;
  min-height: 18px;
}

.token-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  margin-bottom: 16px;
}

.token-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 10px;
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  min-height: 44px;
  border-radius: 8px;
  background: #111827;
  color: white;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

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

  .nav-btn {
    justify-content: center;
  }

  .nav-btn span {
    display: none;
  }

  .split,
  .compose-layout,
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .main {
    padding: 14px;
  }

  .topbar,
  .token-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions > *,
  .token-form {
    width: 100%;
    grid-template-columns: 1fr;
  }

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

  .audit-row {
    grid-template-columns: 1fr;
  }
}
