* { box-sizing: border-box; }
html { font-size: 16px; color-scheme: dark; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, "Noto Sans", "Liberation Sans", sans-serif;
  line-height: 1.5;
  background: #1a1a1a;
  color: #e0e0e0;
}

:root {
  --bg: #1a1a1a;
  --surface: #2d2d2d;
  --surface-2: #404040;
  --text: #e0e0e0;
  --text-strong: #ffffff;
  --border: #404040;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 8px 18px rgba(0, 0, 0, 0.35);
  --focus: #7aa7ff;
  --accent: #1f5bd6;
  --accent-strong: #1743a6;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 16px;
  --radius-sm: 12px;
  --tap: 44px;
}

a { color: var(--text); text-decoration-thickness: 2px; text-underline-offset: 3px; }
a:hover { color: var(--text-strong); }

:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.skip-link {
  position: absolute;
  left: 12px;
  top: 12px;
  padding: 10px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-strong);
  transform: translateY(-140%);
  transition: transform 160ms ease;
  z-index: 10000;
}
.skip-link:focus-visible { transform: translateY(0); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px;
}

h1, h2, h3 { margin: 0; color: var(--text-strong); }
h1 { font-size: clamp(22px, 2.5vw, 32px); font-weight: 750; letter-spacing: 0.2px; }
h2 { font-size: clamp(18px, 2vw, 22px); font-weight: 700; }
h3 { font-size: 18px; font-weight: 700; }
label { color: var(--text-strong); font-weight: 700; }

.toolbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}
.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-start;
}
.user-display { color: var(--text); font-size: 16px; }
.user-display strong { color: var(--text-strong); font-weight: 700; }

.app-main { display: grid; gap: 16px; }
.form-stack { display: flex; flex-direction: column; gap: 12px; max-width: 420px; }
.form-stack button { width: fit-content; }

.upload-container, .results-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}

.start-address-container { display: grid; gap: 8px; margin-bottom: 12px; }
.start-address-container label { font-weight: 700; color: var(--text-strong); }

input, select, textarea, button { font: inherit; }
input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: #1a1a1a;
  border: 1px solid var(--border);
  color: var(--text);
}
input::placeholder { color: #cfcfcf; }
input:disabled { opacity: 0.7; }

input[type="file"] { display: none; }

.upload-area {
  border: 2px dashed var(--surface-2);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(0,0,0,0.12));
  transition: transform 200ms ease, border-color 200ms ease, background 200ms ease, box-shadow 200ms ease;
}
.upload-area p { margin: 0 0 12px; color: var(--text); }
.upload-area.highlight { border-color: var(--success); box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.18), var(--shadow); transform: translateY(-1px); }

