:root {
  color-scheme: light;
  --ink: #10232c;
  --muted: #5b6f78;
  --line: #cfdae0;
  --surface: #ffffff;
  --page: #edf3f5;
  --brand: #075f72;
  --brand-dark: #034656;
  --brand-soft: #e2f2f3;
  --amber: #a45608;
  --amber-soft: #fff1d6;
  --green: #176b45;
  --green-soft: #e1f3e9;
  --red: #a52b2b;
  --red-soft: #fbe7e5;
  font-family: "Nirmala UI", "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--page);
  color: var(--ink);
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  padding: 12px max(18px, calc((100% - 820px) / 2));
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 8px rgba(16, 35, 44, .18);
}

.app-header h1,
.app-header p { margin: 0; }
.app-header h1 { font-size: 1.35rem; }
.app-header .eyebrow { color: #d5eef2; }
.app-header > div:first-child { min-width: 0; }
.header-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.install-button {
  min-height: 42px;
  padding: 7px 11px;
  border: 1px solid rgba(255,255,255,.62);
  border-radius: 8px;
  background: #fff;
  color: var(--brand-dark);
  font-size: .82rem;
  font-weight: 800;
}

[hidden] { display: none !important; }

.eyebrow {
  margin: 0 0 2px;
  color: var(--brand);
  font-size: .76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255,255,255,.55);
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font-size: 1.35rem;
}

.app-shell {
  width: min(100%, 820px);
  margin: 0 auto;
  padding: 18px;
}

.network-status {
  margin-bottom: 12px;
  padding: 11px 13px;
  border: 1px solid #d69a49;
  border-radius: 8px;
  background: var(--amber-soft);
  color: #743802;
  font-size: .88rem;
  font-weight: 750;
  line-height: 1.45;
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding: 13px 14px;
  border: 1px solid #bcd5d9;
  border-radius: 8px;
  background: var(--brand-soft);
}

.status-strip div { display: grid; gap: 2px; min-width: 0; flex: 1; }
.status-strip span:not(.status-dot) { color: var(--muted); font-size: .9rem; }
.status-dot { width: 12px; height: 12px; border-radius: 50%; background: #70919a; flex: none; }
.status-dot.active { background: var(--red); box-shadow: 0 0 0 4px var(--red-soft); }
.quick-restore-button {
  min-height: 42px;
  padding: 8px 11px;
  border: 1px solid var(--green);
  border-radius: 7px;
  background: var(--green);
  color: #fff;
  font-size: .82rem;
  font-weight: 850;
  white-space: nowrap;
}

.form-section,
.preview-section,
.history-section {
  margin-bottom: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.section-heading,
.preview-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 15px;
}

.section-heading h2,
.section-heading p,
.preview-heading h2,
.preview-heading p { margin: 0; }
.section-heading h2,
.preview-heading h2 { font-size: 1.08rem; }
.section-heading p { margin-top: 2px; color: var(--muted); font-size: .84rem; }
.preview-heading { justify-content: space-between; }

.step {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  flex: none;
}

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

.feeder-button {
  min-height: 52px;
  padding: 8px;
  border: 1px solid #afc4cc;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
}

.feeder-button:hover { border-color: var(--brand); }
.feeder-button.active { border-color: var(--brand); background: var(--brand); color: #fff; }

.mapped-group {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #f2f6f7;
  color: var(--muted);
  font-size: .84rem;
}

.event-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
}

.event-tab {
  min-height: 48px;
  padding: 7px;
  border: 1px solid #b7c8ce;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 750;
}

.event-tab.active { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-dark); }
.event-tab[data-event="restored"].active { border-color: var(--green); background: var(--green-soft); color: var(--green); }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.field { display: grid; gap: 6px; font-weight: 700; font-size: .9rem; }
.field small { color: var(--muted); font-weight: 500; }
.full-width { grid-column: 1 / -1; }
.voice-input-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.voice-button {
  min-width: 112px;
  min-height: 46px;
  padding: 8px 12px;
  border: 1px solid var(--brand);
  border-radius: 6px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-weight: 800;
  white-space: nowrap;
}
.voice-button.listening { background: var(--brand); color: #fff; }
.voice-button:disabled { cursor: wait; opacity: 1; }

input,
select {
  width: 100%;
  min-height: 46px;
  padding: 9px 11px;
  border: 1px solid #aebfc6;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(7, 95, 114, .22);
  outline-offset: 1px;
  border-color: var(--brand);
}

.hidden { display: none !important; }
.area-heading { align-items: flex-start; }
.select-all { margin-left: auto; display: flex; gap: 6px; align-items: center; font-weight: 700; }
.select-all input { width: 20px; min-height: 20px; }

.area-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.area-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 7px 9px;
  border: 1px solid #d6e0e4;
  border-radius: 6px;
  background: #f8fafb;
  font-size: .88rem;
}
.area-option input { width: 18px; min-height: 18px; flex: none; }
.empty-state { grid-column: 1 / -1; margin: 0; color: var(--muted); }

