@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');

:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel2: #f8fafc;
  --border: #e5e7eb;
  --text: #0f172a;
  --muted: #94a3b8;
  --accent: #2563eb;
  --btn-bg: #e2e8f0;
}

body.theme-dark {
  color-scheme: dark;
  --bg: #050505;
  --panel: #0f1115;
  --panel2: #0b0d12;
  --border: #2a2d35;
  --text: #f5f7fb;
  --muted: #9ca3af;
  --accent: #06b6d4;
  --btn-bg: #111827;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

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

.brand-logo {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.brand-title {
  font-weight: 800;
  font-size: 15px;
  line-height: 1.1;
}

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

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 480px 1fr;
  gap: 16px;
  padding: 16px;
}

.left {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

.right {
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  position: relative;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

.map {
  width: 100%;
  height: calc(100vh - 16px - 16px - 58px); /* account for padding + topbar */
  min-height: 520px;
}

.map-overlay {
  position: absolute;
  left: 14px;
  bottom: 14px;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 12px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

.map-overlay-title {
  font-weight: 800;
  margin-bottom: 6px;
}

.map-overlay-text {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.login-title {
  margin: 6px 0 6px;
  font-size: 24px;
}

.subtitle {
  margin: 0 0 16px;
  color: var(--muted);
}

.status {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--muted);
  min-height: 1.2em;
}

.status[data-kind='error'] {
  color: #fb7185;
}

.status[data-kind='ok'] {
  color: #34d399;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-weight: 700;
}

input,
select {
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 15px;
}

input:focus,
select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 4px;
}

.btn {
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 800;
  cursor: pointer;
  min-width: 140px;
  text-align: center;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
}

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

.dash-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dash-row h2 {
  margin: 0;
  font-size: 18px;
}

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

.filters {
  display: flex;
  gap: 10px;
  align-items: end;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 1000;
}

.modal {
  width: min(1280px, 98vw);
  /* Try to avoid scrolling in the modal for typical desktop sizes */
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.18);
}

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

.modal-title {
  font-weight: 900;
  font-size: 16px;
}

.modal-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.modal-body {
  padding: 14px;
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 14px;
}

/* In the edit modal, allow the points table to expand (avoid internal scrolling) */
.modal .table-wrap {
  max-height: none;
}

.modal-actions {
  display: flex;
  justify-content: flex-start;
}

.modal-points-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.modal-points-title {
  font-weight: 900;
}

.modal-points-hint {
  color: var(--muted);
  font-size: 12px;
}

.btn.small {
  min-width: 0;
  padding: 8px 10px;
  font-size: 12px;
  border-radius: 9px;
}

@media (max-width: 980px) {
  .modal-body {
    grid-template-columns: 1fr;
  }
}

.project-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 260px;
  overflow: auto;
  padding-right: 4px;
}

.project-item {
  text-align: left;
  padding: 12px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel2);
  cursor: pointer;
}

.project-item:hover {
  border-color: var(--accent);
}

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

.project-name {
  font-weight: 900;
}

.project-edit {
  display: none;
  min-width: 0;
  padding: 8px 10px;
  font-size: 12px;
  border-radius: 9px;
}

.project-item.selected {
  border-color: var(--accent);
  background: var(--panel);
}

.project-item.selected .project-edit {
  display: inline-flex;
}

.project-address {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.3;
}

.table-wrap {
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

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

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

.data-table th {
  position: sticky;
  top: 0;
  background: var(--panel2);
  z-index: 1;
}

@media (max-width: 1050px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .map {
    height: 420px;
    min-height: 420px;
  }
}
