:root {
  color-scheme: dark;
  --ink: #f7f8fb;
  --ink-strong: #ffffff;
  --muted: #a4abb7;
  --muted-soft: #7d8490;
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(251, 203, 80, 0.34);
  --paper: #0d0f17;
  --paper-strong: #141722;
  --canvas: #030407;
  --input: #090b11;
  --gold: #fbcb50;
  --terra: #e36658;
  --pink: #d87297;
  --blue: #74a7ff;
  --green: #50d89a;
  --danger: #e36658;
  --gradient-brand: linear-gradient(135deg, #fbcb50 0%, #e36658 52%, #d87297 100%);
  --gradient-brand-side: linear-gradient(90deg, #d87297 0%, #e36658 48%, #fbcb50 100%);
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.38);
  --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.28);
  --glow: 0 0 34px rgba(251, 203, 80, 0.14), 0 0 52px rgba(216, 114, 151, 0.08);
  --font-sans: Nunito, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --sidebar-width: 300px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 0;
  overflow-x: hidden;
  background: var(--canvas);
}

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, rgba(251, 203, 80, 0.04), transparent 220px),
    linear-gradient(135deg, #030407 0%, #080a10 46%, #100c12 100%);
  color: var(--ink);
  font-family: var(--font-sans);
  text-rendering: geometricPrecision;
}

body.auth-pending .app-shell,
body.auth-required .app-shell,
body.authenticated .login-screen {
  display: none;
}

button,
input,
textarea,
select {
  min-width: 0;
  font: inherit;
}

button {
  display: inline-flex;
  min-height: 40px;
  max-width: 100%;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  line-height: 1.12;
  overflow-wrap: anywhere;
  padding: 0 14px;
  text-align: center;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

button:hover {
  border-color: rgba(251, 203, 80, 0.5);
  background: rgba(251, 203, 80, 0.08);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

button.primary {
  border-color: rgba(251, 203, 80, 0.72);
  background: #f3bd46;
  box-shadow: 0 10px 24px rgba(251, 203, 80, 0.14);
  color: #08090d;
}

button.primary:hover {
  border-color: rgba(251, 203, 80, 0.9);
  background: #fbcb50;
}

button.danger {
  border-color: rgba(227, 102, 88, 0.68);
  background: #d96a63;
  color: #08090d;
}

button.danger:hover {
  border-color: rgba(251, 203, 80, 0.58);
  background: #e36658;
}

label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: rgba(9, 11, 17, 0.92);
  color: var(--ink);
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

input,
select {
  height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 120px;
  padding: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted-soft);
}

select option {
  background: #0d0f17;
  color: var(--ink);
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--gold);
  background: rgba(13, 15, 23, 0.96);
  box-shadow: 0 0 0 3px rgba(251, 203, 80, 0.12);
}

input[type="file"] {
  height: auto;
  min-height: 42px;
  padding: 8px;
}

input[type="file"]::file-selector-button {
  margin-right: 10px;
  border: 0;
  border-radius: 7px;
  background: #f3bd46;
  color: #08090d;
  cursor: pointer;
  font-weight: 900;
  padding: 7px 10px;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
  width: 100%;
}

.app-shell > *,
.topbar > *,
.editor-grid > *,
.send-strip > *,
.field-row > *,
.inline-action > *,
.voice-row > *,
.user-box > *,
.panel header > * {
  min-width: 0;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: clamp(16px, 5vw, 32px);
}

.login-card {
  width: min(430px, 100%);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(20, 23, 34, 0.96), rgba(8, 10, 16, 0.98));
  box-shadow: var(--shadow), var(--glow);
  padding: clamp(20px, 5vw, 28px);
}

