:root {
  --bg: #ffffff;
  --sidebar: #ffffff;
  --panel: #ffffff;
  --panel-soft: rgba(255, 223, 88, 0.12);
  --text: #1f1b14;
  --muted: #7a7260;
  --line: #efede6;
  --primary: #ffdf58;
  --primary-dark: #967c0b;
  --danger: #9b2c2c;
  --ok: #2b6b4d;
  --warn: #9a6a11;
  --info: #375f9b;
  --shadow: 0 6px 18px rgba(43, 33, 13, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Manrope', sans-serif;
}

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

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

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand-block h1,
.workspace-header h2,
h3 {
  font-family: 'Sora', sans-serif;
}

.brand-mark,
.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--primary-dark);
  font-size: 0.7rem;
  font-weight: 800;
}

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

.brand-block h1 {
  margin: 0;
  font-size: 1.55rem;
  line-height: 1.05;
}

.sidebar-nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
  cursor: pointer;
}

.nav-item.is-active {
  background: var(--panel-soft);
  border-color: rgba(197, 154, 35, 0.45);
}

.nav-item span {
  font-weight: 700;
  font-size: 0.95rem;
}

.nav-item strong {
  color: var(--primary-dark);
  font-size: 0.95rem;
}

.sidebar-stats {
  display: grid;
  gap: 8px;
}

.sidebar-stats article {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  padding: 10px 12px;
}

.sidebar-stats span,
.muted {
  color: var(--muted);
}

.sidebar-stats strong {
  display: block;
  margin-top: 4px;
  font-size: 1.2rem;
}

.workspace {
  padding: 16px 18px;
}

.workspace-header {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 4px 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.workspace-header h2 {
  margin-bottom: 4px;
  font-size: clamp(1.4rem, 2.4vw, 2rem);
}

.workspace-copy {
  margin-bottom: 0;
  color: var(--muted);
  max-width: 720px;
  font-size: 0.95rem;
}

.workspace-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.plus-button {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 0;
  background: var(--primary);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #fff;
}

.login-card {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: #fff;
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-family: 'Sora', sans-serif;
  margin-bottom: 8px;
  font-size: 2rem;
}

.login-copy {
  color: var(--muted);
  margin-bottom: 20px;
}

.login-form {
  gap: 14px;
}

.login-submit {
  margin-top: 4px;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.split-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.split-layout.composer-open {
  grid-template-columns: 1fr;
}

.booking-layout.finalize-open {
  grid-template-columns: minmax(0, 1fr) 360px;
}

.booking-layout.composer-open.finalize-open {
  grid-template-columns: minmax(0, 1fr) 360px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
}

.list-panel,
.logs-panel {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.stack {
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 8px;
}

input[type='text'],
input[type='date'],
input[type='email'],
input[type='tel'],
input[type='number'],
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 10px 12px;
  color: var(--text);
}

input[type='text']:focus,
input[type='date']:focus,
input[type='email']:focus,
input[type='tel']:focus,
input[type='number']:focus,
textarea:focus,
select:focus {
  outline: 2px solid rgba(197, 154, 35, 0.18);
  border-color: rgba(197, 154, 35, 0.42);
}

textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 10px 12px;
  color: var(--text);
  resize: vertical;
}

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

.checkbox-row input {
  width: 18px;
  height: 18px;
}

.primary-button,
.ghost-button,
.danger-button {
  border-radius: 12px;
  padding: 9px 12px;
  cursor: pointer;
  border: 1px solid transparent;
  font-size: 0.92rem;
}

.primary-button {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.ghost-button {
  background: #fff;
  border-color: var(--line);
  color: var(--text);
}

.icon-button {
  width: 42px;
  height: 42px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

.icon-button[data-permission='granted'] {
  background: var(--panel-soft);
  border-color: rgba(150, 124, 11, 0.25);
  color: var(--primary-dark);
}

.icon-button[data-permission='denied'] {
  color: var(--danger);
}

.icon-button[data-channel-enabled='false'] {
  opacity: 0.55;
}

.danger-button {
  background: rgba(155, 44, 44, 0.08);
  border-color: rgba(155, 44, 44, 0.1);
  color: var(--danger);
}

.feedback {
  min-height: 24px;
  margin: 14px 0 0;
  color: var(--ok);
}

.feedback[data-error='true'] {
  color: var(--danger);
}

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

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 160px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 18px;
  background: #fff;
}

.expediente-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 6px 8px;
}

.expediente-card:hover {
  border-color: var(--line);
}

.card-top,
.card-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.status-badge,
.schedule-pill,
.run-status {
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.72rem;
  font-weight: 700;
}

.status-badge[data-status='ok'],
.run-status[data-status='ok'] {
  color: var(--ok);
  background: rgba(43, 107, 77, 0.14);
}

.status-badge[data-status='sin_resultado'],
.run-status[data-status='sin_resultado'] {
  color: var(--warn);
  background: rgba(154, 106, 17, 0.14);
}

.status-badge[data-status='booked'],
.run-status[data-status='booked'] {
  color: var(--ok);
  background: rgba(43, 107, 77, 0.14);
}

.status-badge[data-status='paused'],
.run-status[data-status='paused'] {
  color: var(--muted);
  background: rgba(122, 114, 96, 0.12);
}

.status-badge[data-status='error'],
.run-status[data-status='error'] {
  color: var(--danger);
  background: rgba(155, 44, 44, 0.14);
}

.status-badge[data-status='revision_manual'],
.run-status[data-status='revision_manual'],
.status-badge[data-status='pending'],
.run-status[data-status='pending'] {
  color: var(--info);
  background: rgba(55, 95, 155, 0.14);
}

.expediente-meta,
.last-message,
.booking-summary {
  color: var(--muted);
}

.expediente-meta,
.booking-meta {
  margin-bottom: 0;
  font-size: 0.72rem;
  font-style: italic;
  line-height: 1.2;
}

.last-message {
  margin: 3px 0 4px;
  padding: 0;
  border-radius: 0;
  background: transparent;
  font-size: 0.78rem;
  line-height: 1.2;
}

.card-actions {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.card-actions .primary-button,
.card-actions .ghost-button,
.card-actions .danger-button {
  padding: 4px 8px;
  font-size: 0.76rem;
  border-radius: 10px;
}

.field-section {
  display: grid;
  gap: 10px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}

.field-section-head h4 {
  margin: 0 0 4px;
  font-size: 0.94rem;
}

.field-section-head p {
  margin-bottom: 0;
}

.dynamic-fields {
  display: grid;
  gap: 10px;
}

.dynamic-label {
  display: grid;
  gap: 8px;
}

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

.field-hint {
  color: var(--muted);
  font-size: 0.82rem;
}

.compact-copy {
  margin: 0;
  font-size: 0.88rem;
}

.booking-summary {
  margin-bottom: 4px;
  font-size: 0.76rem;
  line-height: 1.15;
}

.booking-slot-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 7px;
  border-radius: 10px;
  border: 1px solid rgba(150, 124, 11, 0.14);
  background: rgba(255, 223, 88, 0.09);
}

.booking-slot-inline strong,
.booking-slot-meta strong {
  display: block;
  color: var(--text);
}

.booking-slot-inline p {
  margin: 2px 0 0;
}

.booking-slot-meta {
  text-align: right;
  white-space: nowrap;
}

.booking-slot-meta span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
}

