:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2487ea;
  --primary-dark: #1566b7;
  --success: #0f9d58;
  --danger: #dc2626;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top right, #dceeff 0%, var(--bg) 42%);
  color: var(--text);
  font-family: 'Manrope', sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  min-height: 100vh;
  display: flex;
}

.sidebar {
  width: 270px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 40;
}

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

.brand h1 {
  margin: 0;
  font-size: 20px;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--primary), #5fb4ff);
  color: #fff;
}

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

.menu-link {
  border-radius: 10px;
  padding: 10px;
  display: flex;
  gap: 10px;
  align-items: center;
  color: #334155;
  font-weight: 600;
  transition: 0.2s ease;
}

.menu-link:hover {
  background: #edf5ff;
  transform: translateX(2px);
}

.menu-link.active {
  background: #dfeeff;
  color: var(--primary-dark);
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.user-block {
  display: flex;
  gap: 10px;
  align-items: center;
}

.user-block p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #dbeafe;
}

.content-wrap {
  margin-left: 270px;
  width: calc(100% - 270px);
}

.topbar {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar h2 {
  margin: 0;
  font-size: 20px;
}

.topbar-actions,
.topbar-actions form {
  margin: 0;
  display: flex;
}

.page-container {
  padding: 20px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.04);
}

.panel h3 {
  margin: 0 0 14px;
}

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

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

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

.stats-grid.single-row {
  grid-template-columns: minmax(240px, 1fr);
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.stat-card p {
  margin: 0;
  color: var(--muted);
  font-weight: 600;
}

.stat-card h3 {
  margin: 10px 0 0;
  font-size: 26px;
}

.stat-card.danger h3 {
  color: var(--danger);
}

.chart-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 12px;
}

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

.analytics-grid .wide {
  grid-column: 1 / -1;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 11px 10px;
  border-bottom: 1px solid #f1f5f9;
}

.actions {
  white-space: nowrap;
}

.btn {
  border: 1px solid transparent;
  padding: 9px 14px;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  transition: 0.18s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

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

.btn-sm {
  padding: 7px 10px;
  font-size: 12px;
}

.btn-primary {
  background: linear-gradient(145deg, var(--primary), #4ca2f6);
  color: #fff;
}

.btn-primary:hover {
  background: linear-gradient(145deg, #1173d4, #3f9bf5);
}

.btn-light {
  border-color: var(--border);
  background: #fff;
}

.btn-danger {
  background: #fff1f2;
  color: var(--danger);
  border-color: #fecdd3;
}

.btn-add-product {
  margin-top: 12px;
  background: #ecfdf3;
  color: #15803d;
  border-color: #86efac;
}

.btn-add-product:hover {
  background: #dcfce7;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn.sm {
  width: 34px;
  height: 34px;
}

.icon-btn.danger {
  color: var(--danger);
  border-color: #fecdd3;
  background: #fff1f2;
}

#menuBtn {
  display: none;
}

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

.grid-form label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  font-family: inherit;
  font-size: 14px;
  background: #fbfdff;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid #9bccff;
  border-color: #9bccff;
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
  margin-top: 8px;
}

.text-danger {
  color: var(--danger);
}

.text-success {
  color: var(--success);
}

.balance-down {
  color: var(--danger);
}

.balance-up {
  color: var(--success);
}

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

.alert {
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-weight: 700;
  background: #e0f2fe;
  color: #0c4a6e;
}

.errorlist,
.error-list {
  color: var(--danger);
  margin: 8px 0;
  padding: 0;
  list-style: none;
}

.order-bottom {
  margin-top: 12px;
}

.wrap-head {
  flex-wrap: wrap;
}

.search-inline {
  display: flex;
  gap: 8px;
}

.search-inline input {
  min-width: 220px;
}

.order-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.badge {
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.badge-status-new {
  background: #dbeafe;
  color: #1d4ed8;
  border-radius: 999px;
  padding: 5px 10px;
}

.badge-status-done {
  background: #dcfce7;
  color: #15803d;
  border-radius: 999px;
  padding: 5px 10px;
}

.badge-status-closed {
  background: #fee2e2;
  color: #b91c1c;
  border-radius: 999px;
  padding: 5px 10px;
}

.badge-danger,
.badge.balance-down {
  background: #fee2e2;
  color: #b91c1c;
}

.badge-success,
.badge.balance-up {
  background: #dcfce7;
  color: #15803d;
}

.badge.balance-neutral {
  background: #f1f5f9;
}

.icon-action-group {
  display: flex;
  gap: 6px;
}

.pagination {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.custom-modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 90;
}

.custom-modal.show {
  display: block;
}

.custom-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
}

.custom-modal-dialog {
  position: relative;
  width: min(920px, calc(100vw - 24px));
  margin: 24px auto;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--border);
  overflow: hidden;
}

