:root {
  --green-900: #06573f;
  --green-800: #0b6b4c;
  --green-700: #13855d;
  --green-600: #1aa36d;
  --surface: #f5f6f6;
  --ink: #1f2937;
  --muted: #6b7280;
  --card-border: rgba(17, 24, 39, 0.28);
  --danger: #e83434;
  --warn: #f39c12;
  --ok: #22b35e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Plus Jakarta Sans", sans-serif;
  color: var(--ink);
  background: #eef0f2;
}

.bg-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(rgba(255, 255, 255, 0.8) 0.8px, transparent 0.8px),
    radial-gradient(rgba(0, 0, 0, 0.03) 1px, transparent 1px);
  background-size: 3px 3px, 6px 6px;
  opacity: 0.8;
}

.app-shell {
  width: min(1200px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 8px;
  padding-bottom: 8px;
  position: relative;
}

.app-header {
  background: linear-gradient(120deg, var(--green-900), var(--green-800));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-logo {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
}

.header-right {
  position: relative;
}

.icon-btn {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 3px;
}

#settingsBtn.icon-btn {
  display: none;
}

.brand {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: clamp(20px, 2.4vw, 28px);
}

.sub {
  margin: 2px 0 0;
  font-size: clamp(11px, 1.2vw, 14px);
  color: rgba(255, 255, 255, 0.92);
}

.mini-wave {
  display: inline-flex;
  align-items: end;
  gap: 2px;
}

.mini-wave i {
  width: 3px;
  height: 14px;
  border-radius: 999px;
  background: #23d16f;
  animation: waveBeat 0.9s ease-in-out infinite;
}

.mini-wave i:nth-child(2) { animation-delay: 0.1s; }
.mini-wave i:nth-child(3) { animation-delay: 0.2s; }
.mini-wave i:nth-child(4) { animation-delay: 0.06s; }

@keyframes waveBeat {
  0%, 100% { transform: scaleY(0.4); }
  50% { transform: scaleY(1.12); }
}

.mic-toggle {
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #f31359;
  color: #fff;
  cursor: pointer;
  padding: 9px;
}

.mic-toggle.mic-on {
  background: #4bb33f;
}

.mic-toggle.mic-denied {
  background: #991b1b;
}

.mic-icon {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mic-toggle.mic-on .mic-slash {
  display: none;
}

.pill-btn,
.ghost-btn,
.tab-btn,
.send-btn,
#closeViewer,
#closeSettings,
#closeProfile {
  border: 0;
  cursor: pointer;
}

.pill-btn {
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--green-700);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  background: var(--green-800);
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  border-bottom: 1px solid rgba(0, 0, 0, 0.2);
}

.tab-btn {
  background: transparent;
  color: rgba(255, 255, 255, 0.95);
  font-size: clamp(13px, 1.4vw, 16px);
  padding: 9px 6px;
  border-right: 1px solid rgba(0, 0, 0, 0.3);
}

.tab-btn:last-child {
  border-right: 0;
}

.tab-btn.active {
  background: rgba(255, 255, 255, 0.13);
}

.actions-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  display: grid;
  gap: 4px;
  width: 210px;
  padding: 6px;
  border: 1px solid rgba(17, 24, 39, 0.16);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 14px 34px rgba(17, 24, 39, 0.18);
}

.action-btn {
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #1f2937;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  padding: 9px 10px;
  text-align: left;
}

.action-btn:hover {
  background: #eef0f2;
}

.menu-group {
  display: grid;
  gap: 3px;
}

.menu-group summary {
  list-style: none;
}

.menu-group summary::-webkit-details-marker {
  display: none;
}

.menu-group[open] summary {
  background: #fee2e2;
}

.menu-group .action-btn:not(summary) {
  padding-left: 22px;
}

.action-btn.danger {
  color: #991b1b;
}

.action-btn.danger:hover {
  background: #fee2e2;
}

main {
  padding: 8px 12px 112px;
}

.receive-status {
  margin: 0 12px;
  padding: 5px 9px;
  border-radius: 8px;
  background: #e8eff3;
  color: #335474;
  font-size: 12px;
}

.receive-status.ok {
  background: #d9f6ea;
  color: #06573f;
}

.receive-status.warn {
  background: #fff2bf;
  color: #8a5b00;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  z-index: 60;
  transform: translateX(-50%);
  border-radius: 999px;
  padding: 10px 16px;
  background: #06573f;
  color: #fff;
  box-shadow: 0 10px 28px rgba(17, 24, 39, 0.22);
  font-size: 14px;
  font-weight: 700;
}

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

