:root {
  --font-title: "Trebuchet MS", "Segoe UI", sans-serif;
  --font-body: "Segoe UI", Tahoma, Arial, sans-serif;

  --bg: #f2f7f7;
  --surface: #ffffff;
  --surface-muted: #ebf4f4;
  --text: #1c2427;
  --text-muted: #4f5e66;

  --brand: #0b5c5f;
  --brand-strong: #083f41;
  --brand-soft: #2c8f92;

  --danger: #b5383f;
  --border: #d0dde0;
  --shadow: 0 12px 30px rgba(7, 48, 52, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="SYSTEM"] {
    --bg: #0f1618;
    --surface: #172125;
    --surface-muted: #1d2a30;
    --text: #e8f0f1;
    --text-muted: #a7bcc2;
    --brand: #48bfc3;
    --brand-strong: #98eef0;
    --brand-soft: #2e9094;
    --danger: #f28d95;
    --border: #2f3f45;
    --shadow: 0 12px 30px rgba(2, 8, 9, 0.4);
  }
}

:root[data-theme="DARK"] {
  --bg: #0f1618;
  --surface: #172125;
  --surface-muted: #1d2a30;
  --text: #e8f0f1;
  --text-muted: #a7bcc2;
  --brand: #48bfc3;
  --brand-strong: #98eef0;
  --brand-soft: #2e9094;
  --danger: #f28d95;
  --border: #2f3f45;
  --shadow: 0 12px 30px rgba(2, 8, 9, 0.4);
}