.login-card h1 {
  margin: 18px 0 7px;
  color: var(--ink-strong);
  font-size: clamp(22px, 7vw, 28px);
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.login-card p {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.login-card button {
  width: 100%;
  margin-top: 14px;
}

.otp-group {
  margin-top: 12px;
}

.login-status {
  min-height: 20px;
  margin: 12px 0 0 !important;
  color: var(--gold) !important;
  font-size: 13px;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  width: var(--sidebar-width);
  min-width: 0;
  align-self: start;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
  overscroll-behavior: contain;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(251, 203, 80, 0.08), transparent 170px),
    rgba(4, 5, 9, 0.92);
  padding: 20px;
}

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

.brand > div {
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid rgba(251, 203, 80, 0.42);
  border-radius: 8px;
  background: var(--gradient-brand);
  box-shadow: 0 10px 26px rgba(227, 102, 88, 0.2);
  color: #090a0e;
  font-size: 14px;
  font-weight: 900;
}

.brand h1 {
  margin: 0;
  color: var(--ink-strong);
  font-size: 18px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.brand p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.toolbar button {
  min-height: 38px;
  font-size: 12px;
  padding: 0 8px;
  white-space: nowrap;
}

.library-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.library-tabs button {
  min-height: 40px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  padding: 0 8px;
}

.library-tabs button.active {
  background: #f3bd46;
  color: #08090d;
}

.user-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
  padding: 9px;
}

.user-box span {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-box button {
  min-height: 34px;
  padding: 0 10px;
}

.template-list {
  display: flex;
  min-height: 0;
  flex: 1 1 0;
  flex-direction: column;
  gap: 9px;
  overflow: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
}

.template-item {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(20, 23, 34, 0.8), rgba(11, 13, 19, 0.88));
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
  color: var(--ink);
  padding: 13px;
  text-align: left;
}

.template-item:hover {
  background: linear-gradient(180deg, rgba(25, 28, 40, 0.92), rgba(12, 14, 22, 0.95));
}

.template-item.active {
  border-color: transparent;
  background:
    linear-gradient(180deg, rgba(42, 31, 31, 0.92), rgba(14, 16, 24, 0.96)) padding-box,
    var(--gradient-brand) border-box;
  box-shadow: 0 0 0 1px rgba(251, 203, 80, 0.14), var(--glow);
}

.template-item strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  color: var(--ink-strong);
  font-size: 14px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.template-item span {
  display: block;
  min-width: 0;
  margin-top: 6px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.template-item em {
  display: inline-flex;
  max-width: 100%;
  margin-top: 10px;
  border: 1px solid rgba(251, 203, 80, 0.22);
  border-radius: 999px;
  background: rgba(251, 203, 80, 0.12);
  color: var(--gold);
  font-size: 11px;
  font-style: normal;
  font-weight: 900;
  line-height: 1.2;
  overflow-wrap: anywhere;
  padding: 4px 8px;
}

.template-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  padding: 14px;
}

.workspace {
  display: grid;
  grid-column: 2;
  min-width: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 16px;
  padding: clamp(14px, 2vw, 20px);
}

.topbar {
  display: grid;
  grid-template-columns: 0.85fr 1.15fr 1fr;
  gap: 12px;
}

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

.panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(20, 23, 34, 0.93), rgba(9, 11, 17, 0.95));
  box-shadow: var(--shadow-soft);
  padding: 14px;
}

.panel header {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel h2 {
  min-width: 0;
  margin: 0;
  color: var(--ink-strong);
  font-size: 16px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.segmented {
  display: grid;
  min-width: min(170px, 100%);
  grid-template-columns: repeat(2, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
}

.segmented button {
  min-height: 34px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  padding: 0 10px;
}

.segmented button.active {
  background: #f3bd46;
  color: #08090d;
}

.composer-panel textarea,
.composer-panel iframe {
  min-height: 360px;
  flex: 1;
}

#htmlEditor {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

#previewFrame {
  display: none;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.ai-panel {
  overflow: auto;
}

.brief {
  min-height: 138px;
}

.transcript {
  min-height: 82px;
}

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

.check-option {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
  margin: -2px 0 2px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: none;
}

.check-option input {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  margin: 0;
  accent-color: var(--gold);
}

.check-option span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.voice-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.file-list {
  display: grid;
  gap: 7px;
}

.file-pill {
  display: flex;
  min-width: 0;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  font-size: 13px;
  padding: 9px 10px;
}

.file-pill span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.file-pill span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-pill span:last-child {
  flex: 0 0 auto;
}

.send-strip {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(210px, 0.8fr) minmax(260px, 1.1fr) minmax(220px, 0.85fr) minmax(160px, 0.55fr);
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(20, 23, 34, 0.93), rgba(9, 11, 17, 0.95));
  box-shadow: var(--shadow-soft);
  padding: 14px;
}

.send-field,
.send-actions,
.scheduled-panel {
  min-width: 0;
}

.inline-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.inline-action button {
  white-space: nowrap;
}

.recipients-field textarea {
  min-height: 72px;
}

.delivery-field {
  display: flex;
  flex-direction: column;
}

.delivery-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
}

.delivery-toggle button {
  min-height: 42px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 10px;
}

.delivery-toggle button.active {
  background: #f3bd46;
  color: #08090d;
}

.schedule-controls {
  margin-top: 10px;
}

.schedule-controls label {
  margin-bottom: 6px;
}

.send-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: end;
}

