:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-2: #eef1f3;
  --ink: #182025;
  --muted: #69747c;
  --line: #d9dee2;
  --accent: #147d64;
  --accent-2: #0f6fae;
  --danger: #bd2b2b;
  --warning: #b7791f;
  --critical: #8f1d45;
  --hot: #d85d17;
  --shadow: 0 16px 40px rgba(16, 24, 32, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

body.auth-locked .app-shell {
  display: none;
}

body:not(.auth-locked) .login-screen {
  display: none;
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #eef5f2, #f7f8f9 48%, #edf3f8);
}

.login-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 13px;
}

.login-card h1 {
  margin: 8px 0 0;
  font-size: 26px;
}

.login-card label {
  display: grid;
  gap: 6px;
  font-weight: 800;
  color: #3b464d;
}

.login-brand {
  color: var(--ink);
  border-bottom-color: var(--line);
}

.login-brand span {
  color: var(--muted);
}

.login-error {
  min-height: 20px;
  color: var(--danger);
  font-weight: 700;
}

.sidebar {
  background: #11191f;
  color: #f8fafb;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand strong {
  display: block;
  font-size: 18px;
}

.brand span {
  color: #aeb8bf;
  font-size: 13px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #fff;
  overflow: hidden;
  padding: 3px;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.field-label {
  color: #b8c1c7;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.control {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}

.control:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(15, 111, 174, 0.16);
}

.sidebar .control {
  background: #1b252c;
  border-color: #2d3b45;
  color: #f8fafb;
}

.account-box {
  display: grid;
  gap: 7px;
  padding: 12px;
  background: #1b252c;
  border: 1px solid #2d3b45;
  border-radius: 8px;
}

.account-box strong {
  overflow-wrap: anywhere;
}

.account-box span:last-of-type {
  color: #aeb8bf;
  font-size: 13px;
}

.full-button {
  width: 100%;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #ced6db;
  text-align: left;
  padding: 9px 10px;
  font-weight: 700;
  position: relative;
}

.nav-item:hover,
.nav-item.active {
  background: #26333b;
  color: #fff;
}

.nav-dot {
  display: none;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #e73333;
  box-shadow: 0 0 0 3px rgba(231, 51, 51, 0.18);
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
}

.nav-dot.visible {
  display: block;
}

.sidebar-status {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

.main {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar h1,
h2,
h3,
p {
  margin: 0;
}

.topbar h1 {
  font-size: 26px;
  line-height: 1.15;
}

.topbar p,
.muted {
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 20px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 190px 160px auto auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.search {
  min-width: 0;
}

.toggle {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
  white-space: nowrap;
}

.toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
  gap: 14px;
  align-items: start;
}

.panel,
.detail-panel,
.form-section,
.chat-shell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  min-width: 0;
}

.table-wrap {
  overflow: auto;
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
}

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

th {
  background: var(--surface-2);
  font-size: 12px;
  color: #4e5a62;
  text-transform: uppercase;
}

tbody tr {
  transition: background 0.12s ease;
}

tbody tr:hover,
tbody tr.selected {
  background: #eef7f3;
}

.route {
  color: #26333b;
  font-weight: 700;
}

.subline {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border-radius: 999px;
  background: #e5f4ee;
  color: #0d684f;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.muted-pill {
  background: #edf0f2;
  color: #59656d;
}

.status-pill {
  background: #e8f1fa;
  color: #175d91;
}

.priority-normal {
  background: #edf0f2;
  color: #59656d;
}

.priority-dolezita {
  background: #fff2d2;
  color: #815711;
}

.priority-hot {
  background: #ffe3d1;
  color: #a13e08;
}

.priority-kriticka {
  background: #fbe0ea;
  color: #8f1d45;
}

.detail-panel {
  min-height: 640px;
  padding: 16px;
  position: sticky;
  top: 22px;
}

.detail-empty {
  color: var(--muted);
  padding: 20px 0;
}

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.detail-head h2 {
  font-size: 20px;
  line-height: 1.2;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0;
}

.fact {
  background: #f7f8f9;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  min-height: 60px;
}

.fact span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}

.fact strong {
  overflow-wrap: anywhere;
}

.action-row,
.form-actions,
.flag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.action-row {
  margin: 12px 0;
}

.primary,
.secondary,
.danger {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 12px;
  font-weight: 800;
}

.primary {
  background: var(--accent);
  color: #fff;
}

.primary:hover {
  background: #106b55;
}

.secondary {
  background: #eef3f6;
  border-color: #d6dde2;
  color: #22303a;
}

.secondary:hover {
  background: #e1e9ee;
}

.danger {
  background: #fff0f0;
  border-color: #f1c9c9;
  color: var(--danger);
}

.price-box {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.price-box label,
.input-grid label,
.admin-form label {
  display: grid;
  gap: 5px;
  color: #3b464d;
  font-size: 13px;
  font-weight: 700;
}

.price-box label:last-of-type {
  grid-column: 1 / -1;
}

.comments {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.comments h3,
.dashboard-layout h3 {
  font-size: 15px;
  margin-bottom: 10px;
}

.comment-list {
  display: grid;
  gap: 8px;
  max-height: 210px;
  overflow: auto;
  padding-right: 3px;
}

.comment {
  background: #f7f8f9;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 9px;
}

.comment strong {
  display: block;
  font-size: 13px;
}

.comment p {
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.comment-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 10px;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
}

.form-section {
  padding: 16px;
}

.form-section.wide {
  min-width: 0;
}

.section-head,
.dashboard-head,
.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.compact {
  width: auto;
  min-width: 160px;
}

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

.flag-row {
  margin-top: 12px;
}

.form-actions {
  margin-top: 14px;
}

.email-box {
  min-height: 260px;
  resize: vertical;
  line-height: 1.45;
  margin-bottom: 10px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 12px;
  margin: 12px 0 16px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  font-size: 24px;
  margin-top: 6px;
}

.dashboard-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
  align-items: start;
}

.status-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 12px;
}

.status-column {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 160px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.status-column h4 {
  margin: 0 0 10px;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

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

.compact-stack {
  margin-bottom: 18px;
}

.shipment-card,
.mini-row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
}

.status-column .shipment-card {
  box-shadow: none;
  margin-bottom: 8px;
}

.shipment-card strong,
.mini-row strong {
  display: block;
  margin-bottom: 4px;
}

.shipment-card small,
.mini-row small {
  color: var(--muted);
}

.chat-shell {
  max-width: 900px;
  padding: 16px;
}

.direct-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 900px);
  gap: 14px;
  align-items: start;
}

