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

:root {
  --bg-1: #03070f;
  --bg-2: #071426;
  --bg-3: #0b1f3a;
  --panel: rgba(10, 20, 38, 0.88);
  --panel-strong: rgba(14, 28, 52, 0.94);
  --text: #e9f3ff;
  --muted: #9fb7d6;
  --accent: #6cb7ff;
  --accent-2: #9cd4ff;
  --danger: #ff6f91;
  --border: rgba(108, 183, 255, 0.28);
  --shadow: 0 20px 36px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Rubik', sans-serif;
  color: var(--text);
  background: linear-gradient(120deg, var(--bg-1), var(--bg-2));
}

.page-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 10% 20%, rgba(108, 183, 255, 0.22) 0, transparent 38%),
    radial-gradient(circle at 90% 15%, rgba(68, 139, 255, 0.18) 0, transparent 30%),
    radial-gradient(circle at 75% 80%, rgba(44, 88, 170, 0.2) 0, transparent 40%);
  z-index: 0;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1380px, 96vw);
  margin: 18px auto 28px;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(1, 6, 16, 0.84);
}

.login-screen.active {
  display: flex;
}

.login-card {
  width: min(430px, 96vw);
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px;
  display: grid;
  gap: 10px;
}

.login-card h2 {
  margin: 0;
}

.login-card p {
  margin: 0;
  color: var(--muted);
}

.login-card input,
.login-card button {
  border-radius: 10px;
  border: 1px solid rgba(108, 183, 255, 0.34);
  padding: 10px;
  font: inherit;
  color: var(--text);
  background: rgba(5, 15, 29, 0.9);
}

.login-card button {
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(135deg, rgba(105, 172, 255, 0.7), rgba(40, 88, 162, 0.95));
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-logo {
  width: 138px;
  height: 138px;
  object-fit: contain;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--border);
  padding: 6px;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--accent-2);
  font-size: 0.78rem;
}

h1 {
  font-family: 'Space Grotesk', sans-serif;
  margin: 6px 0 10px;
  font-size: clamp(1.45rem, 3.5vw, 2.45rem);
}

.subtitle {
  margin: 0;
  color: var(--muted);
  max-width: 820px;
}

.header-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.session-info {
  min-width: 210px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(7, 21, 41, 0.86);
  color: #d4e8ff;
  text-align: center;
  font-size: 0.86rem;
}

#logoutBtn {
  display: none;
}

#profileBtn {
  display: none;
}

.file-loader,
.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 210px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  font-weight: 700;
  color: #dcedff;
  cursor: pointer;
  background: linear-gradient(140deg, rgba(38, 80, 145, 0.65), rgba(87, 163, 255, 0.24));
  font: inherit;
  text-decoration: none;
}

.secondary-btn:hover,
.file-loader:hover {
  filter: brightness(1.08);
}

.file-loader input {
  display: none;
}

.status-row {
  margin-top: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  color: #d4e7ff;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px 0;
}

.tab {
  border: 1px solid var(--border);
  background: rgba(9, 26, 48, 0.82);
  padding: 10px 14px;
  border-radius: 999px;
  cursor: pointer;
  color: #cde4ff;
  transition: all 180ms ease;
  font-weight: 600;
}

.tab.active,
.tab:hover {
  background: linear-gradient(135deg, rgba(107, 179, 255, 0.35), rgba(35, 72, 130, 0.82));
  color: #fff;
}

.admin-only {
  display: none;
}

.tab.admin-only.visible {
  display: inline-flex;
}

.view.admin-only.visible {
  display: block;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.kpi-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.kpi-card,
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.kpi-card h3 {
  margin: 0;
  font-size: 0.84rem;
  color: var(--muted);
  font-weight: 500;
}

.kpi-card p {
  margin: 8px 0 0;
  font-size: 1.38rem;
  font-weight: 800;
}

.panel {
  margin-bottom: 14px;
}

.mini-panel {
  padding: 12px 14px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 1.08rem;
}

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

.form-panel {
  padding-bottom: 8px;
}

#view-zones .form-panel .inline-form + .inline-form {
  margin-top: 8px;
}

#view-inventory .form-panel {
  position: relative;
  z-index: 9;
}

.inline-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
}

.inline-form.compact {
  grid-template-columns: minmax(180px, 280px) 180px;
}

.inline-form input,
.inline-form select,
.inline-form button,
.filters input:not([type="checkbox"]),
.filters select,
.panel-head select {
  border-radius: 10px;
  border: 1px solid rgba(108, 183, 255, 0.34);
  padding: 9px 10px;
  min-height: 40px;
  line-height: 1.25;
  font: inherit;
  color: var(--text);
  background: rgba(5, 15, 29, 0.9);
}

