/* tire-plant-map — Light, minimal, English UI */

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: #1f2937;
  background: #fafafa;
}

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

/* ───────── Top bar ───────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: #ffffff;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}

header h1 {
  font-size: 16px;
  font-weight: 600;
  color: #111827;
  letter-spacing: -0.01em;
}

header h1 .accent {
  color: #2563eb;
}

.subtitle {
  font-size: 12px;
  color: #6b7280;
  margin-left: 12px;
}

.legend {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: #4b5563;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

/* ───────── Phase filter (legend clicks) ───────── */
.phase-filter {
  border: none;
  background: transparent;
  font: inherit;
  color: inherit;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  opacity: 0.45;
  transition: opacity 0.15s, background 0.15s;
}

.phase-filter:hover {
  opacity: 0.8;
  background: #f3f4f6;
}

.phase-filter.active {
  opacity: 1;
}

/* ───────── Map ───────── */
#map {
  flex: 1;
  background: #f3f4f6;
}

/* ───────── Sidebar ───────── */
aside {
  position: absolute;
  top: 60px;
  right: 12px;
  width: 320px;
  max-height: calc(100vh - 80px);
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  padding: 16px;
  overflow-y: auto;
  z-index: 10;
}

aside h2 {
  font-size: 13px;
  font-weight: 600;
  color: #111827;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

aside .close {
  float: right;
  cursor: pointer;
  color: #9ca3af;
  font-size: 18px;
  line-height: 1;
}

aside .close:hover { color: #1f2937; }

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid #f3f4f6;
  font-size: 13px;
}

.detail-row .label {
  color: #6b7280;
}

.detail-row .value {
  color: #111827;
  font-weight: 500;
  text-align: right;
}

.phase-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.phase-badge.operating { background: #dcfce7; color: #166534; }
.phase-badge.building  { background: #fef3c7; color: #92400e; }
.phase-badge.planned   { background: #dbeafe; color: #1e40af; }

/* ───────── MapLibre popup overrides ───────── */
.maplibregl-popup-content {
  padding: 12px 14px;
  border-radius: 6px;
  font-size: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  min-width: 180px;
}

.maplibregl-popup-content strong {
  font-size: 13px;
  color: #111827;
}

.maplibregl-popup-content .meta {
  color: #6b7280;
  font-size: 11px;
  margin-top: 2px;
}

.maplibregl-popup-content .cap {
  color: #2563eb;
  font-weight: 600;
  margin-top: 6px;
}

.maplibregl-popup-content .cap-row {
  display: flex;
  justify-content: space-between;
  margin-top: 3px;
  font-size: 11px;
  gap: 12px;
}

.maplibregl-popup-content .cap-row .cap-label {
  color: #6b7280;
}

.maplibregl-popup-content .cap-row .cap-val {
  color: #111827;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  min-width: 70px;
}

/* ───────── View-mode toggle (PCR/TBR/OTR) ───────── */
.view-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 16px;
  padding: 3px;
  background: #f3f4f6;
  border-radius: 6px;
  font-size: 12px;
}

.view-toggle-label {
  color: #6b7280;
  font-size: 11px;
  margin-right: 4px;
  margin-left: 4px;
}

.view-toggle button {
  border: none;
  background: transparent;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  color: #4b5563;
  font-size: 12px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.view-toggle button:hover {
  color: #111827;
}

.view-toggle button.active {
  background: #ffffff;
  color: #2563eb;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

/* ───────── Capacity split (sidebar) ───────── */
.cap-section {
  background: #f9fafb;
  border-radius: 6px;
  padding: 8px 10px;
  margin-top: 4px;
  margin-bottom: 4px;
}

.cap-section .cap-title {
  font-size: 10px;
  text-transform: uppercase;
  color: #6b7280;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.cap-row-split {
  display: grid;
  grid-template-columns: auto minmax(11ch, 1fr) 36px;
  align-items: baseline;
  font-size: 12px;
  padding: 2px 0;
  column-gap: 6px;
}

.cap-row-split .type {
  color: #4b5563;
  font-weight: 500;
}

.cap-row-split .val {
  display: contents;  /* let .num and .unit become direct grid items */
}

.cap-row-split .num {
  color: #111827;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  justify-self: end;
}

.cap-row-split .val.zero {
  color: #9ca3af;
  font-weight: 400;
}

.cap-row-split .val.muted,
.cap-row-split .num.muted {
  color: #9ca3af;
  font-weight: 400;
}

.cap-row-split .unit {
  color: #9ca3af;
  font-weight: 400;
  font-size: 10px;
  justify-self: start;  /* unit sits in its own column, fixed position regardless of num width */
}

/* ───────── Mobile (< 640px) ───────── */
@media (max-width: 640px) {
  header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 12px;
  }

  header h1 {
    font-size: 15px;
    text-align: center;
  }

  .legend {
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px 14px;
  }

  .view-toggle {
    margin-left: 0;
    width: 100%;
    justify-content: center;
  }

  .view-toggle-label {
    margin-left: 0;
  }

  /* sidebar: 全屏底部 sheet, 不挡地图 */
  aside {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 65vh;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
  }
}

/* ───────── 极窄屏 (< 380px) ───────── */
@media (max-width: 380px) {
  .legend {
    font-size: 11px;
    gap: 8px 10px;
  }

  .view-toggle button {
    padding: 4px 8px;
    font-size: 11px;
  }
}

/* ───────── Brand multi-select dropdown ───────── */
.brand-filter {
  position: relative;
  margin-left: 6px;
}

.brand-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  color: #1f2937;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
  max-width: 180px;
}

.brand-btn:hover {
  border-color: #9ca3af;
  background: #f9fafb;
}

.brand-btn-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}

.brand-btn-caret {
  font-size: 10px;
  color: #6b7280;
}

.brand-panel {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  z-index: 50;
  min-width: 220px;
  max-width: 280px;
}

.brand-panel.open {
  display: block;
}

.brand-panel-actions {
  display: flex;
  gap: 6px;
  padding: 6px 8px;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
  border-radius: 6px 6px 0 0;
}

.brand-panel-actions button {
  flex: 1;
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  color: #1f2937;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 3px;
  padding: 3px 8px;
  cursor: pointer;
}

.brand-panel-actions button:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}

.brand-list {
  max-height: 320px;
  overflow-y: auto;
  padding: 4px 0;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 12px;
  color: #1f2937;
  user-select: none;
}

.brand-row:hover {
  background: #f3f4f6;
}

.brand-row input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
  flex-shrink: 0;
}