:root[data-theme="LIGHT"] {
  --bg: #f2f7f7;
  --surface: #ffffff;
  --surface-muted: #ebf4f4;
  --text: #1c2427;
  --text-muted: #4f5e66;
  --brand: #0b5c5f;
  --brand-strong: #083f41;
  --brand-soft: #2c8f92;
  --danger: #b5383f;
  --border: #d0dde0;
  --shadow: 0 12px 30px rgba(7, 48, 52, 0.12);
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    radial-gradient(circle at 10% -15%, rgba(44, 143, 146, 0.24), transparent 45%),
    radial-gradient(circle at 100% 0%, rgba(11, 92, 95, 0.18), transparent 35%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
}

.topbar > div:first-child {
  flex: 1;
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-family: var(--font-title);
  font-size: 1.2rem;
  letter-spacing: 0.2px;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.app-shell.logged-in .topbar {
  padding-top: 10px;
  padding-bottom: 10px;
}

.app-shell.logged-in .topbar h1 {
  font-size: 1.08rem;
}

.app-shell.logged-in #connectionInfo {
  margin: 0;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  justify-content: flex-end;
  align-items: center;
}

.topbar-actions .btn {
  padding: 7px 11px;
  font-size: 0.9rem;
  border-radius: 10px;
  line-height: 1.1;
  white-space: nowrap;
}

.topbar-clock {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.topbar-db-status {
  min-width: 78px;
  padding: 5px 9px;
  font-size: 0.76rem;
  border-radius: 10px;
  line-height: 1.1;
  white-space: nowrap;
}

.topbar-db-status.status-online {
  background: color-mix(in srgb, #2f9b67 18%, var(--surface));
  color: #1f7f54;
  border-color: color-mix(in srgb, #2f9b67 40%, var(--border));
}

.topbar-db-status.status-offline {
  background: color-mix(in srgb, var(--danger) 14%, var(--surface));
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}

.topbar-db-status.status-checking {
  background: var(--surface-muted);
  color: var(--text-muted);
  border-color: var(--border);
}

.app-shell.logged-in .topbar-actions {
  gap: 6px;
}

.app-shell.logged-in .topbar-actions .btn {
  padding: 6px 10px;
  font-size: 0.86rem;
}

.app-shell.logged-in .topbar-clock {
  font-size: 0.76rem;
}

.app-shell.logged-in .topbar-db-status {
  font-size: 0.72rem;
  min-width: 70px;
}

.app-shell.logged-in .topbar-actions .topbar-db-status {
  min-width: 58px;
  padding: 4px 8px;
  font-size: 0.68rem;
}

.screen-wrap {
  flex: 1;
  width: min(880px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.card h2 {
  margin-top: 0;
  margin-bottom: 14px;
  font-family: var(--font-title);
}

.card h3 {
  margin: 20px 0 8px;
  font-family: var(--font-title);
}

label {
  display: block;
  margin: 12px 0 6px;
  font-weight: 600;
  color: var(--text-muted);
}

input,
select {
  width: 100%;
  padding: 13px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
}

input:disabled,
select:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent);
  outline-offset: 2px;
}

.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 14px;
  cursor: pointer;
  font-size: 0.98rem;
  font-weight: 700;
  transition: transform 0.12s ease, opacity 0.12s ease, background-color 0.12s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn:disabled:hover {
  transform: none;
}

.btn.primary {
  background: linear-gradient(140deg, var(--brand), var(--brand-soft));
  color: #fff;
}

.btn.ghost {
  background: var(--surface-muted);
  color: var(--text);
  border-color: var(--border);
}

.btn.danger {
  background: color-mix(in srgb, var(--danger) 15%, var(--surface));
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}

.btn.tile {
  min-height: 62px;
  text-align: left;
}

.btn.block {
  width: 100%;
  margin-top: 16px;
}

.actions {
  margin-top: 16px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.actions .btn {
  flex: 1;
  min-width: 130px;
}

.actions-secondary {
  margin-top: 10px;
}

.grid-buttons {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.menu-board {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  max-width: 440px;
}

.menu-tile {
  display: grid;
  grid-template-rows: 1fr auto;
  justify-items: center;
  align-items: stretch;
  min-height: 150px;
  border: 1px solid #99d5da;
  border-radius: 6px;
  padding: 14px 10px 10px;
  background:
    linear-gradient(180deg, #1689a1 0%, #0f7890 58%, #0d6f85 100%);
  color: #fff;
  font: 700 1rem/1 var(--font-body);
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(3, 61, 72, 0.22);
  transition: transform 0.12s ease, filter 0.12s ease, opacity 0.12s ease;
}

.menu-tile:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

.menu-tile:active {
  transform: translateY(0);
}

.menu-tile:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.3);
}

.menu-tile svg {
  width: 62px;
  height: 62px;
  align-self: center;
  stroke: #ffffff;
  stroke-width: 2.2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.menu-tile span {
  align-self: end;
  font-size: 1.02rem;
}

.choice-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--surface-muted);
}

.choice.muted {
  opacity: 0.65;
}

.choice input {
  width: auto;
  margin: 0;
}

.split-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.hint {
  margin: 10px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.summary-box {
  margin: 0;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  white-space: pre-wrap;
  font: 500 0.95rem/1.35 var(--font-body);
}

.indicators {
  margin: 0 0 8px;
  color: var(--text-muted);
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.selected-item-info {
  margin: 12px 0 0;
  color: var(--text-muted);
  font-weight: 600;
}

.item-tabs {
  display: flex;
  gap: 8px;
  margin: 10px 0 10px;
}

.tab-btn {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-muted);
  color: var(--text-muted);
  padding: 9px 10px;
  font-weight: 700;
  cursor: pointer;
}

.tab-btn.active {
  background: linear-gradient(140deg, var(--brand), var(--brand-soft));
  color: #fff;
  border-color: color-mix(in srgb, var(--brand-soft) 70%, var(--border));
}

.item-row {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 10px;
  font-size: 0.92rem;
  cursor: default;
  transition: border-color 0.12s ease, transform 0.12s ease;
}

.item-row.selectable {
  cursor: pointer;
}

.item-row.selectable:hover {
  border-color: color-mix(in srgb, var(--brand) 45%, var(--border));
}

.item-row.pending-focus {
  background: rgba(255, 182, 108, 0.18);
  animation: pendingPulse 3.8s ease-in-out infinite;
}

.item-row.done-focus {
  background: rgba(146, 221, 171, 0.2);
  animation: donePulse 3.8s ease-in-out infinite;
}

.item-row.selected {
  border-color: color-mix(in srgb, var(--brand) 70%, var(--border));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand) 60%, transparent);
}

.item-row.empty {
  color: var(--text-muted);
  border-style: dashed;
  cursor: default;
}

.item-row.ok {
  border-left: 6px solid #2f9b67;
}

.item-row.warn {
  border-left: 6px solid #e1992f;
}

.item-row.danger {
  border-left: 6px solid var(--danger);
}

@keyframes pendingPulse {
  0%,
  100% {
    background-color: rgba(255, 182, 108, 0.16);
    border-color: color-mix(in srgb, #f0af67 35%, var(--border));
    box-shadow: 0 0 0 rgba(240, 175, 103, 0);
  }
  50% {
    background-color: rgba(255, 182, 108, 0.34);
    border-color: color-mix(in srgb, #f0af67 70%, var(--border));
    box-shadow: 0 0 0 1px rgba(240, 175, 103, 0.45), 0 0 12px rgba(240, 175, 103, 0.28);
  }
}

@keyframes donePulse {
  0%,
  100% {
    background-color: rgba(146, 221, 171, 0.18);
    border-color: color-mix(in srgb, #67b883 35%, var(--border));
    box-shadow: 0 0 0 rgba(103, 184, 131, 0);
  }
  50% {
    background-color: rgba(146, 221, 171, 0.36);
    border-color: color-mix(in srgb, #67b883 70%, var(--border));
    box-shadow: 0 0 0 1px rgba(103, 184, 131, 0.45), 0 0 12px rgba(103, 184, 131, 0.28);
  }
}

@media (prefers-reduced-motion: reduce) {
  .item-row.pending-focus,
  .item-row.done-focus {
    animation: none;
  }
}

dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  width: min(460px, 95vw);
  background: var(--surface);
  color: var(--text);
}

dialog::backdrop {
  background: rgba(6, 13, 14, 0.52);
}

.dialog-form {
  padding: 18px;
}

.dialog-form h2 {
  margin-top: 0;
  font-family: var(--font-title);
}

.dialog-form h3 {
  margin: 18px 0 6px;
  font-family: var(--font-title);
  font-size: 1rem;
  color: var(--text-muted);
}

.read-dialog {
  width: min(620px, 96vw);
}

.read-dialog-item-info {
  margin: 0 0 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-muted);
  font-weight: 600;
  color: var(--text);
}

.read-dialog-item-info.error {
  border-color: #b24b4b;
  background: rgba(178, 75, 75, 0.14);
  color: #8d1e1e;
}

.read-dialog-item-info.error.qty-over-msg {
  border-color: #cf2a2a;
  background: rgba(207, 42, 42, 0.14);
  color: #c00000;
  font-weight: 800;
}

.read-feedback {
  margin: 8px 0 0;
  padding: 8px 10px;
  border: 1px solid #b24b4b;
  border-radius: 8px;
  background: rgba(178, 75, 75, 0.12);
  color: #8d1e1e;
  font-weight: 600;
}

.read-feedback.qty-over-msg {
  border-color: #cf2a2a;
  background: rgba(207, 42, 42, 0.14);
  color: #c00000;
  font-weight: 800;
}

.toast {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  min-width: 220px;
  max-width: 90vw;
  background: #0d1d20;
  color: #fff;
  border-radius: 12px;
  padding: 11px 14px;
  text-align: center;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.3);
  z-index: 60;
}

.hidden {
  display: none !important;
}

@media (min-width: 760px) {
  .grid-buttons {
    grid-template-columns: 1fr 1fr;
  }

  .card {
    padding: 22px;
  }

  .menu-board {
    max-width: 520px;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 10px 10px;
  }

  .app-shell.logged-in .topbar {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .topbar-clock {
    font-size: 0.72rem;
  }

  .topbar-db-status {
    min-width: 56px;
    font-size: 0.66rem;
    padding: 4px 7px;
  }

  .app-shell.logged-in .topbar-actions .topbar-db-status {
    min-width: 52px;
    padding: 3px 7px;
    font-size: 0.64rem;
  }

  .screen-wrap {
    padding: 6px;
  }

  .card {
    padding: 10px;
    border-radius: 12px;
  }

  .menu-board {
    max-width: 100%;
    gap: 8px;
  }

  #screen-menu .card h2 {
    margin-bottom: 8px;
  }

  #screen-menu .menu-tile {
    min-height: 132px;
    padding: 10px 8px 8px;
  }

  #screen-menu .menu-tile svg {
    width: 52px;
    height: 52px;
  }
}

@media (max-width: 480px) {
  .split-fields {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
}