.inline-form input::placeholder,
.filters input:not([type="checkbox"])::placeholder {
  color: #88a8cd;
}

.inline-form button {
  cursor: pointer;
  font-weight: 700;
  background: linear-gradient(135deg, rgba(105, 172, 255, 0.7), rgba(40, 88, 162, 0.95));
}

.form-hint {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

.mini-note {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.chart {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 10px;
  align-items: end;
  min-height: 200px;
}

.bar-wrap {
  display: grid;
  gap: 6px;
}

.bar {
  width: 100%;
  border-radius: 10px 10px 4px 4px;
  background: linear-gradient(180deg, #9fd8ff, #4f95ff);
  min-height: 8px;
}

.bar-label,
.bar-value {
  text-align: center;
  font-size: 0.78rem;
}

.bar-label {
  color: var(--muted);
}

.bar-value {
  font-weight: 700;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.dashboard-filters .custom-month {
  display: none;
}

.dashboard-filters.custom .custom-month {
  display: inline-block;
}

.filters label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(7, 21, 41, 0.86);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}

.filters label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-height: 0;
  accent-color: var(--accent);
}

.sales-summary {
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 600;
}

.table-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel-strong);
}

#inventoryTable {
  max-height: none;
  overflow: visible;
  position: relative;
  overscroll-behavior: auto;
}

#inventoryTable table {
  border-collapse: separate;
  border-spacing: 0;
}

#inventoryTable th {
  position: -webkit-sticky;
  top: 0;
  z-index: 6;
  background: rgba(20, 40, 72, 0.98);
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table-wrap th,
.table-wrap td {
  border-bottom: 1px solid rgba(108, 183, 255, 0.16);
  padding: 8px 9px;
  text-align: left;
  vertical-align: top;
}

.table-wrap th {
  position: sticky;
  top: 0;
  background: rgba(20, 40, 72, 0.98);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #b8d8ff;
  z-index: 1;
}

.table-wrap tr:hover td {
  background: rgba(51, 112, 205, 0.18);
}

@media (min-width: 861px) {
  #clientsTable th:nth-child(1),
  #clientsTable td:nth-child(1) {
    min-width: 280px;
    width: 26%;
  }

  #clientsTable th:nth-child(4),
  #clientsTable td:nth-child(4) {
    min-width: 96px;
    width: 96px;
  }

  #clientsTable th:nth-child(5),
  #clientsTable td:nth-child(5) {
    min-width: 88px;
    width: 88px;
  }

  #clientsTable .cell-input[data-field="name"] {
    min-width: 240px;
  }

  #clientsTable .cell-select[data-field="payment_method"] {
    min-width: 84px;
  }

  #clientsTable .cell-input[data-field="systems_count"] {
    min-width: 72px;
  }

  #systemsTable th:nth-child(1),
  #systemsTable td:nth-child(1) {
    min-width: 250px;
    width: 24%;
  }

  #systemsTable th:nth-child(3),
  #systemsTable td:nth-child(3) {
    min-width: 110px;
    width: 110px;
  }

  #systemsTable .cell-input[data-field="client"] {
    min-width: 220px;
  }

  #systemsTable .cell-input[data-field="serial_number"] {
    min-width: 80px;
  }
}

.cell-subtext {
  margin-top: 4px;
  color: var(--accent-2);
  font-size: 0.78rem;
  line-height: 1.3;
}

.cell-input,
.cell-select {
  width: 100%;
  min-width: 110px;
  border-radius: 8px;
  border: 1px solid rgba(108, 183, 255, 0.32);
  padding: 6px 8px;
  font: inherit;
  color: var(--text);
  background: rgba(4, 14, 28, 0.96);
}

.cell-input[data-address-popup="1"],
input[data-address-popup="1"] {
  cursor: pointer;
}

.row-actions {
  display: inline-flex;
  gap: 6px;
}

.small-btn,
.danger-btn {
  border: 1px solid var(--border);
  background: rgba(67, 138, 234, 0.2);
  color: #d9ecff;
  font: inherit;
  border-radius: 8px;
  min-height: 34px;
  padding: 6px 9px;
  cursor: pointer;
}

.danger-btn {
  border-color: rgba(255, 111, 145, 0.45);
  background: rgba(255, 111, 145, 0.14);
  color: #ffc0cf;
}

.badge-low {
  color: #fff;
  background: #ff6f91;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.74rem;
  white-space: nowrap;
}

.empty {
  padding: 18px;
  color: var(--muted);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 8, 20, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 14px;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  width: min(760px, 96vw);
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.modal-card h3 {
  margin: 0 0 10px;
}

#addressModalTextarea {
  width: 100%;
  min-height: 230px;
  resize: vertical;
  border-radius: 10px;
  border: 1px solid rgba(108, 183, 255, 0.34);
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: rgba(5, 15, 29, 0.92);
}

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

