* {
  box-sizing: border-box;
}

:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --border: #e5e7eb;
  --danger: #dc2626;
  --modal-border: #000000;
}

:root[data-theme="dark"] {
  --bg: #0f172a;
  --card: #1e293b;
  --text: #f9fafb;
  --muted: #94a3b8;
  --primary: #60a5fa;
  --border: #334155;
  --danger: #f87171;
  --modal-border: #ffffff;
}

html {
  height: 100%;
}

body {
  height: calc(var(--app-vh, 1vh) * 100);
  min-height: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  flex: 0 0 auto;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 12px 4px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#app-title {
    margin: 0;
}

.header-top,
.header-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

body.auth-screen .header-top {
  justify-content: center;
  align-items: center;
  min-height: 35px;
}

body.auth-screen .header-left {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

body.auth-screen .header-right {
  display: none;
}

body.auth-screen #app-title {
  text-align: center;
}

.container {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
}

body.auth-screen .container {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding-bottom: 12px;
}

.login-card {
  width: min(100%, 500px);
}

.app-footer {
  flex: 0 0 auto;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
}

.footer-content {
  display: grid;
  gap: 8px;
}

.footer-toolbar {
  display: grid;
  gap: 8px;
}

.footer-toolbar-empty {
  min-height: 35px;
}

.footer-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.footer-left,
.footer-right {
  min-width: 0;
}

.footer-right {
  display: flex;
  justify-content: flex-end;
  flex: 1 1 auto;
}

.requests-footer-toolbar .footer-left .footer-row,
.requests-footer-toolbar .footer-right .footer-row {
  flex-wrap: nowrap;
  overflow-x: auto;
}

.footer-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.centered-footer .footer-row {
  justify-content: center;
}

.footer-row button {
  flex: 0 0 auto;
  min-height: 35px;
}

.mobile-only {
  display: none;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button {
  border: 1px solid var(--border);
  background: transparent;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
}

button.primary {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
}

button.danger {
  background: var(--danger);
  color: #fff;
  border-color: transparent;
}

button.warning {
  background: #f59e0b;
  color: #fff;
  border-color: transparent;
}

button.ghost {
  background: transparent;
}

.offline {
  padding: 6px 10px;
  border-radius: 16px;
  background: var(--danger);
  color: #fff;
  font-size: 12px;
}

.hidden {
  display: none !important;
}

.card,
.panel {
  background: var(--card);
  border-radius: 16px;
  padding: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
}

h3 {
  margin: 0 0 12px;
}

.form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  font-weight: 600;
}

input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: transparent;
  color: var(--text);
}

.row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.login-actions {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.login-version {
  grid-column: 1;
  justify-self: start;
  margin: 0;
}

.login-submit-button {
  grid-column: 2;
  justify-self: center;
}

.login-theme-button {
  grid-column: 3;
  justify-self: end;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 12px;
}

.muted {
  color: var(--muted);
}

.sub-info {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 4px;
  font-size: 14px;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.requests-info {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.header-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  width: 35px;
  height: 35px;
  min-width: 35px;
  font-weight: 600;
  line-height: 1;
  text-align: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
}

.error {
  color: var(--danger);
  font-weight: 600;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.table {
  display: grid;
  gap: 10px;
}

.table-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  cursor: pointer;
}

.requests-table .table-row {
  grid-template-columns: 64px 1.1fr 1.5fr 1.2fr 1.2fr 80px;
}

.requests-table .cell-emoji {
  text-align: center;
  font-size: 18px;
}

.requests-table .table-row:not(.header) {
  display: block;
}

.desktop-only-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
}

.desktop-only-grid span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.requests-table .table-row.header {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.requests-table .table-row.header span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.mobile-only-block {
  display: none;
}

.request-mobile-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
}

.request-mobile-route {
  font-size: 12px;
  line-height: 1.2;
  color: var(--muted);
}

.request-mobile-status-text {
  font-size: 12px;
  line-height: 1.2;
  font-weight: 600;
}

.request-mobile-date {
  font-size: 12px;
  line-height: 1.2;
}

.request-mobile-patient {
  font-size: 14px;
  line-height: 1.25;
}

.request-mobile-center {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.request-mobile-center > div {
  min-width: 0;
  overflow-wrap: anywhere;
}

.desktop-only-inline {
  display: inline;
}

.mobile-only-inline {
  display: none;
}

.table-row.header {
  font-weight: 700;
  cursor: default;
  background: var(--bg);
}

.monitor-table .monitor-col-hidden {
  display: none;
}

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

.monitor-table .table-row:not(.header) {
  display: block;
}

.monitor-desktop-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
}

.monitor-mobile-block {
  display: none;
}

.monitor-mobile-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.monitor-mobile-line span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.statistics-table .table-row.stats-cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.statistics-table .table-row.stats-total-row {
  font-weight: 700;
}

.detail-grid {
  display: grid;
  gap: 12px;
}

.detail-grid div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px dashed var(--border);
  padding-bottom: 6px;
}

