:root {
  color-scheme: light;
  --bg: #dddddd;
  --surface: #efefef;
  --surface-strong: #ffffff;
  --surface-muted: #f7f7f7;
  --header: #171717;
  --line: #d3d3d3;
  --line-strong: #bfbfbf;
  --text: #232323;
  --muted: #666666;
  --accent: #9cdd72;
  --accent-strong: #5f9e41;
  --accent-soft: #dff3cf;
  --danger: #d46a65;
  --danger-soft: #fff1ef;
  --warn: #b87a00;
  --toast: rgba(24, 24, 24, 0.94);
  --shadow: 0 10px 24px rgba(0, 0, 0, 0.08);
  --radius-lg: 8px;
  --radius-md: 6px;
  --field-h: 40px;
  --font-ui: "Segoe UI", Tahoma, sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f0f;
  --surface: #151515;
  --surface-strong: #1d1d1d;
  --surface-muted: #181818;
  --header: #111111;
  --line: #313131;
  --line-strong: #3e3e3e;
  --text: #f1f1f1;
  --muted: #b8b8b8;
  --accent: #91d26a;
  --accent-strong: #81c15c;
  --accent-soft: rgba(145, 210, 106, 0.18);
  --danger: #eb8c86;
  --danger-soft: rgba(235, 140, 134, 0.08);
  --warn: #ffc55d;
  --toast: rgba(10, 10, 10, 0.96);
  --shadow: 0 14px 32px rgba(0, 0, 0, 0.28);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
}

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

.page {
  min-height: 100dvh;
}

.app-shell {
  width: 100%;
  max-width: 420px;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(9px + env(safe-area-inset-top)) 12px 10px;
  background: var(--header);
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
}

.topbar-user {
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: rgba(255, 255, 255, 0.78);
  font-size: 13px;
}

.logout-form {
  margin: 0;
}

.hero-logo {
  display: block;
  width: 160px;
  max-width: 52%;
  height: 28px;
  object-fit: contain;
}

.submit-btn,
.action-btn,
.theme-switch,
.link-btn,
.toast-close,
.icon-btn {
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
}

.submit-btn {
  min-height: 36px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--accent-strong);
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.submit-btn:disabled {
  opacity: 0.65;
  cursor: default;
}

.submit-btn-top {
  flex: 0 0 auto;
  white-space: nowrap;
}

.form-panel {
  padding: 10px 12px calc(18px + env(safe-area-inset-bottom));
}

.form-grid {
  display: grid;
  gap: 6px;
}

.field {
  display: block;
}

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

.field-header label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.field-tools {
  display: inline-flex;
  gap: 6px;
}

.control-wrap {
  position: relative;
}

.field-tools-floating {
  position: absolute;
  top: 50%;
  right: 8px;
  z-index: 3;
  transform: translateY(-50%);
}

.field-tools-floating-textarea {
  top: 8px;
  transform: none;
}

.input-shell,
.select-shell,
.textarea-shell {
  display: flex;
  align-items: stretch;
  min-height: var(--field-h);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.field-phone .input-shell {
  border-color: rgba(95, 158, 65, 0.55);
}

.textarea-shell {
  min-height: 68px;
}

.textarea-shell-readonly {
  min-height: 84px;
}

.field-icon {
  width: 34px;
  min-width: 34px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--surface-muted);
  border-right: 1px solid var(--line);
}

.field-icon-top {
  align-items: start;
  padding-top: 10px;
}

.input-shell input,
.select-shell select,
.textarea-shell textarea {
  width: 100%;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  padding: 0 10px;
  font-size: 14px;
}

.has-actions input,
.has-actions textarea {
  padding-right: 74px;
}

.input-shell input,
.select-shell select {
  min-height: calc(var(--field-h) - 2px);
}

.textarea-shell textarea {
  min-height: 68px;
  padding: 8px 10px;
  resize: vertical;
}

.textarea-shell-readonly textarea {
  min-height: 84px;
}

select option {
  color: #111111;
}

html[data-theme="dark"] select option {
  color: #f1f1f1;
  background: #1b1b1b;
}

.input-shell:focus-within,
.select-shell:focus-within,
.textarea-shell:focus-within {
  border-color: rgba(95, 158, 65, 0.75);
  box-shadow: 0 0 0 3px rgba(156, 221, 114, 0.18);
}

.field.invalid .input-shell,
.field.invalid .select-shell,
.field.invalid .textarea-shell {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.error-text {
  min-height: 16px;
  padding-top: 2px;
  font-size: 11px;
  color: var(--danger);
}

.icon-btn,
.action-btn,
.theme-switch,
.link-btn {
  background: var(--surface-strong);
  border-color: var(--line);
  color: var(--text);
}

.link-btn-dark {
  min-height: 34px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  font-size: 13px;
}

.icon-btn {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  padding: 0;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03);
}