.modal-actions button {
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 9px 12px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  background: linear-gradient(135deg, rgba(105, 172, 255, 0.7), rgba(40, 88, 162, 0.95));
}

.modal-actions .modal-cancel {
  min-width: 120px;
}

@media (max-width: 960px) {
  .app-shell {
    width: min(100%, 100vw - 18px);
    margin: 10px auto 20px;
  }

  .hero {
    flex-direction: column;
    padding: 14px;
  }

  .status-row {
    padding: 10px 12px;
  }

  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 4px;
    margin: 14px 0;
  }

  .tabs::-webkit-scrollbar {
    height: 6px;
  }

  .tab {
    flex: 0 0 auto;
    min-height: 42px;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
  }

  .header-actions {
    width: 100%;
  }

  .file-loader,
  .secondary-btn {
    width: 100%;
  }
}

@media (max-width: 860px) {
  .table-wrap:not(#inventoryTable) {
    border: none;
    background: transparent;
    overflow: visible;
  }

  .table-wrap:not(#inventoryTable) table,
  .table-wrap:not(#inventoryTable) thead,
  .table-wrap:not(#inventoryTable) tbody,
  .table-wrap:not(#inventoryTable) tr,
  .table-wrap:not(#inventoryTable) th,
  .table-wrap:not(#inventoryTable) td {
    display: block;
    width: 100%;
  }

  .table-wrap:not(#inventoryTable) thead {
    display: none;
  }

  .table-wrap:not(#inventoryTable) th {
    position: static;
  }

  .table-wrap:not(#inventoryTable) tbody {
    display: grid;
    gap: 10px;
  }

  .table-wrap:not(#inventoryTable) tr {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--panel-strong);
    padding: 8px;
  }

  .table-wrap:not(#inventoryTable) td {
    border-bottom: none;
    padding: 6px 8px;
    display: grid;
    grid-template-columns: minmax(112px, 40%) 1fr;
    gap: 8px;
    align-items: start;
  }

  .table-wrap:not(#inventoryTable) td::before {
    content: attr(data-label);
    color: var(--accent-2);
    font-size: 0.72rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-weight: 700;
  }

  .table-wrap:not(#inventoryTable) tr:hover td {
    background: transparent;
  }

  #inventoryTable {
    border: 1px solid var(--border);
    background: var(--panel-strong);
    overflow: visible;
    max-height: none;
  }

  #inventoryTable table {
    width: 100%;
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0;
  }

  #inventoryTable thead {
    display: table-header-group;
  }

  #inventoryTable tbody {
    display: table-row-group;
  }

  #inventoryTable tr {
    display: table-row;
    border: none;
    border-radius: 0;
    background: transparent;
    padding: 0;
  }

  #inventoryTable th,
  #inventoryTable td {
    display: table-cell;
    width: auto;
  }

  #inventoryTable td::before {
    content: none;
  }

  #inventoryTable th {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 4;
  }

  .cell-input,
  .cell-select {
    min-width: 0;
    min-height: 40px;
    padding: 8px 9px;
  }

  .row-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100%, 100vw - 12px);
    margin: 8px auto 16px;
  }

  .panel,
  .kpi-card {
    padding: 12px;
  }

  .brand-wrap {
    flex-direction: column;
    align-items: flex-start;
  }

  .brand-logo {
    width: 112px;
    height: 112px;
  }

  .kpi-grid,
  .kpi-grid.compact {
    grid-template-columns: 1fr;
  }

  .chart {
    min-height: 160px;
  }

  .filters {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .filters label {
    width: 100%;
    min-height: 42px;
  }

  .filters input:not([type="checkbox"]),
  .filters select,
  .panel-head select,
  .inline-form input,
  .inline-form select,
  .inline-form button,
  .file-loader,
  .secondary-btn,
  .modal-actions button,
  .small-btn,
  .danger-btn {
    min-height: 44px;
  }

  .filters input:not([type="checkbox"]),
  .filters select,
  .inline-form input,
  .inline-form select,
  .inline-form button {
    width: 100%;
    min-width: 0;
  }

  .inline-form,
  .inline-form.compact {
    grid-template-columns: 1fr;
  }

  .panel-head {
    flex-direction: column;
    align-items: stretch;
  }

  .modal-card {
    width: 100%;
    max-height: calc(100vh - 18px);
    overflow-y: auto;
  }

  #addressModalTextarea {
    min-height: 180px;
  }

  .modal-actions {
    flex-direction: column;
  }
}

@media (max-width: 420px) {
  .tab {
    padding: 10px 12px;
    font-size: 0.9rem;
  }

  .table-wrap td {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