.expediente-card.is-highlighted,
.booking-card.is-highlighted {
  border-color: rgba(150, 124, 11, 0.42);
  box-shadow: 0 0 0 3px rgba(255, 223, 88, 0.2);
}

.booking-alerts {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.booking-alert {
  border: 1px solid rgba(150, 124, 11, 0.22);
  border-radius: 14px;
  background: #fff9dc;
  padding: 12px;
}

.booking-alert-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.booking-alert-head strong {
  display: block;
  margin-bottom: 4px;
}

.booking-alert p {
  margin-bottom: 0;
}

.booking-alert-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.inline-link {
  color: var(--primary-dark);
  text-decoration: none;
  font-weight: 700;
}

.inline-link:hover {
  text-decoration: underline;
}

.empty-fields {
  padding: 12px;
  border-radius: 14px;
  border: 1px dashed var(--line);
  background: #fff;
  color: var(--muted);
  text-align: left;
}

.settings-log-section {
  gap: 8px;
}

.settings-log-head {
  margin-bottom: 0;
}

.settings-log-table {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  overflow: auto;
}

.settings-log-table.empty-state {
  min-height: 96px;
}

.log-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.77rem;
}

.log-table th,
.log-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.log-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fff;
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.log-table tr:last-child td {
  border-bottom: 0;
}

.log-table td:nth-child(1) {
  width: 118px;
}

.log-table td:nth-child(2) {
  width: 88px;
}

.log-table td:nth-child(4) {
  width: 72px;
}

.log-table td:nth-child(5) {
  width: 104px;
}

.log-table .run-status {
  display: inline-flex;
  max-width: 100%;
}

.finalize-panel {
  position: sticky;
  top: 18px;
  align-self: start;
  max-height: calc(100vh - 36px);
  overflow: auto;
}

.finalize-summary {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.captcha-box {
  min-height: 54px;
  display: flex;
  align-items: center;
}

.composer-panel {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  width: min(760px, calc(100vw - 32px));
  max-height: min(88vh, 920px);
  overflow: auto;
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 45;
  box-shadow: 0 24px 64px rgba(31, 27, 20, 0.12);
}

.split-layout.composer-open .composer-panel {
  display: block;
}

.composer-panel[data-open='true'] {
  pointer-events: auto;
}

.settings-panel {
  width: min(620px, calc(100vw - 32px));
}

.settings-panel[data-open='true'] {
  display: block;
  pointer-events: auto;
}

.logs-panel-modal {
  width: min(1180px, calc(100vw - 32px));
  max-height: min(90vh, 980px);
}

.logs-panel-modal[data-open='true'] {
  display: block;
  pointer-events: auto;
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(31, 27, 20, 0.3);
  z-index: 40;
}

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .split-layout,
  .booking-layout.finalize-open,
  .booking-layout.composer-open.finalize-open {
    grid-template-columns: 1fr;
  }

  .composer-panel {
    width: min(760px, calc(100vw - 20px));
    max-height: 90vh;
  }

  .finalize-panel {
    position: static;
    max-height: none;
  }
}

@media (max-width: 720px) {
  .workspace {
    padding: 12px;
  }

  .sidebar {
    padding: 14px 12px;
  }

  .booking-slot-inline {
    align-items: flex-start;
    flex-direction: column;
  }

  .booking-slot-meta {
    text-align: left;
  }

  .card-top,
  .card-bottom,
  .panel-head,
  .workspace-header,
  .field-row {
    flex-direction: column;
    align-items: flex-start;
  }

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

  .composer-panel {
    width: calc(100vw - 16px);
    max-height: calc(100vh - 16px);
    border-radius: 16px;
  }

  .modal-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}
