@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&display=swap");

* {
  box-sizing: border-box;
}

:root {
  --brand-primary: #ffc700;
  --brand-on-primary: #111827;
  --brand-secondary: #0b1220;
  --brand-accent: #2f80ff;

  --surface-bg: #f7f8fa;
  --surface-card: #ffffff;
  --surface-sheet: #ffffff;

  --text-primary: #0b1220;
  --text-secondary: #4b5563;
  --text-tertiary: #9ca3af;

  --line-default: #e5e7eb;
  --danger: #ef4444;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "SF Pro Text", "Segoe UI", sans-serif;
  background: radial-gradient(
      1200px circle at 15% -10%,
      rgba(255, 199, 0, 0.12),
      rgba(247, 248, 250, 0.95) 45%,
      var(--surface-bg) 100%
    );
  color: var(--text-primary);
  overflow-y: scroll;
}

.offline {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--surface-card);
  border: 1px solid var(--line-default);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
  font-size: 14px;
}

.offline button {
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 12px;
  background: var(--brand-primary);
  color: var(--brand-on-primary);
}

/* Пока идет проверка токена — скрываем интерфейсы, чтобы избежать мерцаний. */
body.auth-pending #login,
body.auth-pending #layout {
  display: none !important;
}

#app {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  width: 100%;
}

body.modal-open {
  overflow: hidden;
}

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

.modal-overlay.doc-viewer-fullscreen {
  padding: 0;
}

.modal {
  width: min(520px, 92vw);
  max-height: 90vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-header h3 {
  margin: 0;
  font-size: 20px;
}

.modal-desc {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-helper {
  font-size: 12px;
  color: var(--text-secondary);
}

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

.doc-viewer {
  width: min(860px, 96vw);
}

.modal-overlay.doc-viewer-fullscreen .doc-viewer {
  width: 100%;
  height: 100%;
  max-height: none;
  border-radius: 0;
}

.doc-viewer-body {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f172a;
  border-radius: 16px;
  padding: 12px;
  min-height: 320px;
  position: relative;
  overflow: hidden;
}

.modal-overlay.doc-viewer-fullscreen .doc-viewer-body {
  flex: 1;
  border-radius: 0;
  padding: 16px;
}

.doc-viewer-body img {
  width: 100%;
  height: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 16px 32px rgba(15, 23, 42, 0.4);
}

.modal-overlay.doc-viewer-fullscreen .doc-viewer-body img {
  max-height: 100%;
  border-radius: 0;
  box-shadow: none;
}

.doc-viewer-fallback {
  color: #e2e8f0;
  text-align: center;
  font-size: 14px;
}

.doc-viewer-fallback a {
  color: var(--brand-primary);
  font-weight: 600;
}

/* Скрываем элементы поверх их собственных display-настроек. */
.hidden {
  display: none !important;
}

.card {
  background: var(--surface-card);
  border-radius: 16px;
  padding: 24px;
  border: 1px solid var(--line-default);
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.08);
}

#login {
  width: min(380px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#login h1 {
  margin: 0;
  font-size: 24px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.login-brand p {
  margin: 4px 0 0;
  color: var(--text-secondary);
}

.login-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--brand-primary);
  color: var(--brand-on-primary);
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 700;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}

input {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line-default);
  font-size: 14px;
  background: var(--surface-card);
}

select,
textarea {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line-default);
  font-size: 14px;
  background: var(--surface-card);
  font-family: inherit;
}

textarea {
  min-height: 110px;
  resize: vertical;
}

button {
  padding: 12px 14px;
  border: none;
  border-radius: 12px;
  background: var(--brand-primary);
  color: var(--brand-on-primary);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}

button:hover {
  background: #eab308;
}

.button-secondary {
  background: transparent;
  border: 1px solid var(--line-default);
  color: var(--text-primary);
}

.button-secondary:hover {
  background: #f1f5f9;
}

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

.button-danger:hover {
  background: #dc2626;
}

