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

:root {
  --bg: #e8edf5;
  --panel: #ffffff;
  --ink: #0f172a;
  --ink-muted: #475569;
  --line: #d4deea;
  --primary: #1363df;
  --primary-dark: #0a4cb0;
  --danger: #b42318;
  --success: #13795b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'IBM Plex Sans', sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top left, #d8ebff 0%, #f2f6fb 45%, #e8edf5 100%);
}

h1,
h2,
h3 {
  margin: 0;
  font-family: 'Space Grotesk', sans-serif;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-shell {
  width: min(92vw, 480px);
}

.login-card {
  background: linear-gradient(160deg, #ffffff 0%, #f6faff 100%);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 2rem;
  box-shadow: 0 22px 60px rgba(15, 23, 42, 0.14);
}

.brand-logo {
  display: block;
  width: 100%;
  height: auto;
}

.login-logo {
  max-width: 300px;
  margin: 0 auto 1rem;
}

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

.form-stack {
  display: grid;
  gap: 0.85rem;
}

.form-stack.compact {
  gap: 0.6rem;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  padding: 0.6rem 0.7rem;
}

.btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.8rem;
  background: #fff;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.78;
}

.btn.is-loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

.btn.is-loading::before {
  content: '';
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(15, 23, 42, 0.2);
  border-top-color: rgba(15, 23, 42, 0.85);
  animation: spin 0.8s linear infinite;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 16px rgba(15, 23, 42, 0.12);
}

.btn.primary {
  color: #fff;
  background: linear-gradient(160deg, var(--primary), var(--primary-dark));
  border-color: transparent;
}

.btn.danger {
  color: #fff;
  background: linear-gradient(160deg, #dc2626, var(--danger));
  border-color: transparent;
}

.btn.success {
  color: #fff;
  background: linear-gradient(160deg, #16a34a, #15803d);
  border-color: transparent;
}

.btn.ghost {
  background: #f1f5f9;
}

.error-text {
  min-height: 1em;
  color: #dc2626;
  font-size: 0.9rem;
}

.app-page {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(7px);
}

.top-bar p {
  margin: 0.2rem 0 0;
  color: var(--ink-muted);
  font-size: 0.85rem;
}

.top-brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
}

.top-logo {
  width: 220px;
  max-width: 36vw;
}

.top-brand-text {
  display: grid;
  gap: 0.1rem;
}

.top-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  width: min(55vw, 560px);
}

.top-actions input {
  min-width: 200px;
}

.app-layout {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: 380px 1fr;
}

.sidebar {
  overflow: auto;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  padding: 0.8rem;
  display: grid;
  align-content: start;
  gap: 0.7rem;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  padding: 0.7rem;
}

.panel h2 {
  font-size: 1rem;
  margin-bottom: 0.55rem;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.button-row .btn:nth-child(2):last-child {
  grid-column: span 2;
}

.status-text {
  margin: 0.5rem 0 0;
  min-height: 1rem;
  font-size: 0.82rem;
  color: var(--ink-muted);
  opacity: 1;
  transition: opacity 0.45s ease;
}

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

.status-text.error {
  color: #dc2626;
}

.status-text.fade-out {
  opacity: 0;
}

.status-toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  min-height: 0;
  min-width: 260px;
  max-width: min(72vw, 760px);
  padding: 0.5rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.16);
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 9;
  pointer-events: none;
}

.status-toast:empty {
  display: none;
}

.status-toast.success {
  border-color: #86efac;
  background: rgba(240, 253, 244, 0.96);
}

.status-toast.error {
  border-color: #fca5a5;
  background: rgba(254, 242, 242, 0.97);
}

.territory-list,
.version-list {
  max-height: 210px;
  overflow: auto;
  display: grid;
  gap: 0.4rem;
}

.folder-group {
  display: grid;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.folder-heading {
  font-size: 0.85rem;
  color: #334155;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.territory-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.5rem;
  cursor: pointer;
  background: #f8fbff;
}

.territory-item.active {
  border-color: var(--primary);
  background: #e5efff;
}

.territory-item h3 {
  font-size: 0.92rem;
}

.territory-item p {
  margin: 0.2rem 0 0;
  color: var(--ink-muted);
  font-size: 0.78rem;
}

.version-item.expanded {
  border-color: var(--primary);
  background: #eef4ff;
}

.version-zip-details {
  margin-top: 0.45rem;
  padding-top: 0.45rem;
  border-top: 1px dashed var(--line);
}

.version-zip-title {
  margin: 0 0 0.35rem;
  color: #334155;
  font-size: 0.76rem;
  font-weight: 700;
}

.version-zip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
  max-height: 130px;
  overflow: auto;
}

.version-zip-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid #c7d2fe;
  background: #e0e7ff;
  color: #1e293b;
  font-size: 0.7rem;
  padding: 0.15rem 0.42rem;
}

.muted {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.82rem;
}

.stats-panel {
  max-height: 420px;
  overflow: auto;
}

.stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.stats-header h2 {
  margin: 0;
}

.stats-total {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.simple-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.simple-table th,
.simple-table td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 0.35rem;
}

.zip-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.4rem;
  margin-top: 0.4rem;
  background: #f9fbff;
}

.map-stage {
  position: relative;
  min-height: 0;
  height: 100%;
}

.map-canvas {
  width: 100%;
  height: 100%;
}

.map-hint {
  position: absolute;
  left: 16px;
  bottom: 14px;
  max-width: 420px;
  background: rgba(3, 7, 18, 0.85);
  color: white;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  font-size: 0.82rem;
  z-index: 6;
}

.floating-stats {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 15vw;
  min-width: 260px;
  max-width: 360px;
  max-height: calc(100% - 28px);
  overflow: auto;
  z-index: 7;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(6px);
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.18);
}

.import-pane {
  position: absolute;
  top: 14px;
  left: 14px;
  width: min(420px, 90vw);
  z-index: 8;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(6px);
  box-shadow: 0 18px 34px rgba(15, 23, 42, 0.2);
}

.import-pane[hidden] {
  display: none;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1024px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 45vh 55vh;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .map-canvas {
    height: 100%;
    min-height: 40vh;
  }

  .floating-stats {
    position: absolute;
    width: min(92vw, 360px);
    min-width: 0;
  }

  .top-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .top-brand {
    width: 100%;
    flex-wrap: wrap;
  }

  .top-logo {
    width: min(260px, 70vw);
    max-width: none;
  }

  .top-actions {
    width: 100%;
  }
}
