/* ---------- кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--r-control);
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--ink);
  font-weight: 500;
  font-size: 14px;
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.1s;
}

.btn:hover {
  background: var(--panel-2);
}

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

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--ink-inverse);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

[data-theme="dark"] .btn-primary,
.btn-primary {
  color: #fff;
}

.btn-signal {
  background: var(--signal);
  border-color: var(--signal);
  color: var(--signal-ink);
}

.btn-signal:hover {
  filter: brightness(0.96);
  background: var(--signal);
}

.btn-danger {
  color: var(--st-bad);
  border-color: color-mix(in srgb, var(--st-bad) 40%, var(--line));
}

.btn-danger:hover {
  background: var(--st-bad-soft);
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
}

.btn-ghost:hover {
  background: var(--panel-2);
}

.btn-sm {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 13px;
}

.btn-lg {
  min-height: 52px;
  padding: 12px 20px;
  font-size: 16px;
  border-radius: 12px;
}

.btn-icon {
  width: 40px;
  padding: 0;
}

.btn-block {
  width: 100%;
}

.btn .kbd {
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.18);
}

/* ---------- поля ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field > span,
.field-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
}

.field .hint {
  font-size: 12px;
  color: var(--ink-3);
}

.field .error {
  font-size: 12px;
  color: var(--st-bad);
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: var(--r-control);
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--ink);
  font-size: 15px;
}

.input:disabled,
.select:disabled {
  background: var(--panel-2);
  color: var(--ink-3);
  cursor: not-allowed;
}

.input[aria-invalid="true"] {
  border-color: var(--st-bad);
}

.textarea {
  min-height: 72px;
  resize: vertical;
}

.select {
  appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%236b7d8d' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-group svg {
  position: absolute;
  left: 12px;
  color: var(--ink-3);
  pointer-events: none;
}

.input-group .input {
  padding-left: 38px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s3);
}

.form-grid .span-2 {
  grid-column: span 2;
}

@media (max-width: 560px) {
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .form-grid .span-2 {
    grid-column: auto;
  }
}

/* переключатель */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  min-height: 32px;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch .track {
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--line-strong);
  position: relative;
  transition: background 0.15s;
  flex-shrink: 0;
}

.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.18s var(--ease);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.switch input:checked + .track {
  background: var(--primary);
}

.switch input:checked + .track::after {
  transform: translateX(16px);
}

.switch input:focus-visible + .track {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.switch input:disabled + .track {
  opacity: 0.5;
}

/* сегментированный контрол */
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: 11px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.segmented button {
  min-height: 32px;
  padding: 4px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--ink-2);
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
}

.segmented button[aria-pressed="true"] {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(16, 36, 52, 0.12);
}

/* ---------- чипы, бейджи, статусы ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-chip);
  background: var(--st-bad);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
}

.badge-signal {
  background: var(--signal);
  color: var(--signal-ink);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 2px 10px;
  border-radius: var(--r-chip);
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
  white-space: nowrap;
}

.chip-plus {
  background: var(--st-ready-soft);
  border-color: transparent;
  color: var(--st-ready);
}

.chip-minus {
  background: var(--st-bad-soft);
  border-color: transparent;
  color: var(--st-bad);
}

.chip-signal {
  background: var(--signal-soft);
  border-color: transparent;
  color: var(--ink);
}

button.chip {
  cursor: pointer;
}

button.chip[aria-pressed="true"] {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px 2px 8px;
  border-radius: var(--r-chip);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--tone-soft);
  color: var(--tone);
}

.status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.tone-booked { --tone: var(--st-booked); --tone-soft: var(--st-booked-soft); }
.tone-arrived { --tone: var(--st-arrived); --tone-soft: var(--st-arrived-soft); }
.tone-work { --tone: var(--st-work); --tone-soft: var(--st-work-soft); }
.tone-ready { --tone: var(--st-ready); --tone-soft: var(--st-ready-soft); }
.tone-hold { --tone: var(--st-hold); --tone-soft: var(--st-hold-soft); }
.tone-done { --tone: var(--st-done); --tone-soft: var(--st-done-soft); }
.tone-bad { --tone: var(--st-bad); --tone-soft: var(--st-bad-soft); }
.tone-muted { --tone: var(--ink-3); --tone-soft: var(--panel-2); }

/* казахстанский госномер */
.plate {
  display: inline-flex;
  align-items: stretch;
  height: 24px;
  border: 1.5px solid #1c2530;
  border-radius: 4px;
  background: #fff;
  color: #111a22;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.04em;
  line-height: 1;
  overflow: hidden;
  white-space: nowrap;
  font-feature-settings: "tnum" 1;
}