.both-wrap {
  display: grid;
  gap: 16px;
}

.both-wrap > div > h3 {
  margin: 0 8px 6px;
  color: #2bad81;
  font-size: clamp(18px, 2vw, 28px);
  font-weight: 500;
}

.both-wrap > div:first-child > h3 {
  text-align: left;
}

.both-wrap > div:last-child > h3 {
  text-align: right;
}

.placeholder h3 {
  margin: 0 0 12px;
  text-align: center;
  color: #2bad81;
  font-size: clamp(30px, 3vw, 50px);
  font-weight: 500;
}

.placeholder {
  border: 1px solid var(--card-border);
  padding: 14px;
  background: #fff;
}

.hidden {
  display: none !important;
}

.item-wrap {
  display: grid;
  gap: 4px;
}

.item-time {
  margin: 0;
  color: #6b7280;
  font-size: clamp(11px, 1vw, 13px);
  padding-inline: 8px;
}

.item-card {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  gap: 9px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  background: #f7f7f8;
  touch-action: pan-y;
  transition: transform 0.18s ease, border-color 0.18s ease, background-color 0.18s ease;
}

.item-card.starred {
  border-color: rgba(245, 158, 11, 0.55);
  background: #fffaf0;
}

.item-card.incoming-new {
  animation: receivedGlow 2.4s ease-out;
}

@keyframes receivedGlow {
  0% { box-shadow: 0 0 0 4px rgba(34, 179, 94, 0.45); }
  100% { box-shadow: 0 0 0 0 rgba(34, 179, 94, 0); }
}

.item-card.swiping {
  background: #fee2e2;
  transition: none;
}

.badge {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
}

.badge.red { background: var(--danger); }
.badge.orange {
  background: var(--warn);
  animation: pulse 1.4s ease-in-out infinite;
}
.badge.green { background: var(--ok); }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(243, 156, 18, 0.4); }
  100% { box-shadow: 0 0 0 12px rgba(243, 156, 18, 0); }
}

.item-title {
  margin: 0;
  font-size: clamp(14px, 1.2vw, 17px);
  font-weight: 700;
}

.item-meta {
  margin: 2px 0 0;
  color: #4b5563;
  font-size: clamp(12px, 1vw, 14px);
}

.wave-btn {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 2px solid rgba(0, 0, 0, 0.24);
  background: #f0f4f7;
  font-size: 18px;
  cursor: pointer;
}

.star-btn,
.delete-btn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: transparent;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.star-btn {
  color: #8a6b12;
}

.star-btn.active {
  color: #f59e0b;
  background: #fff2bf;
}

.delete-btn {
  color: #991b1b;
  background: #fee2e2;
  font-size: 24px;
}

.composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  margin: 0;
  padding: 8px max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  border-radius: 0;
  border: 0;
  border-top: 1px solid rgba(0, 0, 0, 0.12);
  background: rgba(245, 247, 248, 0.98);
  box-shadow: 0 10px 30px rgba(17, 24, 39, 0.16);
}

.clip {
  grid-column: 1;
  grid-row: 1;
  justify-self: start;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  color: #111827;
}

.camera {
  grid-column: 1;
  grid-row: 1;
  justify-self: start;
  margin-left: 34px;
  font-size: 23px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
}

.attachment-preview {
  grid-column: 1;
  grid-row: 1;
  justify-self: start;
  display: flex;
  gap: 7px;
  align-items: center;
  min-width: 0;
  max-width: min(420px, calc(100vw - 120px));
  margin-left: 68px;
}

.attachment-thumb {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border-radius: 6px;
  object-fit: cover;
}

.file-badge {
  max-width: 260px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  background: #d9f6ea;
  color: #06573f;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 14px;
}

.remove-attachment {
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 999px;
  background: #fee2e2;
  color: #991b1b;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

#messageInput {
  grid-column: 1;
  grid-row: 2;
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  padding: 10px 13px;
  font-size: clamp(14px, 1.2vw, 16px);
  min-width: 0;
  background: #fff;
}