.direct-users,
.order-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.direct-users h2,
.order-panel h2 {
  margin-bottom: 12px;
}

.direct-user {
  cursor: pointer;
}

.direct-user.active {
  border-color: var(--accent);
  background: #eef7f3;
}

.chat-messages {
  min-height: 420px;
  max-height: 58vh;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 12px;
  background: #f7f8f9;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.chat-message {
  max-width: 72%;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
}

.chat-message.own {
  justify-self: end;
  background: #e7f5ef;
  border-color: #c5e7d9;
}

.chat-message strong {
  display: block;
  font-size: 12px;
  color: #3e4a52;
  margin-bottom: 3px;
}

.chat-message p {
  overflow-wrap: anywhere;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 12px;
}

.admin-grid {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 14px;
}

.admin-grid .panel {
  padding: 16px;
}

.admin-panel-wide {
  grid-column: 1 / -1;
}

.settings-form {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
}

.settings-toggle {
  align-self: end;
}

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

.admin-form {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
  margin-bottom: 14px;
}

.permissions-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 14px;
  background: #f7f8f9;
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.permission-item {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  font-size: 13px;
  font-weight: 700;
}

.permission-item input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.orders-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: start;
}

.alert-form {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  align-items: end;
  margin-bottom: 14px;
}

.alert-form .secondary,
.alert-form .primary,
.admin-form .secondary,
.admin-form .danger {
  width: 100%;
  white-space: normal;
}

.admin-form {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.admin-form select[multiple] {
  min-height: 104px;
}

.offers {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.offer-row p {
  color: var(--muted);
  margin-top: 5px;
}

.kpi-toolbar {
  grid-template-columns: 160px 160px 160px auto auto;
}

.audit-list {
  max-height: 520px;
  overflow: auto;
}

.audit-row {
  display: grid;
  gap: 5px;
}

.audit-row code {
  white-space: pre-wrap;
  color: #4a5660;
  font-size: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  pointer-events: none;
  background: #11191f;
  color: #fff;
  border-radius: 8px;
  padding: 11px 14px;
  box-shadow: var(--shadow);
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 20;
  max-width: min(520px, calc(100vw - 30px));
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.deal-overlay {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(10, 14, 18, 0.86);
  z-index: 50;
  padding: 24px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(10, 14, 18, 0.58);
  z-index: 45;
  padding: 20px;
}

.modal-overlay.visible {
  display: grid;
}

.modal-card {
  width: min(760px, 100%);
  max-height: min(780px, calc(100vh - 40px));
  overflow: auto;
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.28);
}

.modal-body {
  display: grid;
  gap: 12px;
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

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

.timeline-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.timeline-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--accent);
  margin-top: 5px;
}

.timeline-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.timeline-card strong {
  display: block;
}

.bar-chart {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

#kpiStatusCounts {
  display: block;
}

.bar-row {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr) 36px;
  gap: 10px;
  align-items: center;
}

.bar-track {
  height: 18px;
  border-radius: 999px;
  background: #e7ecef;
  border: 1px solid #cfd8de;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  min-width: 6px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.deal-overlay.visible {
  display: grid;
}

.deal-content {
  width: min(680px, 100%);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: clamp(24px, 5vw, 46px);
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
}

.deal-content span {
  display: block;
  color: var(--hot);
  font-size: clamp(22px, 5vw, 42px);
  font-weight: 900;
  text-transform: uppercase;
}

.deal-content strong {
  display: block;
  font-size: clamp(46px, 12vw, 110px);
  line-height: 1;
  margin: 14px 0;
}

.deal-content p {
  font-size: clamp(16px, 3vw, 24px);
  margin-bottom: 8px;
}

@media (max-width: 1180px) {
  .split,
  .dashboard-layout,
  .form-grid,
  .admin-grid,
  .direct-shell,
  .orders-grid {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    position: static;
  }

  .metric-grid,
  .status-board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .settings-form,
  .alert-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 780px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

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

  .nav-item {
    text-align: center;
  }

  .main {
    padding: 14px;
  }

  .toolbar,
  .input-grid,
  .price-box,
  .facts,
  .metric-grid,
  .status-board,
  .admin-form {
    grid-template-columns: 1fr;
  }

  .settings-form,
  .alert-form,
  .permission-grid {
    grid-template-columns: 1fr;
  }

  .comment-form,
  .chat-form,
  .inline-form {
    grid-template-columns: 1fr;
    display: grid;
  }

  .chat-message {
    max-width: 100%;
  }

  .modal-grid,
  .bar-row {
    grid-template-columns: 1fr;
  }
}