.action {
  background: #f1f5f9;
  color: #0f172a;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  margin-right: 4px;
  border: 1px solid var(--line-default);
}

.action:hover {
  background: #cbd5f5;
}

.actions {
  white-space: nowrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(148, 163, 184, 0.2);
  color: var(--text-secondary);
}

.chip--success {
  background: rgba(34, 197, 94, 0.18);
  color: #16a34a;
}

.chip--warning {
  background: rgba(245, 158, 11, 0.18);
  color: #d97706;
}

.chip--danger {
  background: rgba(239, 68, 68, 0.18);
  color: #dc2626;
}

.chip--info {
  background: rgba(47, 128, 255, 0.18);
  color: #2563eb;
}

.map-container {
  width: 100%;
  height: 520px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line-default);
}

.map-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.map-toolbar input {
  flex: 1;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.doc-groups {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.doc-group {
  padding: 16px;
}

.doc-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.doc-group-title {
  font-size: 16px;
  font-weight: 700;
}

.doc-group-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
}

.doc-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line-default);
  background: var(--surface-card);
}

.doc-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.doc-title {
  font-weight: 600;
}

.doc-meta-text {
  font-size: 12px;
  color: var(--text-secondary);
}

.doc-reason {
  font-size: 12px;
  color: var(--danger);
}

.doc-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-card);
  border: 1px solid var(--line-default);
  color: var(--text-secondary);
}

.legend-item::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--text-secondary);
}

.legend-driver::before {
  background: #22c55e;
}

.legend-order::before {
  background: var(--brand-accent);
}

.legend-sos::before {
  background: var(--danger);
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.report-card {
  background: var(--surface-card);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

.report-row {
  margin-bottom: 6px;
  font-size: 14px;
}

.bar {
  background: #e2e8f0;
  border-radius: 8px;
  margin-bottom: 8px;
  overflow: hidden;
}

.bar span {
  display: block;
  background: var(--brand-accent);
  color: #fff;
  padding: 4px 8px;
  font-size: 12px;
  white-space: nowrap;
}

.bar-success span {
  background: #16a34a;
}

.bar-danger span {
  background: #dc2626;
}

.toast {
  background: #ecfeff;
  border: 1px solid #99f6e4;
  color: #0f172a;
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.loading {
  color: var(--text-secondary);
  font-size: 14px;
}

.error {
  color: var(--danger);
  font-size: 13px;
}

#layout {
  display: flex;
  width: 100%;
  min-height: calc(100vh - 48px);
  align-items: stretch;
}

.sidebar {
  width: 260px;
  flex: 0 0 260px;
  background: var(--brand-secondary);
  color: #fff;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-radius: 18px;
}

.sidebar .brand {
  font-weight: 700;
  font-size: 18px;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar nav button {
  background: #111827;
  border-radius: 10px;
  text-align: left;
  color: #e2e8f0;
  font-weight: 600;
  padding: 10px 12px;
}

.sidebar nav button:hover {
  background: #1f2937;
}

.sidebar nav button.active {
  background: var(--brand-primary);
  color: var(--brand-on-primary);
}

.sidebar .logout {
  margin-top: auto;
  background: var(--danger);
}

.content {
  flex: 1;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  min-width: 0;
  max-width: 1440px;
  margin: 0 auto;
}

.table-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.table-toolbar input {
  flex: 1;
  min-width: 220px;
}

.table-count {
  font-size: 12px;
  color: var(--text-secondary);
}

.table-wrapper {
  border: 1px solid var(--line-default);
  border-radius: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--surface-card);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 0 16px;
  background: var(--surface-card);
  border: 1px solid var(--line-default);
  border-radius: 14px;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06);
}

#viewContent.card {
  min-height: 70vh;
}

table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: var(--surface-card);
  border-radius: 12px;
  overflow: hidden;
}

th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-default);
  text-align: left;
  white-space: nowrap;
}

th {
  background: #f1f5f9;
  color: var(--text-secondary);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}

@media (max-width: 900px) {
  .sidebar {
    width: 200px;
  }
}
