:root {
  --bg: #07100b;
  --bg-soft: #0a1510;
  --surface: rgba(17, 29, 21, 0.92);
  --surface-strong: #142219;
  --surface-hover: #192b20;
  --border: rgba(171, 210, 180, 0.14);
  --border-strong: rgba(171, 210, 180, 0.24);
  --text: #f4f8f5;
  --muted: #94a89a;
  --muted-strong: #b8c7bc;
  --green: #62ec89;
  --green-bright: #8cffaa;
  --green-dark: #06190c;
  --amber: #ffc96b;
  --red: #ff8585;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.28);
  --radius: 24px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  color-scheme: dark;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 22% -10%, rgba(98, 236, 137, 0.1), transparent 32rem),
    linear-gradient(180deg, #08120c 0%, var(--bg) 48%, #050b07 100%);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

button {
  color: inherit;
}

.hidden {
  display: none !important;
}

.ambient {
  position: fixed;
  z-index: -1;
  width: 460px;
  height: 460px;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.12;
  pointer-events: none;
}

.ambient-one {
  top: -240px;
  right: -120px;
  background: var(--green);
}

.ambient-two {
  bottom: -320px;
  left: -180px;
  background: #2f9060;
}

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

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--green-bright), #34d969);
  box-shadow: 0 10px 28px rgba(76, 232, 119, 0.18);
  color: var(--green-dark);
  font-size: 22px;
  font-weight: 900;
}

.brand-mark.small {
  width: 39px;
  height: 39px;
  border-radius: 12px;
  font-size: 19px;
}

.eyebrow,
.brand-subtitle {
  margin: 0;
}

.eyebrow {
  color: var(--green-bright);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.17em;
}

.brand-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 18px
    max(24px, env(safe-area-inset-bottom));
}

.login-card {
  width: min(480px, 100%);
  padding: 30px;
  border: 1px solid var(--border);
  border-radius: 30px;
  background: rgba(14, 26, 18, 0.88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.login-copy {
  padding: 50px 0 30px;
}

.secure-pill,
.status-pill,
.model-badge,
.count-badge,
.connection-badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(98, 236, 137, 0.22);
  border-radius: 999px;
  background: rgba(98, 236, 137, 0.08);
  color: var(--green-bright);
  font-size: 12px;
  font-weight: 700;
}

.secure-pill {
  padding: 7px 10px;
}

.login-copy h1 {
  max-width: 390px;
  margin: 18px 0 13px;
  font-size: clamp(38px, 9vw, 58px);
  line-height: 0.98;
  letter-spacing: -0.055em;
}

.login-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.6;
}

.login-copy strong {
  color: var(--muted-strong);
}

.button {
  min-height: 50px;
  border: 0;
  border-radius: 14px;
  padding: 0 18px;
  cursor: pointer;
  font-weight: 760;
  transition:
    transform 160ms ease,
    background 160ms ease,
    opacity 160ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0);
}

.button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.button.primary {
  background: linear-gradient(145deg, var(--green-bright), #43df73);
  color: var(--green-dark);
}

.button.secondary {
  border: 1px solid var(--border-strong);
  background: var(--surface-strong);
}

.button.secondary:hover {
  background: var(--surface-hover);
}

.button.danger {
  border: 1px solid rgba(255, 133, 133, 0.22);
  background: rgba(255, 133, 133, 0.08);
  color: #ffadad;
}

.button.full {
  width: 100%;
}

.knowledge-panel {
  margin-top: 22px;
}

.knowledge-channel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 17px;
  background: rgba(12, 24, 16, 0.72);
}