.detail-grid div span {
  flex: 1 1 55%;
}

.detail-grid div strong {
  flex: 1 1 45%;
  text-align: right;
}

.detail-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal {
  background: var(--card);
  color: var(--text);
  border: 2px solid var(--modal-border);
  border-radius: 16px;
  padding: 16px;
  width: min(420px, 100%);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.modal h3 {
  margin: 0;
}

.modal-message {
  margin: 12px 0 0;
  white-space: pre-line;
}

.info-modal {
  width: min(520px, 100%);
}

.info-modal-content {
  display: grid;
  gap: 10px;
  margin: 12px 0 16px;
}

.info-modal-line {
  margin: 0;
}

.info-modal-description {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  max-height: min(32vh, 220px);
  overflow-y: auto;
  white-space: pre-line;
}

.modal-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 16px;
}

.modal-list button {
  width: 100%;
  text-align: left;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
}

.qr-scan-modal {
  width: min(520px, 100%);
  height: auto;
  display: block;
}

.qr-scan-frame {
  position: relative;
  background: #111827;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: auto;
  height: 50vh;
  display: grid;
  place-items: center;
}

.qr-scan-modal .modal-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 16px;
}

.qr-scan-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #111827;
}

.qr-scan-hint {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(17, 24, 39, 0.72);
  color: #fff;
  font-size: 12px;
  text-align: center;
}

.qr-scan-error {
  min-height: 60px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: transparent;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  line-height: 1.35;
  cursor: default;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.qr-scan-error.has-message {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.12);
  color: #b91c1c;
  visibility: visible;
  opacity: 1;
  pointer-events: none;
}

.qr-scan-error.has-message.is-success {
  border-color: #22c55e;
  background: #dcfce7;
  color: #166534;
}

:root[data-theme="dark"] .qr-scan-error.has-message.is-success {
  border-color: #22c55e;
  background: #052e16;
  color: #86efac;
}

.qr-modal-actions {
  justify-content: flex-start;
  gap: 12px;
}

.qr-modal-actions .qr-close-button {
  margin-left: auto;
}

.modal-actions-sticky {
  position: sticky;
  bottom: 0;
  background: var(--card);
  padding-top: 8px;
}

.medcard-modal .modal-list {
  margin-bottom: 8px;
}