.button-container { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

.export-button, .export-button-mapy, .optimize-button, .upload-button, .toggle-button, button, [role="button"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  min-height: var(--tap);
  padding: 10px 14px;
  background: var(--surface-2);
  color: var(--text-strong);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease, border-color 160ms ease;
  text-decoration: none;
}
.export-button:hover, .export-button-mapy:hover, .optimize-button:hover, .upload-button:hover, .toggle-button:hover, button:hover, [role="button"]:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.export-button:active, .export-button-mapy:active, .optimize-button:active, .upload-button:active, .toggle-button:active, button:active, [role="button"]:active { transform: translateY(0); }
.export-button:disabled, .export-button-mapy:disabled, .optimize-button:disabled, .upload-button:disabled, .toggle-button:disabled { opacity: 0.6; cursor: not-allowed; box-shadow: none; }

.optimize-button, .upload-button { background: linear-gradient(180deg, var(--accent), var(--accent-strong)); border-color: rgba(255,255,255,0.12); }
.export-button { background: linear-gradient(180deg, #22c55e, #169a47); border-color: rgba(255,255,255,0.12); }
.export-button-mapy { background: linear-gradient(180deg, #ef4444, #b91c1c); border-color: rgba(255,255,255,0.12); }
.toggle-button { width: var(--tap); padding: 0; display: inline-grid; place-items: center; border-radius: 16px; }

.status-indicators { display: inline-flex; gap: 10px; align-items: center; }
.status-dot {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #8a8a8a;
  box-shadow: var(--shadow-sm);
}
.status-dot.ok { background: var(--success); }
.status-dot.warn { background: var(--warning); }
.status-dot.err { background: var(--danger); }

.results-container h2 { margin-bottom: 12px; }
.results-table-container {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  max-height: min(420px, 55vh);
  box-shadow: var(--shadow-sm);
}
table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  background: var(--surface);
  color: var(--text);
}
th, td { padding: 12px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: var(--surface-2); color: var(--text-strong); }
tbody tr:hover { background: rgba(255, 255, 255, 0.04); }

.warning-row { background: rgba(245, 158, 11, 0.10); }
.warning-cell { color: var(--text-strong); font-weight: 700; }
.warning-icon { margin-right: 6px; font-size: 18px; }

.progress { width: 48px; height: 48px; position: relative; transform: rotate(45deg); margin: 16px 0 8px; }
.progress:before, .progress:after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50% 50% 0 50%;
  background: transparent;
  background-image: radial-gradient(circle 12px at 50% 50%, transparent 94%, var(--accent));
}
.progress:after { animation: pulse-ytk0dhmd 1s infinite; transform: perspective(340px) translateZ(0); }
@keyframes pulse-ytk0dhmd { to { transform: perspective(340px) translateZ(170px); opacity: 0; } }
.progress-text { color: var(--text); margin-top: 10px; font-weight: 700; font-size: 16px; }

.map-container {
  width: 100%;
  height: clamp(320px, 52vh, 560px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 14px;
  box-shadow: var(--shadow);
}

.leaflet-container { background: var(--surface); }
.leaflet-control { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.leaflet-bar a, .leaflet-bar a:hover { background: var(--surface); border-bottom: 1px solid var(--border); color: var(--text); }

.modal { position: fixed; inset: 0; display: grid; place-items: center; z-index: 1000; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.72); }
.modal-content {
  position: relative;
  width: min(560px, 92vw);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.qr-area { display: grid; place-items: center; padding: 12px; background: #1a1a1a; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

.info-box {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: min(440px, 92vw);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: none;
  z-index: 1200;
}
.info-box.is-visible { display: block; }
.info-box h3 { margin: 0 0 8px; font-size: 18px; color: var(--text-strong); }
.info-close { position: absolute; top: 10px; right: 10px; }
.info-list { margin: 10px 0 0 18px; }
.info-list li { margin-bottom: 10px; }

.inline-chip.pending {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 16px;
  background: rgba(77, 163, 255, 0.16);
  color: var(--text-strong);
  border: 1px solid rgba(77, 163, 255, 0.35);
}
.inline-chip-spacer { margin-left: 8px; }
.inline-error { margin-top: 8px; font-size: 16px; color: var(--danger); font-weight: 700; }
.inline-edit-button { margin-left: 8px; }
.manual-edit { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.manual-edit-input { flex: 1 1 260px; }
.manual-edit-hint { color: var(--text); font-weight: 700; }
.order-cell { font-weight: 800; color: var(--text-strong); white-space: nowrap; }
.start-row { background: rgba(34, 197, 94, 0.12); }
.start-icon { margin-right: 6px; }
.fallback-notice { left: 16px; right: auto; bottom: 16px; width: min(520px, 92vw); }
.qr-area img { max-width: 100%; height: auto; display: block; }

footer {
  margin-top: 18px;
  padding: 14px 0;
  text-align: center;
  color: var(--text);
}
footer a { color: var(--text-strong); }

@media (min-width: 768px) {
  .toolbar { grid-template-columns: 1fr auto; }
  .toolbar-actions { justify-content: flex-end; }
}

@media (min-width: 1024px) {
  .container { padding: 24px; }
  .app-main { grid-template-columns: 420px 1fr; align-items: start; }
  .upload-container { position: sticky; top: 16px; z-index: 10; }
  .results-container { position: relative; z-index: 1; }
}

@media (max-width: 600px) {
  .results-table-container { overflow: visible; max-height: none; }
  table { min-width: auto; }
  table thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody tr {
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
  }
  tbody td {
    border-bottom: 1px solid var(--border);
    padding: 12px 14px;
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 10px;
    align-items: start;
  }
  tbody td:last-child { border-bottom: none; }
  tbody td::before { content: attr(data-label); color: #ffffff; font-weight: 700; }
}

@media (max-width: 320px) {
  .container { padding: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