.channel-copy {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.channel-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.channel-copy small,
.privacy-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.knowledge-posts h3 {
  margin: 24px 0 12px;
  color: var(--muted-strong);
  font-size: 13px;
}

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

.knowledge-post {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(12, 24, 16, 0.62);
  color: inherit;
  text-decoration: none;
  transition:
    border-color 160ms ease,
    background 160ms ease;
}

.knowledge-post:hover {
  border-color: rgba(98, 236, 137, 0.34);
  background: var(--surface-hover);
}

.knowledge-post > span {
  color: var(--green-bright);
  font-size: 12px;
  font-weight: 750;
}

.knowledge-post p {
  display: -webkit-box;
  overflow: hidden;
  margin: 0;
  color: var(--muted-strong);
  font-size: 13px;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.knowledge-post small {
  color: var(--muted);
  font-size: 11px;
}

.privacy-note {
  margin: 18px 0 0;
}

@media (max-width: 680px) {
  .knowledge-post-grid {
    grid-template-columns: 1fr;
  }
}

.code-form {
  display: grid;
  gap: 12px;
  margin-top: 22px;
}

.code-form label,
.field,
.time-grid label,
.limits-form label {
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 13px;
  outline: none;
  background: #0b1710;
  color: var(--text);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(98, 236, 137, 0.6);
  box-shadow: 0 0 0 3px rgba(98, 236, 137, 0.1);
}

.code-form input {
  height: 58px;
  padding: 0 18px;
  text-align: center;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.2em;
}

.form-message {
  min-height: 20px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.form-message.error {
  color: #ffadad;
}

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

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding:
    max(12px, env(safe-area-inset-top))
    max(22px, env(safe-area-inset-right))
    12px
    max(22px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: rgba(7, 16, 11, 0.78);
  backdrop-filter: blur(20px);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.text-button {
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: rgba(20, 34, 25, 0.72);
  cursor: pointer;
}

.icon-button {
  width: 40px;
  font-size: 22px;
}

.text-button {
  padding: 0 14px;
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 650;
}

.dashboard {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 28px 22px max(40px, env(safe-area-inset-bottom));
}

.master-card {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 230px;
  padding: clamp(28px, 5vw, 48px);
  border: 1px solid rgba(98, 236, 137, 0.2);
  border-radius: 30px;
  background:
    radial-gradient(circle at 88% 12%, rgba(98, 236, 137, 0.16), transparent 22rem),
    linear-gradient(140deg, rgba(21, 42, 27, 0.98), rgba(12, 25, 17, 0.98));
  box-shadow: var(--shadow);
}

.master-card::after {
  content: "";
  position: absolute;
  right: -70px;
  bottom: -100px;
  width: 260px;
  height: 260px;
  border: 1px solid rgba(98, 236, 137, 0.08);
  border-radius: 50%;
}

.master-card h1 {
  margin: 18px 0 10px;
  font-size: clamp(38px, 6vw, 64px);
  line-height: 0.98;
  letter-spacing: -0.05em;
}

.master-card p {
  max-width: 620px;
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.status-pill {
  padding: 7px 11px;
}

.status-pill.off {
  border-color: rgba(255, 133, 133, 0.22);
  background: rgba(255, 133, 133, 0.08);
  color: #ffadad;
}

.status-pill.waiting {
  border-color: rgba(255, 201, 107, 0.24);
  background: rgba(255, 201, 107, 0.08);
  color: var(--amber);
}

.master-switch {
  position: relative;
  z-index: 2;
  display: grid;
  justify-items: center;
  gap: 10px;
  cursor: pointer;
}

.master-switch input,
.compact-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.master-switch-track {
  width: 108px;
  height: 60px;
  display: flex;
  align-items: center;
  padding: 6px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: #1c2820;
  transition: background 180ms ease;
}

.master-switch-thumb {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #7e8f83;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  transition:
    transform 200ms ease,
    background 180ms ease;
}

.master-switch input:checked + .master-switch-track {
  background: rgba(98, 236, 137, 0.18);
}

.master-switch input:checked + .master-switch-track .master-switch-thumb {
  transform: translateX(48px);
  background: var(--green-bright);
}

.master-switch > span:last-child {
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 750;
}

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

.stat-card,
.panel {
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.12);
}

.stat-card {
  min-height: 112px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px;
  border-radius: 18px;
}

.stat-card span {
  color: var(--muted);
  font-size: 12px;
}

.stat-card strong {
  font-size: 31px;
  letter-spacing: -0.04em;
}

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

.panel {
  padding: 24px;
  border-radius: var(--radius);
}

.schedule-panel {
  grid-row: span 2;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.panel-heading h2,
.section-kicker {
  margin: 0;
}

.panel-heading h2 {
  margin-top: 5px;
  font-size: 24px;
  letter-spacing: -0.035em;
}

.section-kicker {
  color: var(--green);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.panel-hint {
  margin: 14px 0 22px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.compact-switch {
  position: relative;
  cursor: pointer;
}

.compact-switch span {
  position: relative;
  width: 52px;
  height: 30px;
  display: block;
  border-radius: 999px;
  background: #273229;
  transition: background 180ms ease;
}

.compact-switch span::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #89988d;
  transition:
    transform 180ms ease,
    background 180ms ease;
}

.compact-switch input:checked + span {
  background: rgba(98, 236, 137, 0.22);
}

.compact-switch input:checked + span::after {
  transform: translateX(22px);
  background: var(--green-bright);
}

.time-grid,
.limits-form {
  display: grid;
  gap: 12px;
}

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

.time-grid input,
.field select,
.limits-form input[type="number"] {
  height: 48px;
  margin-top: 7px;
  padding: 0 13px;
}

.days-fieldset {
  margin: 20px 0;
  padding: 0;
  border: 0;
}

.days-fieldset legend {
  margin-bottom: 9px;
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 650;
}

.days-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.days-row input {
  position: absolute;
  opacity: 0;
}

.days-row span {
  min-height: 39px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: #0c1811;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.days-row input:checked + span {
  border-color: rgba(98, 236, 137, 0.4);
  background: rgba(98, 236, 137, 0.11);
  color: var(--green-bright);
}

.field {
  display: block;
  margin-bottom: 18px;
}

.mode-picker {
  display: grid;
  gap: 9px;
  margin-top: 20px;
}

.mode-picker button {
  display: grid;
  gap: 4px;
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #0c1811;
  text-align: left;
  cursor: pointer;
}

.mode-picker button:hover {
  background: var(--surface-hover);
}

.mode-picker button.active {
  border-color: rgba(98, 236, 137, 0.46);
  background: rgba(98, 236, 137, 0.1);
}

.mode-picker button strong {
  font-size: 14px;
}

.mode-picker button span {
  color: var(--muted);
  font-size: 12px;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.check-row input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  accent-color: var(--green);
}

.model-badge,
.count-badge,
.connection-badge {
  padding: 6px 9px;
}

.connection-badge.offline {
  border-color: rgba(255, 133, 133, 0.2);
  background: rgba(255, 133, 133, 0.07);
  color: #ffadad;
}

.budget-item {
  margin-top: 20px;
}

.budget-item > div:first-child {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.budget-item span {
  color: var(--muted);
  font-size: 12px;
}

.budget-item strong {
  font-size: 13px;
}

.progress {
  width: 100%;
  height: 7px;
  margin-top: 8px;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: #263229;
  appearance: none;
}

.progress::-webkit-progress-bar {
  border-radius: inherit;
  background: #263229;
}

.progress::-webkit-progress-value {
  border-radius: inherit;
  background: linear-gradient(90deg, #39d96a, var(--green-bright));
}

.progress::-moz-progress-bar {
  border-radius: inherit;
  background: linear-gradient(90deg, #39d96a, var(--green-bright));
}

.limits-form {
  margin-top: 22px;
}

.range-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.range-row input {
  height: auto;
  accent-color: var(--green);
}

.range-row output {
  color: var(--green-bright);
  font-size: 13px;
  font-weight: 750;
  text-align: right;
}

.drafts-panel,
.chats-panel {
  margin-top: 16px;
}

.stack-list {
  display: grid;
  gap: 10px;
  margin-top: 20px;
}

.empty-state {
  min-height: 94px;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.draft-card,
.chat-row {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(9, 20, 13, 0.74);
}

.draft-card {
  padding: 18px;
}

.draft-top,
.chat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.contact {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
}

.avatar {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: linear-gradient(145deg, #254b32, #183322);
  color: var(--green-bright);
  font-weight: 800;
}

.contact strong,
.contact small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact strong {
  font-size: 14px;
}

.contact small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.confidence-badge {
  flex: 0 0 auto;
  color: var(--green-bright);
  font-size: 12px;
  font-weight: 750;
}

.message-block {
  margin-top: 14px;
  padding: 13px;
  border-radius: 12px;
  background: #0b1710;
}

.message-block span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.message-block p {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.draft-reply {
  min-height: 108px;
  margin-top: 10px;
  padding: 12px;
  resize: vertical;
  font-size: 13px;
  line-height: 1.5;
}

.risk-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.risk-list span {
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(255, 201, 107, 0.08);
  color: var(--amber);
  font-size: 10px;
  font-weight: 700;
}

.draft-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.draft-actions .button {
  min-height: 42px;
  padding: 0 10px;
  font-size: 12px;
}

.chat-row {
  padding: 13px;
}

.chat-mode {
  width: auto;
  min-width: 134px;
  height: 40px;
  padding: 0 10px;
  font-size: 12px;
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 26px 4px 0;
  color: #65756a;
  font-size: 11px;
}

.toast {
  position: fixed;
  z-index: 50;
  right: 20px;
  bottom: max(20px, env(safe-area-inset-bottom));
  max-width: min(390px, calc(100vw - 40px));
  padding: 13px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 13px;
  background: #17271c;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
  font-size: 13px;
}

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

.toast.error {
  border-color: rgba(255, 133, 133, 0.3);
  color: #ffb5b5;
}

@media (max-width: 760px) {
  .dashboard {
    padding: 16px 14px max(34px, env(safe-area-inset-bottom));
  }

  .master-card {
    min-height: 300px;
    align-items: flex-start;
    flex-direction: column;
    padding: 26px 22px;
  }

  .master-switch {
    width: 100%;
    grid-template-columns: auto 1fr;
    align-items: center;
    justify-items: start;
  }

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

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

  .schedule-panel {
    grid-row: auto;
  }

  .panel {
    padding: 20px;
  }

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

  .footer {
    flex-direction: column;
  }
}

@media (max-width: 430px) {
  .topbar {
    padding-left: 14px;
    padding-right: 14px;
  }

  .topbar .brand-subtitle {
    display: none;
  }

  .login-card {
    padding: 24px 20px;
  }

  .login-copy {
    padding-top: 42px;
  }

  .stat-card {
    min-height: 100px;
  }

  .days-row {
    gap: 4px;
  }

  .days-row span {
    min-height: 36px;
    border-radius: 9px;
    font-size: 11px;
  }

  .chat-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .chat-mode {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