.brand-row .brand-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-row .brand-count {
  font-size: 10px;
  color: #6b7280;
  background: #f3f4f6;
  padding: 1px 6px;
  border-radius: 8px;
  flex-shrink: 0;
}

/* ───────── Add plant button ───────── */
.add-btn {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: #ffffff;
  background: #2563eb;
  border: 1px solid #2563eb;
  border-radius: 4px;
  padding: 5px 12px;
  cursor: pointer;
  margin-left: 6px;
  white-space: nowrap;
}

.add-btn:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

/* ───────── Plant modal ───────── */
.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.45);
}

.modal-panel {
  position: relative;
  background: #ffffff;
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.18);
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
}

.modal-header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #111827;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: #6b7280;
  cursor: pointer;
  padding: 0 4px;
}

.modal-close:hover {
  color: #111827;
}

.modal-body {
  padding: 14px 18px 0;
  overflow-y: auto;
  flex: 1;
}

.form-section {
  border: none;
  border-top: 1px solid #e5e7eb;
  margin: 0 0 14px;
  padding: 10px 0 0;
}

.form-section:first-of-type {
  border-top: none;
  padding-top: 0;
}

.form-section legend {
  font-size: 11px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0 6px 0 0;
  background: #ffffff;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  margin-bottom: 8px;
}

.form-row label,
label.full {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1 1 140px;
  font-size: 11px;
  font-weight: 500;
  color: #4b5563;
}

label.full {
  flex-basis: 100%;
}

.form-row input,
.form-row select,
label.full input {
  font-family: inherit;
  font-size: 12px;
  color: #111827;
  padding: 5px 8px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: #ffffff;
}

.form-row input:focus,
.form-row select:focus,
label.full input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
}

.form-row input:invalid {
  border-color: #ef4444;
}

.form-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 12px;
  margin: 0 0 12px;
}

.form-error[hidden] {
  display: none;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
  margin: 14px -18px 0;
}

.btn-primary,
.btn-secondary {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-primary {
  background: #2563eb;
  color: #ffffff;
  border-color: #2563eb;
}

.btn-primary:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

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

.btn-secondary {
  background: #ffffff;
  color: #374151;
  border-color: #d1d5db;
}

.btn-secondary:hover {
  background: #f3f4f6;
}

/* ────── User bar (auth widget in header) ────── */
.user-bar {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: 12px;
}
.user-bar-name {
  font-size: 12px;
  color: #4b5563;
  padding: 4px 8px;
  background: #f3f4f6;
  border-radius: 4px;
  white-space: nowrap;
}
.user-bar-btn {
  font-size: 12px;
  padding: 5px 10px;
  border: 1px solid #d1d5db;
  background: white;
  border-radius: 4px;
  cursor: pointer;
  color: #374151;
  text-decoration: none;
  display: inline-block;
}
.user-bar-btn:hover {
  background: #f9fafb;
  border-color: #9ca3af;
}
.user-bar-btn.user-bar-login {
  background: #2563eb;
  color: white;
  border-color: #2563eb;
}
.user-bar-btn.user-bar-login:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

/* ────── Login modal ────── */
.modal-panel-narrow {
  max-width: 380px;
  width: 90%;
}
#login-form {
  padding: 16px 20px 20px;
}
#login-form label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  color: #374151;
  font-weight: 500;
}
#login-form label[hidden] {
  display: none;
}
#login-form input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 7px 10px;
  font-size: 14px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  box-sizing: border-box;
}
#login-form input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.form-error {
  color: #dc2626;
  font-size: 12px;
  padding: 8px 10px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 4px;
  margin-bottom: 12px;
}

/* ────── Sidebar Edit/Delete buttons ────── */
.sidebar-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #e5e7eb;
}
.btn-danger {
  background: white;
  color: #dc2626;
  border: 1px solid #dc2626;
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
}
.btn-danger:hover {
  background: #fef2f2;
}

/* ────── Login modal: switch to register link ────── */
.login-switch {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #f3f4f6;
  text-align: center;
  font-size: 12px;
  color: #6b7280;
}
.login-switch a {
  color: #2563eb;
  text-decoration: none;
}
.login-switch a:hover {
  text-decoration: underline;
}