.activity-log {
  min-height: 42px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.scheduled-panel {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.scheduled-list {
  display: grid;
  gap: 8px;
}

.scheduled-empty {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.scheduled-item {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  padding: 10px 12px;
}

.scheduled-item strong,
.scheduled-item span {
  display: block;
  min-width: 0;
  overflow: hidden;
  overflow-wrap: anywhere;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scheduled-item strong {
  color: var(--ink-strong);
}

.scheduled-item span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.scheduled-item button {
  min-height: 34px;
  padding: 0 10px;
}

.status-pill {
  border: 1px solid rgba(116, 167, 255, 0.25);
  border-radius: 999px;
  background: rgba(116, 167, 255, 0.12);
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  line-height: 1.2;
  overflow-wrap: anywhere;
  padding: 5px 8px;
  text-transform: capitalize;
}

.status-pill.sent {
  border-color: rgba(80, 216, 154, 0.26);
  background: rgba(80, 216, 154, 0.12);
  color: var(--green);
}

.status-pill.failed {
  border-color: rgba(227, 102, 88, 0.32);
  background: rgba(227, 102, 88, 0.14);
  color: var(--terra);
}

.status-pill.canceled {
  border-color: rgba(164, 171, 183, 0.22);
  background: rgba(164, 171, 183, 0.1);
  color: var(--muted);
}

@media (max-width: 1280px) {
  .editor-grid,
  .send-strip {
    grid-template-columns: 1fr;
  }

  .composer-panel textarea,
  .composer-panel iframe {
    min-height: 340px;
  }
}

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

  .sidebar {
    position: static;
    height: auto;
    max-height: none;
    width: auto;
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .template-list {
    max-height: 260px;
  }

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

@media (max-width: 820px) {
  .topbar,
  .field-row,
  .inline-action,
  .scheduled-item {
    grid-template-columns: 1fr;
  }

  .inline-action button {
    width: 100%;
    white-space: normal;
  }

  .scheduled-item strong,
  .scheduled-item span {
    white-space: normal;
  }
}

@media (max-width: 560px) {
  body {
    background:
      linear-gradient(180deg, rgba(251, 203, 80, 0.05), transparent 180px),
      #030407;
  }

  .login-screen,
  .workspace,
  .sidebar {
    padding: 12px;
  }

  .brand {
    align-items: flex-start;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .brand h1 {
    font-size: 17px;
  }

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

  .toolbar button,
  .library-tabs button,
  .delivery-toggle button,
  .segmented button {
    min-height: 40px;
    padding: 0 6px;
    font-size: 12px;
  }

  .user-box {
    grid-template-columns: 1fr;
  }

  .user-box span {
    white-space: normal;
  }

  .panel,
  .send-strip,
  .login-card {
    padding: 12px;
  }

  .panel header {
    align-items: flex-start;
    flex-direction: column;
  }

  .segmented {
    width: 100%;
  }

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

  .composer-panel textarea,
  .composer-panel iframe {
    min-height: 300px;
  }

  #htmlEditor {
    font-size: 12px;
  }
}