.plate .flag {
  display: grid;
  place-items: center;
  padding: 0 3px;
  background: #00a8c6;
  color: #ffd200;
  font-size: 7px;
  letter-spacing: 0;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.plate .code {
  display: flex;
  align-items: center;
  padding: 0 6px;
}

.plate .region {
  display: flex;
  align-items: center;
  padding: 0 4px;
  border-left: 1.5px solid #1c2530;
  font-size: 11px;
}

.plate-lg {
  height: 34px;
  font-size: 18px;
}

.plate-lg .region {
  font-size: 15px;
}

/* ---------- панели ---------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s4) var(--s4) 0;
  flex-wrap: wrap;
}

.panel-head h2 {
  margin-right: auto;
}

.panel-body {
  padding: var(--s4);
}

.panel-flush {
  padding: var(--s3) 0 0;
}

.grid {
  display: grid;
  gap: var(--s4);
}

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

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

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

@media (max-width: 1200px) {
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .grid-2,
  .grid-3 {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 480px) {
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--s2);
  }
}

.row {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
}

.row-between {
  justify-content: space-between;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}

.stack-sm {
  gap: var(--s2);
}

.divider {
  height: 1px;
  background: var(--line);
  border: 0;
  margin: 0;
}

/* показатели */
.kpi {
  padding: var(--s4);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-label {
  font-size: 13px;
  color: var(--ink-3);
  font-weight: 500;
}

.kpi-value {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 26px;
  letter-spacing: -0.02em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.kpi-foot {
  font-size: 12px;
  color: var(--ink-3);
}

.delta-up {
  color: var(--st-ready);
  font-weight: 600;
}

.delta-down {
  color: var(--st-bad);
  font-weight: 600;
}

@media (max-width: 480px) {
  .kpi {
    padding: var(--s3);
  }
  .kpi-value {
    font-size: 20px;
  }
}

.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
}

.progress > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

/* ---------- таблицы ---------- */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

.table th {
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  color: var(--ink-3);
  padding: 10px var(--s4);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  background: var(--panel);
}

.table td {
  padding: 10px var(--s4);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

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

.table tr.clickable {
  cursor: pointer;
}

.table tr.clickable:hover td {
  background: var(--panel-2);
}

.table .right {
  text-align: right;
}

.table .input {
  min-height: 34px;
  padding: 4px 8px;
  font-size: 14px;
  max-width: 120px;
}

.cell-main {
  font-weight: 500;
}

.cell-sub {
  font-size: 12px;
  color: var(--ink-3);
}

/* список-строки для мобильных */
.list {
  display: flex;
  flex-direction: column;
}

.list-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-top: 1px solid var(--line);
  min-height: 56px;
  text-align: left;
  background: none;
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
  width: 100%;
}

.list-item:first-child {
  border-top: 0;
}

button.list-item:hover {
  background: var(--panel-2);
}

.list-item .grow {
  flex: 1;
  min-width: 0;
}

.time-cell {
  font-weight: 600;
  min-width: 48px;
  font-variant-numeric: tabular-nums;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}

/* ---------- пустые состояния ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  padding: var(--s6) var(--s4);
  text-align: center;
  color: var(--ink-3);
}

.empty strong {
  color: var(--ink);
}

/* ---------- ящик (drawer) и модалка ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(10, 22, 32, 0.42);
  animation: fade-in 0.18s var(--ease);
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 51;
  width: min(520px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  box-shadow: var(--shadow-float);
  animation: slide-in 0.24s var(--ease);
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  padding: var(--s4) var(--s4) var(--s3);
  border-bottom: 1px solid var(--line);
}

.drawer-head .titles {
  flex: 1;
  min-width: 0;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--s4);
  display: flex;
  flex-direction: column;
  gap: var(--s4);
}

.drawer-foot {
  display: flex;
  gap: var(--s2);
  flex-wrap: wrap;
  padding: var(--s3) var(--s4) calc(var(--s3) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.modal {
  position: fixed;
  z-index: 51;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow-float);
  animation: pop-in 0.2s var(--ease);
}

.modal-sm {
  width: min(440px, calc(100vw - 32px));
}

@media (max-width: 760px) {
  .modal {
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    transform: none;
    width: 100%;
    max-height: 92dvh;
    border-radius: 18px 18px 0 0;
    animation: sheet-in 0.24s var(--ease);
  }
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-3);
  margin-bottom: 8px;
}

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  font-size: 14px;
}

.kv dt {
  color: var(--ink-3);
}

.kv dd {
  margin: 0;
  text-align: right;
  font-weight: 500;
}

.callout {
  display: flex;
  gap: 10px;
  padding: var(--s3);
  border-radius: 10px;
  background: var(--panel-2);
  font-size: 14px;
  color: var(--ink-2);
}

.callout-warn {
  background: var(--st-hold-soft);
  color: var(--ink);
}

.callout-bad {
  background: var(--st-bad-soft);
  color: var(--ink);
}

.callout-signal {
  background: var(--signal-soft);
  color: var(--ink);
}

.callout svg {
  margin-top: 2px;
}

/* ---------- тосты ---------- */

.toasts {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: min(440px, calc(100vw - 32px));
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  background: #16242f;
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow-float);
  animation: toast-in 0.22s var(--ease);
}

.toast .btn {
  margin-left: auto;
  color: var(--signal);
  background: none;
  border: 0;
  min-height: 28px;
  padding: 2px 6px;
}

.toast-bad svg {
  color: #ff8a80;
}

.toast-ok svg {
  color: #6ee7b0;
}

@media (max-width: 760px) {
  .toasts {
    bottom: calc(80px + env(safe-area-inset-bottom));
  }
}

/* всплывающая подсказка графиков */
.tip {
  position: fixed;
  z-index: 90;
  pointer-events: none;
  padding: 8px 10px;
  border-radius: 8px;
  background: #16242f;
  color: #fff;
  font-size: 12px;
  line-height: 1.4;
  box-shadow: var(--shadow-float);
  max-width: 240px;
}

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

/* меню */
.menu {
  position: absolute;
  z-index: 60;
  min-width: 220px;
  padding: 6px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-float);
}

.menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 38px;
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  text-align: left;
  font-size: 14px;
}

.menu button:hover {
  background: var(--panel-2);
}

@keyframes fade-in {
  from { opacity: 0; }
}

@keyframes slide-in {
  from { transform: translateX(40px); opacity: 0; }
}

@keyframes pop-in {
  from { transform: translate(-50%, -48%) scale(0.98); opacity: 0; }
}

@keyframes sheet-in {
  from { transform: translateY(40px); opacity: 0; }
}

@keyframes toast-in {
  from { transform: translateY(10px); opacity: 0; }
}