.medcard-modal-input {
  width: 100%;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

.stat-grid div {
  background: var(--bg);
  padding: 16px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-rows {
  display: grid;
  gap: 16px;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(140px, 1fr));
  gap: 16px;
}

.stat-row div {
  background: var(--bg);
  padding: 16px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-header h3 {
  margin: 0;
}

.statistics-chart-wrap {
  position: relative;
  width: 100%;
  height: min(58vh, 520px);
  min-height: 320px;
}

.statistics-chart-canvas {
  width: 100% !important;
  height: 100% !important;
}

.statistics-metric-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
}

.statistics-metric-label {
  color: var(--muted);
  font-weight: 600;
}

.statistics-metric-button {
  min-width: 44px;
  text-align: center;
  font-weight: 700;
}

.info-page-description {
  display: grid;
  gap: 8px;
}

.info-page-description p {
  margin: 0;
}

.info-page-changes {
  white-space: pre-wrap;
}

.statistics-footer-line {
  align-items: center;
  justify-content: space-between;
}

.statistics-footer-line .footer-left,
.statistics-footer-line .footer-right,
.statistics-footer-line .footer-center {
  flex: 1 1 0;
  display: flex;
}

.statistics-footer-line .footer-left {
  justify-content: flex-start;
}

.statistics-footer-line .footer-center {
  justify-content: center;
}

.statistics-footer-line .footer-right {
  justify-content: flex-end;
}


@media (max-width: 900px) {
  .modal-overlay-mobile-safe {
    align-items: flex-start;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .modal-mobile-safe {
    width: min(420px, 100%);
    max-height: calc(100dvh - 16px);
    overflow-y: auto;
  }
  .desktop-only {
    display: none !important;
  }
  .mobile-only {
    display: flex !important;
  }
  .mobile-only.hidden {
    display: none !important;
  }
  .nav {
    display: none !important;
  }
  .app-header {
    padding-left: 10px;
    padding-right: 10px;
  }
  .header-top {
    align-items: flex-start;
  }
  .header-left {
    width: 100%;
    display: flex;
    justify-content: center;
  }
  #app-title {
    text-align: center;
  }
  .header-bottom {
    flex-wrap: nowrap;
    align-items: center;
  }
  .header-bottom .header-indicator {
    display: inline-flex;
    align-items: center;
    min-height: 35px;
  }
  #menu-button {
    min-height: 35px;
    margin-left: auto;
  }
  .container {
    padding: 10px;
  }
  body.auth-screen .container {
    align-items: center;
    justify-content: center;
    padding-bottom: 10px;
  }
  .login-card {
    width: 100%;
    max-width: 100%;
  }
  .app-footer {
    padding-left: 10px;
    padding-right: 10px;
  }
  .table-row {
    grid-template-columns: repeat(2, 1fr);
  }
  .requests-table .table-row {
    grid-template-columns: 1fr;
    padding: 8px 10px;
    border-width: 3px;
  }
  .desktop-only-grid {
    display: none !important;
  }
  .mobile-only-block {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: center;
    gap: 4px;
  }
  .requests-table .table-row.request-type-0 {
    border-color: #22c55e;
  }
  .requests-table .table-row.request-type-1 {
    border-color: #eab308;
  }
  .requests-table .table-row.request-type-2 {
    border-color: #ef4444;
  }
  .desktop-only-inline {
    display: none;
  }
  .mobile-only-inline {
    display: inline;
  }
  .requests-table .cell-emoji {
    font-size: 16px;
    text-align: left;
  }
  .requests-table .table-row span {
    min-width: 0;
    overflow-wrap: anywhere;
  }
  .monitor-desktop-grid {
    display: none;
  }
  .monitor-mobile-block {
    display: grid;
    gap: 6px;
    font-size: 13px;
  }
  .statistics-table .table-row:not(.header) {
    font-size: 13px;
  }
  .statistics-table .table-row {
    gap: 0;
  }
  .statistics-table .table-row.stats-cols-3 {
    grid-template-columns: 50% 30% 20%;
  }
  .statistics-table .table-row.stats-cols-4 {
    grid-template-columns: 50% 10% 15% 25%;
  }
  .statistics-table .table-row.stats-cols-3 > span:nth-child(1),
  .statistics-table .table-row.stats-cols-4 > span:nth-child(1) {
    text-align: left;
  }
  .statistics-table .table-row.stats-cols-3 > span:nth-child(2),
  .statistics-table .table-row.stats-cols-3 > span:nth-child(3),
  .statistics-table .table-row.stats-cols-4 > span:nth-child(2),
  .statistics-table .table-row.stats-cols-4 > span:nth-child(3),
  .statistics-table .table-row.stats-cols-4 > span:nth-child(4) {
    text-align: right;
  }
  .statistics-chart-wrap {
    height: 340px;
    min-height: 260px;
  }
  .detail-grid .details-type-row {
    display: none;
  }
  .panel.detail-type-0 {
    border: 3px solid #22c55e;
  }
  .panel.detail-type-1 {
    border: 3px solid #eab308;
  }
  .panel.detail-type-2 {
    border: 3px solid #ef4444;
  }
  .table-row.header {
    display: none;
  }
  .stat-rows {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }
  .stat-row {
    grid-template-columns: 1fr;
  }
}