.custom-modal-header,
.custom-modal-footer {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.custom-modal-footer {
  border-bottom: 0;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  display: grid;
  gap: 6px;
}

.custom-modal-body {
  padding: 16px;
  max-height: 60vh;
  overflow-y: auto;
}

.summary-row {
  display: flex;
  justify-content: space-between;
}

.muted-note {
  color: var(--muted);
  font-size: 13px;
}

input[type='checkbox'][name$='-DELETE'] {
  display: none;
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(430px, 90vw);
  background: #fff;
  border-radius: 18px;
  border: 1px solid var(--border);
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.08);
  padding: 28px;
}

.auth-logo {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  margin-bottom: 14px;
  background: linear-gradient(145deg, var(--primary), #5fb4ff);
  color: #fff;
  display: grid;
  place-items: center;
}

.auth-card h1 {
  margin: 0;
}

.auth-card p {
  margin: 8px 0 18px;
  color: var(--muted);
}

.auth-form {
  display: grid;
  gap: 10px;
}

.w-full {
  width: 100%;
}

.overlay {
  display: none;
}

.phone-link {
  color: #0369a1;
  font-weight: 700;
}

.entity-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
}

.avatar-thumb {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 38px;
}

.placeholder-avatar {
  background: #e0f2fe;
  color: #0369a1;
}

.image-thumb {
  width: 100%;
  max-width: 220px;
  border-radius: 12px;
  cursor: zoom-in;
  object-fit: cover;
}

.image-viewer-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(2, 6, 23, 0.85);
  z-index: 120;
  padding: 24px;
}

.image-viewer-modal.show {
  display: flex;
}

.image-viewer-modal img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
}

.image-viewer-close {
  position: absolute;
  top: 16px;
  right: 16px;
}

.map-picker-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: #f8fbff;
}

.map-picker {
  height: 320px;
  border-radius: 12px;
  overflow: hidden;
  margin-top: 10px;
}

.order-line-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

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

.compact-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 10px;
  border-radius: 999px;
  background: #eef6ff;
  color: #155e9d;
  font-weight: 700;
  font-size: 12px;
}

.bottom-sheet {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 110;
}

.bottom-sheet.show {
  display: block;
}

.bottom-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.38);
}

.bottom-sheet-card {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  border-radius: 18px 18px 0 0;
  padding: 18px;
  border-top: 1px solid var(--border);
  box-shadow: 0 -12px 30px rgba(15, 23, 42, 0.12);
}

.sheet-actions {
  display: grid;
  gap: 10px;
}

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

.map-mode-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-weight: 700;
  cursor: pointer;
  background: #fff;
}

.map-mode-card input {
  width: auto;
  margin-right: 6px;
}

.map-mode-card.active {
  border-color: #7fb8f8;
  background: #eff6ff;
}

.map-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.map-panel.hidden {
  display: none;
}

.map-shell.fullscreen {
  position: fixed;
  inset: 10px;
  z-index: 100;
  background: #fff;
  border-radius: 10px;
  padding: 10px;
}

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

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

  .chart-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .sidebar {
    transform: translateX(-100%);
    transition: 0.22s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .overlay.show {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.45);
    z-index: 30;
  }

  #menuBtn {
    display: grid;
  }

  .content-wrap {
    margin-left: 0;
    width: 100%;
  }
}

@media (max-width: 700px) {
  .stats-grid,
  .grid-form {
    grid-template-columns: 1fr;
  }

  .stats-grid.stats-grid-six {
    grid-template-columns: 1fr;
  }

  .page-container {
    padding: 14px;
  }

  .panel,
  .stat-card {
    padding: 14px;
  }

  .search-inline,
  .order-actions {
    width: 100%;
  }

  .search-inline input {
    min-width: auto;
  }

  .custom-modal-dialog {
    margin: 10px auto;
  }

  .map-mode-grid {
    grid-template-columns: 1fr;
  }

  #itemTable thead {
    display: none;
  }

  #itemTable tbody,
  #itemTable tr,
  #itemTable td {
    display: block;
    width: 100%;
  }

  #itemTable tr.item-row {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px;
    background: #fff;
    margin-bottom: 10px;
  }

  #itemTable tr.item-row td {
    padding: 0;
    border-bottom: 0;
    margin-bottom: 10px;
  }

  .mobile-inline-label {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }
}