.file-picker {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  padding: 10px 12px;
  border: 1px dashed #8eabb4;
  border-radius: 7px;
  background: #f6fafb;
  color: var(--brand);
  font-weight: 800;
}
.file-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.file-help { margin: 8px 0; color: var(--muted); font-size: .8rem; }
.attachment-summary { color: var(--muted); font-size: .86rem; font-weight: 700; }
.attachment-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.attachment-item { position: relative; aspect-ratio: 1; overflow: hidden; border: 1px solid var(--line); border-radius: 7px; background: #e7eef0; }
.attachment-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attachment-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  width: 28px;
  height: 28px;
  min-height: 0;
  place-items: center;
  border: 1px solid rgba(255,255,255,.9);
  border-radius: 50%;
  background: rgba(16,35,44,.86);
  color: #fff;
  font-size: 1rem;
  font-weight: 900;
}

.preview-section { border-color: #90bbc4; }
.message-preview {
  min-height: 220px;
  padding: 16px;
  border: 1px solid #acc6cc;
  border-left: 5px solid var(--brand);
  border-radius: 6px;
  background: #f8fbfc;
  white-space: pre-wrap;
  line-height: 1.62;
  font-size: 1rem;
}

.action-grid { display: grid; grid-template-columns: 1fr 1.5fr; gap: 9px; margin-top: 14px; }
.primary-button,
.secondary-button,
.text-button {
  min-height: 46px;
  border-radius: 7px;
  font-weight: 800;
}
.primary-button { border: 1px solid var(--brand); background: var(--brand); color: #fff; }
.primary-button:hover { background: var(--brand-dark); }
.secondary-button { border: 1px solid var(--brand); background: #fff; color: var(--brand); }
.text-button { min-height: 36px; padding: 6px 9px; border: 0; background: transparent; color: var(--brand); }
.action-note { margin: 8px 0 0; text-align: center; color: var(--muted); font-size: .82rem; }

.history-list { display: grid; gap: 8px; }
.history-item { padding: 11px; border: 1px solid var(--line); border-radius: 7px; }
.history-item header { display: flex; justify-content: space-between; gap: 10px; }
.history-item p { margin: 4px 0 0; color: var(--muted); font-size: .85rem; }
.history-badge { padding: 3px 7px; border-radius: 999px; background: var(--amber-soft); color: var(--amber); font-size: .76rem; font-weight: 800; white-space: nowrap; }
.history-badge.restored { background: var(--green-soft); color: var(--green); }

dialog {
  width: min(calc(100% - 24px), 640px);
  max-height: 88vh;
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(16, 35, 44, .28);
}
dialog::backdrop { background: rgba(11, 33, 42, .55); }
.settings-form { padding: 18px; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.dialog-header h2,
.dialog-header p { margin: 0; }
.dialog-header .icon-button { border-color: var(--line); color: var(--ink); }
.dialog-copy { color: var(--muted); line-height: 1.45; }
.group-settings { display: grid; gap: 10px; margin: 16px 0; }
.group-row { display: grid; grid-template-columns: 155px 1fr; align-items: center; gap: 10px; }
.group-row span { font-weight: 800; font-size: .88rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 30;
  max-width: calc(100% - 32px);
  padding: 11px 16px;
  border-radius: 7px;
  background: var(--ink);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 650px) {
  .app-header { min-height: 68px; padding: 10px 14px; }
  .app-header h1 { font-size: 1.16rem; }
  .install-button { padding-inline: 8px; font-size: .76rem; }
  .app-shell { padding: 12px; }
  .status-strip { align-items: flex-start; flex-wrap: wrap; }
  .quick-restore-button { width: 100%; }
  .form-section, .preview-section, .history-section { padding: 15px; }
  .feeder-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .event-tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid { grid-template-columns: 1fr; }
  .voice-input-row { grid-template-columns: minmax(0, 1fr) 108px; }
  .voice-button { min-width: 0; padding-inline: 8px; }
  .full-width { grid-column: auto; }
  .area-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .attachment-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .action-grid { grid-template-columns: 1fr; }
  .primary-button, .secondary-button { min-height: 50px; }
  .group-row { grid-template-columns: 1fr; gap: 5px; }
}

@media (max-width: 390px) {
  .app-header .eyebrow { font-size: .65rem; }
  .header-actions { gap: 5px; }
  .install-button { max-width: 88px; line-height: 1.1; }
  .area-grid { grid-template-columns: 1fr; }
  .preview-heading { align-items: flex-start; }
}