.send-btn {
  grid-column: 2;
  grid-row: 2;
  width: 48px;
  height: 48px;
  border-radius: 999px;
  background: #fff;
  color: #fff;
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.send-icon {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.send-wave {
  display: none;
  position: absolute;
  inset: 0;
  align-items: end;
  justify-content: center;
  gap: 2px;
  padding-bottom: 16px;
}

.send-wave i {
  width: 4px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  animation: waveRun 0.65s ease-in-out infinite;
}

.send-wave i:nth-child(1) { height: 8px; }
.send-wave i:nth-child(2) { height: 20px; animation-delay: 0.1s; }
.send-wave i:nth-child(3) { height: 15px; animation-delay: 0.15s; }
.send-wave i:nth-child(4) { height: 24px; animation-delay: 0.2s; }

@keyframes waveRun {
  0%, 100% { transform: scaleY(0.45); }
  50% { transform: scaleY(1.1); }
}

.send-btn.sending .send-icon {
  opacity: 0;
}

.send-btn.sending .send-wave {
  display: inline-flex;
}

.debug {
  margin-top: 12px;
  border: 1px solid rgba(0, 0, 0, 0.16);
  background: #edf2f4;
  border-radius: 12px;
  padding: 8px;
}

.ghost-btn {
  border-radius: 999px;
  padding: 7px 12px;
  background: #e8eff3;
  border: 1px solid rgba(0, 0, 0, 0.2);
  color: #1f2937;
  font-weight: 600;
}

.debug-body {
  margin-top: 8px;
}

#specCanvas {
  width: 100%;
  height: 160px;
  border-radius: 10px;
  background: #031728;
  border: 1px solid rgba(156, 216, 255, 0.2);
}

.stats {
  margin-top: 6px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px;
  font-size: 15px;
  color: #335474;
}

.debug-log {
  margin-top: 8px;
  background: #f9fcff;
  border-radius: 10px;
  border: 1px solid rgba(23, 84, 137, 0.2);
  height: 160px;
  overflow: auto;
  padding: 8px;
  font-size: 12px;
  white-space: pre-wrap;
}

.viewer-modal {
  border: 0;
  border-radius: 16px;
  width: min(560px, calc(100% - 18px));
  padding: 0;
  background: transparent;
}

.viewer-modal::backdrop {
  background: rgba(5, 21, 35, 0.4);
}

.viewer-modal article {
  background: #f7fcff;
  border: 1px solid rgba(34, 90, 139, 0.26);
  border-radius: 16px;
  padding: 12px;
}

.viewer-modal header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.settings-form,
.profile-form {
  display: grid;
  gap: 8px;
}

.settings-form label,
.profile-form label {
  display: grid;
  gap: 4px;
  font-size: 14px;
}

.settings-form input,
.settings-form select,
.profile-form input {
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  padding: 9px;
}

.settings-form .compact-check {
  display: flex;
  gap: 7px;
  align-items: center;
}

.settings-form .compact-check input {
  width: 16px;
  height: 16px;
  padding: 0;
}

.frequency-stepper {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
}

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

.frequency-stepper strong {
  text-align: center;
}

.profile-form label {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.profile-form label > input[type="text"],
.profile-form label > input[type="tel"],
.profile-form label > input[type="email"],
.profile-form label > input[type="file"] {
  grid-column: 1 / -1;
}

.profile-form input[type="checkbox"] {
  width: 18px;
  height: 18px;
  padding: 0;
}

.profile-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

@media (min-width: 900px) {
  .both-wrap {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 860px) {
  .header-right {
    gap: 8px;
  }

  .icon-btn {
    font-size: 21px;
  }

  .brand {
    font-size: clamp(18px, 3.2vw, 24px);
  }

  .sub {
    font-size: clamp(10px, 2vw, 13px);
  }

  .tab-btn {
    font-size: clamp(12px, 2.2vw, 15px);
  }

  .item-title {
    font-size: clamp(13px, 2.2vw, 16px);
  }

  .item-meta {
    font-size: clamp(11px, 1.8vw, 13px);
  }

  #messageInput {
    font-size: clamp(14px, 2vw, 19px);
  }

  .send-btn {
    width: 46px;
    height: 46px;
  }
}

@media (max-width: 640px) {
  .header-left {
    gap: 6px;
  }

  .header-logo {
    width: 36px;
    height: 36px;
  }

  .header-right {
    gap: 6px;
  }

  .mic-toggle {
    width: 40px;
    height: 40px;
    padding: 8px;
  }

  .composer {
    grid-template-columns: 1fr auto;
  }

  main {
    padding: 8px 8px 108px;
  }

  .item-card {
    gap: 6px;
    grid-template-columns: auto 1fr auto auto;
  }

  .delete-btn {
    display: none;
  }
}
