:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --card: #fffdf8;
  --ink: #1c1915;
  --muted: #6b645a;
  --line: #ddd6c8;
  --accent: #1f4f46;
  --accent-hover: #173c35;
  --danger: #8a2b2b;
  --shadow: 0 12px 32px rgba(28, 25, 21, 0.08);
  font-family: "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

#app {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}

.home {
  max-width: 420px;
}

#voice-status {
  margin-bottom: 8px;
}

#call-status {
  margin-bottom: 20px;
}

#phone {
  font-size: 1.15rem;
  letter-spacing: 0.02em;
}

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

.keypad button[data-key="back"] {
  grid-column: 1 / -1;
}

.keypad button {
  width: 100%;
  padding: 12px 0;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

.keypad button:hover {
  background: #f3efe4;
}

.call-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.inbound-actions {
  margin-bottom: 16px;
}

button.danger {
  background: var(--danger);
}

button.danger:hover {
  background: #6e2222;
}

h1 {
  margin: 0 0 8px;
  font-size: 1.5rem;
}

.muted {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 0.95rem;
}

label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  font-weight: 600;
}

input {
  width: 100%;
  margin-bottom: 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

button {
  width: 100%;
  padding: 10px 14px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

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

button:disabled {
  opacity: 0.65;
  cursor: wait;
}

button.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--line);
  margin-top: 16px;
}

button.secondary:hover {
  background: #f3efe4;
}

.error {
  margin: 0 0 16px;
  color: var(--danger);
  font-size: 0.9rem;
}

.status {
  margin: 0 0 24px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
}

.status-pending {
  background: #f3efe4;
  color: var(--muted);
  border: 1px solid var(--line);
}

.status-ready {
  background: #e7f2ef;
  color: var(--accent);
  border: 1px solid #c5ddd6;
}

.status-error {
  background: #f8ecec;
  color: var(--danger);
  border: 1px solid #e4c8c8;
}

.meta {
  display: grid;
  gap: 12px;
  margin: 0 0 8px;
}

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

.meta dt {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.meta dd {
  margin: 0;
  font-weight: 600;
}

.home-layout {
  width: 100%;
  max-width: 860px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.card.history {
  max-width: 860px;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.history-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.history-header .secondary {
  width: auto;
  margin-top: 0;
}

.history-status {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.95rem;
}

.history-status:empty {
  display: none;
}

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

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.history-table th,
.history-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.history-table th {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

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

.card.users {
  max-width: 860px;
}

.users-form {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.users-form .error:empty {
  display: none;
}

.history-table button.users-remove {
  width: auto;
  padding: 6px 10px;
  font-size: 0.8rem;
}

.venue-context {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  font-weight: 600;
}

.venue-context[hidden] {
  display: none;
}

/* SMS inbox */
.card.sms {
  max-width: 860px;
}

#text-number {
  margin: 8px 0 12px;
}

.sms-badge {
  display: inline-block;
  min-width: 20px;
  padding: 1px 7px;
  margin-left: 6px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
  vertical-align: middle;
}

.sms-badge[hidden] {
  display: none;
}

.sms-stop {
  margin-left: 6px;
  color: var(--danger);
  font-size: 0.75rem;
  font-weight: 600;
}

.sms-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
}

@media (max-width: 700px) {
  .sms-layout {
    grid-template-columns: 1fr;
  }
}

.sms-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 460px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.sms-empty {
  padding: 12px;
}

.sms-list li + li {
  border-top: 1px solid var(--line);
}

button.sms-convo {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  font-weight: 400;
}

button.sms-convo:hover,
button.sms-convo.active {
  background: #efe9dc;
}

.sms-convo-top {
  display: flex;
  align-items: center;
}

.sms-convo-preview {
  color: var(--muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sms-convo-when {
  color: var(--muted);
  font-size: 0.75rem;
}

.sms-thread-header {
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.sms-thread {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
  padding: 10px 0;
}

.sms-msg {
  display: flex;
  flex-direction: column;
  max-width: 80%;
}

.sms-in {
  align-self: flex-start;
}

.sms-out {
  align-self: flex-end;
  align-items: flex-end;
}

.sms-bubble {
  padding: 8px 12px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  background: #ece6d9;
}

.sms-out .sms-bubble {
  background: var(--accent);
  color: #fff;
}

.sms-meta {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.72rem;
}

.sms-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  resize: vertical;
}

.sms-form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sms-form-row button {
  width: auto;
  padding-left: 24px;
  padding-right: 24px;
}

.sms-form .error:empty {
  display: none;
}