.voice-btn.is-listening {
  animation: pulse-ring 1s ease-in-out infinite;
  border-color: var(--accent-strong);
  background: var(--accent-soft);
}

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(156, 221, 114, 0.4); }
  70% { box-shadow: 0 0 0 8px rgba(156, 221, 114, 0); }
  100% { box-shadow: 0 0 0 0 rgba(156, 221, 114, 0); }
}

.status-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.status-switch input {
  display: none;
}

.status-switch label {
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}

.status-switch input:checked + label {
  background: var(--accent);
  border-color: rgba(95, 158, 65, 0.3);
  color: #24331b;
}

html[data-theme="dark"] .status-switch input:checked + label {
  color: #0f150b;
}

.zamer-card {
  padding: 10px;
  border-radius: var(--radius-lg);
  background: var(--accent);
}

.zamer-card-title {
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #264117;
}

.zamer-card-grid {
  display: grid;
  gap: 6px;
}

.zamer-row .error-text {
  color: #8f2e2a;
}

.partner-inline {
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid rgba(95, 158, 65, 0.2);
  border-radius: var(--radius-lg);
  background: #edf8e6;
  color: #2f4f1f;
  font-size: 13px;
  line-height: 1.35;
}

html[data-theme="dark"] .partner-inline {
  background: rgba(145, 210, 106, 0.12);
  color: #d6efc8;
}

.details-box {
  margin-top: 10px;
}

.details-box summary {
  list-style: none;
  padding: 8px 2px;
  color: #4c79c6;
  font-size: 14px;
  cursor: pointer;
}

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

.details-content {
  display: grid;
  gap: 7px;
  padding-top: 4px;
}

.details-tools,
.status-bottom {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.action-btn,
.theme-switch,
.link-btn {
  min-height: 34px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}

.status-chip {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
}

.status-chip[data-state="ok"] {
  color: var(--accent-strong);
}

.status-chip[data-state="warn"] {
  color: var(--warn);
}

.status-chip[data-state="error"] {
  color: var(--danger);
}

.mini-grid {
  display: grid;
  gap: 7px;
}

.mini-card {
  padding: 9px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.mini-title {
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
}

.mini-text {
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
}

.warn-text {
  color: var(--warn);
}

.toast-stack {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 999;
  display: grid;
  gap: 8px;
  width: min(92vw, 360px);
  transform: translateX(-50%);
}

.has-voice-panel .toast-stack {
  bottom: calc(86px + env(safe-area-inset-bottom));
}

.toast-card {
  position: relative;
  display: none;
  padding: 12px 38px 12px 12px;
  background: var(--toast);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24);
}

.toast-card.visible {
  display: block;
}

.toast-card p {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
}

.toast-card[data-kind="success"] {
  border-color: rgba(156, 221, 114, 0.45);
}

.toast-card[data-kind="warning"] {
  border-color: rgba(255, 197, 93, 0.45);
}

.toast-card[data-kind="danger"] {
  border-color: rgba(212, 106, 101, 0.45);
}

.toast-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  padding: 0;
  background: transparent;
  color: #ffffff;
}

.voice-panel {
  position: fixed;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  left: 12px;
  z-index: 998;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(24, 24, 24, 0.94);
  color: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.22);
}

.voice-panel-text {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
}

.voice-panel-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(156, 221, 114, 0.5);
  animation: pulse-ring 1s ease-in-out infinite;
}

.voice-stop-btn {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

svg.icon {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.auth-screen {
  padding: 24px 12px calc(24px + env(safe-area-inset-bottom));
}

.auth-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.auth-title {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
}

.auth-subtitle,
.auth-note,
.auth-error {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
}

.auth-subtitle,
.auth-note {
  color: var(--muted);
}

.auth-error {
  padding: 10px 12px;
  border: 1px solid rgba(212, 106, 101, 0.32);
  border-radius: var(--radius-md);
  background: var(--danger-soft);
  color: var(--danger);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-strong);
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table-wrap th,
.table-wrap td {
  padding: 10px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

.table-wrap th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

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

.mono {
  font-family: Consolas, "Courier New", monospace;
}

@media (min-width: 421px) {
  .app-shell {
    margin: 12px auto;
    min-height: calc(100dvh - 24px);
    border-radius: var(--radius-lg);
    overflow: hidden;
  }

  .voice-panel {
    left: auto;
    width: 360px;
  }
}

@media (max-width: 420px) {
  .topbar-user {
    display: none;
  }
}

@media (max-width: 380px) {
  .topbar {
    gap: 8px;
    padding-left: 10px;
    padding-right: 10px;
  }

  .topbar-actions {
    gap: 6px;
  }

  .topbar-user {
    display: none;
  }

  .submit-btn-top,
  .link-btn-dark {
    padding-left: 10px;
    padding-right: 10px;
  }

  .field-tools-floating {
    right: 6px;
  }

  .has-actions input,
  .has-actions textarea {
    padding-right: 68px;
  }

  .voice-panel {
    right: 8px;
    left: 8px;
  }
}
