/* ============================================================
   AssetTrack — Design System (Material 3)
   ============================================================ */

/* ---------- CSS Variables ---------- */
:root {
  --primary: #bc0007;
  --on-primary: #ffffff;
  --primary-container: #ea000c;
  --on-primary-container: #fffbff;
  --inverse-primary: #ffb4a9;
  --surface: #f9f9f9;
  --surface-dim: #dadada;
  --surface-bright: #f9f9f9;
  --surface-container-lowest: #ffffff;
  --surface-container-low: #f3f3f3;
  --surface-container: #eeeeee;
  --surface-container-high: #e8e8e8;
  --surface-container-highest: #e2e2e2;
  --on-surface: #1b1b1b;
  --on-surface-variant: #5f3e3a;
  --inverse-surface: #303030;
  --inverse-on-surface: #f1f1f1;
  --outline: #946e68;
  --outline-variant: #eabcb5;
  --surface-tint: #c00007;
  --error: #ba1a1a;
  --on-error: #ffffff;
  --error-container: #ffdad6;
  --on-error-container: #93000a;
  --background: #f9f9f9;
  --on-background: #1b1b1b;
  --surface-variant: #e2e2e2;
  --secondary: #5d5f5f;
  --on-secondary: #ffffff;
  --secondary-container: #dfe0e0;
  --on-secondary-container: #616363;
  --tertiary: #5c5c5c;
  --on-tertiary: #ffffff;
  --tertiary-container: #757474;
  --on-tertiary-container: #fefcfc;

  --font-display: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-2xl: 24px;
  --radius-full: 9999px;

  --space-unit: 4px;
  --space-gutter: 16px;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; font-family: var(--font-body); font-size: 14px; color: var(--on-background); background: var(--background); }
button { cursor: pointer; font-family: inherit; }
a { color: inherit; text-decoration: none; }
input, select, textarea { font-family: inherit; font-size: inherit; outline: none; }

/* ---------- Leaflet overrides ---------- */
#map { position: fixed; inset: 0; z-index: 0; }
.leaflet-container { width: 100%; height: 100%; z-index: 0; }

/* ---------- Glass base ---------- */
.glass {
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--outline-variant);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}
.glass-strong {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--outline-variant);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

/* ---------- Header ---------- */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 44px;
  z-index: 1001;
  background: var(--inverse-surface);
  color: var(--inverse-on-surface);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 10px;
}
.header-logo {
  width: 28px; height: 28px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.header-title { font-family: var(--font-display); font-size: 14px; font-weight: 600; white-space: nowrap; }
.header-status {
  font-size: 10px;
  color: var(--inverse-primary);
  display: flex;
  align-items: center;
  gap: 4px;
}
.header-status::before {
  content: '';
  width: 6px; height: 6px;
  background: var(--inverse-primary);
  border-radius: 50%;
  animation: pulse 2s infinite;
}
.header-spacer { flex: 1; }
.header-link {
  padding: 4px 10px;
  font-size: 11px;
  font-family: var(--font-body);
  background: rgba(255,255,255,0.1);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--inverse-on-surface);
  transition: background 0.15s;
}
.header-link:hover { background: rgba(255,255,255,0.2); }
.header-menu {
  width: 28px; height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  font-size: 16px;
  color: var(--inverse-on-surface);
  opacity: 0.7;
  transition: opacity 0.15s;
}
.header-menu:hover { opacity: 1; }

/* ---------- Search ---------- */
.search-container {
  position: fixed;
  top: 54px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  width: min(480px, calc(100vw - 80px));
  border-radius: var(--radius-lg);
  padding: 0;
  overflow: visible;
}
.search-input {
  width: 100%;
  padding: 10px 16px 10px 40px;
  border: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: 14px;
  border-radius: var(--radius-lg);
  color: var(--on-surface);
}
.search-input::placeholder { color: var(--on-surface-variant); opacity: 0.6; }
.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  color: var(--on-surface-variant);
  pointer-events: none;
}
.autocomplete-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface-container-lowest);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  max-height: 280px;
  overflow-y: auto;
  display: none;
}
.autocomplete-results.show { display: block; }
.autocomplete-item {
  padding: 10px 16px;
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--surface-container);
  display: flex;
  align-items: center;
  gap: 8px;
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--surface-container-low); }
.autocomplete-item .label { font-weight: 500; }
.autocomplete-item .sub { font-size: 11px; color: var(--on-surface-variant); }

/* ---------- Floating Toolbar ---------- */
.toolbar {
  position: fixed;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1000;
  border-radius: var(--radius-xl);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.toolbar-btn {
  width: 38px; height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  font-size: 16px;
  color: var(--on-surface-variant);
  position: relative;
  transition: all 0.15s;
}
.toolbar-btn:hover {
  background: rgba(188, 0, 7, 0.08);
  color: var(--primary);
}
.toolbar-btn.active {
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 2px 8px rgba(188,0,7,0.3);
}
.toolbar-btn .tooltip {
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--inverse-surface);
  color: var(--inverse-on-surface);
  font-family: var(--font-body);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 2000;
}
.toolbar-btn:hover .tooltip { opacity: 1; }

/* ---------- Scrim ---------- */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 1002;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.scrim.show { opacity: 1; pointer-events: auto; }

/* ---------- Right Drawer ---------- */
:root { --header-h: 44px; --drawer-w: 340px; }
.drawer {
  position: fixed;
  top: var(--header-h); right: 0;
  width: var(--drawer-w);
  height: calc(100% - var(--header-h));
  z-index: 1003;
  background: var(--surface-container-lowest);
  box-shadow: -4px 0 32px rgba(0,0,0,0.12);
  transform: translateX(0);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.1s;
  display: flex;
  flex-direction: column;
}
.drawer.collapsed { transform: translateX(100%); }
.drawer-resize-handle {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 8px;
  cursor: col-resize;
  z-index: 5;
}
.drawer-resize-handle::after {
  content: '';
  position: absolute;
  left: 2px; top: 50%;
  transform: translateY(-50%);
  width: 4px; height: 40px;
  background: var(--outline-variant);
  border-radius: 3px;
  opacity: 0;
  transition: opacity 0.15s;
}
.drawer-resize-handle:hover::after,
.drawer-resize-handle:active::after { opacity: 0.6; }
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--surface-container-highest);
}
.drawer-header h2 { font-family: var(--font-display); font-size: 15px; font-weight: 600; }
.drawer-close {
  width: 32px; height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--surface-container);
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--on-surface-variant);
  transition: background 0.15s;
}
.drawer-close:hover { background: var(--surface-container-high); }
.drawer-stats {
  padding: 8px 16px;
  font-size: 11px;
  color: var(--on-surface-variant);
  background: var(--surface-container-low);
  border-bottom: 1px solid var(--surface-container-highest);
}
.drawer-body { flex: 1; overflow-y: auto; padding: 12px; }

/* ---------- Section headers / splitters inside drawer ---------- */
.section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--on-surface-variant);
  padding: 10px 4px 6px;
}
.splitter {
  height: 1px;
  background: var(--surface-container-highest);
  margin: 8px 0;
}

/* ---------- Drawer collapse toggle (bottom) ---------- */
.drawer-toggle {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 10px 16px;
  margin-top: auto;
  font-size: 12px;
  color: var(--on-surface-variant);
  border-top: 1px solid var(--surface-container-highest);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.drawer-toggle:hover {
  background: var(--surface-container);
  color: var(--on-surface);
}

/* ---------- Layer controls ---------- */
.layer-controls { display: flex; flex-direction: column; gap: 4px; }
.layer-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  cursor: pointer;
  padding: 3px 0;
  color: var(--on-surface-variant);
}
.layer-label input[type="checkbox"] {
  accent-color: var(--primary);
  width: 14px; height: 14px;
}
.layer-label .layer-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.layer-sub {
  font-size: 10px;
  color: var(--primary);
  text-decoration: underline;
  margin-left: 22px;
  cursor: pointer;
}

/* ---------- Asset List ---------- */
.asset-item {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--surface-container-highest);
  font-size: 12px;
  cursor: pointer;
  background: var(--surface-container-lowest);
  margin-bottom: 6px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.asset-item:hover {
  border-color: var(--primary);
  box-shadow: 0 1px 4px rgba(188,0,7,0.08);
}
.asset-item .name { font-weight: 500; margin-bottom: 2px; }
.asset-item .meta { color: var(--on-surface-variant); }

/* ---------- Bottom Sheet ---------- */
.bottom-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 1003;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.bottom-sheet.open { transform: translateY(0); }
.bottom-sheet-inner {
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
  box-shadow: 0 -4px 32px rgba(0,0,0,0.08);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
}
.sheet-drag {
  display: flex;
  justify-content: center;
  padding: 10px 0 4px;
  cursor: grab;
  touch-action: none;
}
.sheet-drag:active { cursor: grabbing; }
.sheet-drag-bar {
  width: 40px; height: 5px;
  background: var(--primary);
  border-radius: var(--radius-full);
}
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px 10px;
  flex-shrink: 0;
  touch-action: none;
}
.sheet-title { font-family: var(--font-display); font-size: 15px; font-weight: 600; }
.sheet-close {
  width: 32px; height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--surface-container);
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--on-surface-variant);
  transition: background 0.15s;
}
.sheet-close:hover { background: var(--surface-container-high); }
.sheet-body {
  overflow-y: auto;
  padding: 0 20px 20px;
  flex: 1;
}

/* ---------- Panel Cards (inside bottom sheet) ---------- */
.panel-card {
  border-radius: var(--radius-lg);
  padding: 16px;
  font-size: 13px;
}
.panel-card h3 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
}
.panel-card label { font-size: 11px; font-weight: 500; color: var(--on-surface-variant); margin-bottom: 2px; display: block; }
.panel-card input,
.panel-card select,
.panel-card textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--outline);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 13px;
  background: var(--surface-container-lowest);
  transition: border-color 0.15s;
  margin-bottom: 8px;
}
.panel-card input:focus,
.panel-card select:focus,
.panel-card textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(188,0,7,0.08);
}
.panel-card textarea { resize: vertical; min-height: 60px; }
.panel-card hr { border: none; border-top: 1px solid var(--surface-container-highest); margin: 12px 0; }
.panel-card .btn-primary {
  width: 100%;
  padding: 10px;
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.panel-card .btn-primary:hover { background: var(--primary-container); }
.panel-card .btn-secondary {
  padding: 8px;
  font-size: 12px;
  color: var(--on-surface-variant);
  background: none;
  border: none;
  cursor: pointer;
  width: 100%;
  text-align: center;
}
.panel-card .btn-secondary:hover { color: var(--on-surface); }
.panel-card .btn-sm {
  padding: 4px 10px;
  font-size: 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--outline);
  background: var(--surface-container-lowest);
  cursor: pointer;
  transition: all 0.15s;
}
.panel-card .btn-sm:hover { border-color: var(--primary); color: var(--primary); }
.panel-card .flex-row { display: flex; gap: 8px; }
.panel-card .flex-row > * { flex: 1; }

/* ---------- Form rows in panel ---------- */
.form-row { display: flex; gap: 8px; }
.form-row > * { flex: 1; }

/* ---------- List items inside panels ---------- */
.list-item {
  border-bottom: 1px solid var(--surface-container);
  padding: 8px 0;
  font-size: 12px;
}
.list-item:last-child { border-bottom: none; }
.list-item .primary { font-weight: 500; }
.list-item .secondary { color: var(--on-surface-variant); font-size: 11px; }

/* ---------- Mobile Bottom Tabs ---------- */
.mobile-tabs {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 1000;
  background: var(--surface-container-lowest);
  border-top: 1px solid var(--surface-container-highest);
  padding: 4px 0 env(safe-area-inset-bottom, 4px);
}
.mobile-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 4px 0;
  border: none;
  background: transparent;
  font-size: 18px;
  color: var(--on-surface-variant);
  transition: color 0.15s;
}
.mobile-tab.active { color: var(--primary); }
.mobile-tab span { font-size: 9px; color: inherit; }

/* ---------- Status badges ---------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: 500;
  font-family: var(--font-mono);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.badge-active { background: #d1fae5; color: #065f46; }
.badge-maintenance { background: #fef3c7; color: #92400e; }
.badge-decommissioned { background: #fee2e2; color: #991b1b; }
.badge-planned { background: #dbeafe; color: #1e40af; }
.badge-pending { background: var(--surface-container); color: var(--on-surface-variant); }
.badge-in_progress { background: #fef3c7; color: #92400e; }
.badge-completed { background: #d1fae5; color: #065f46; }
.badge-open { background: #fee2e2; color: #991b1b; }

/* ---------- Animations ---------- */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.animate-in {
  animation: slideUp 0.3s ease-out;
}

/* ---------- Responsive ---------- */

/* Tablet: 768-1024px */
@media (max-width: 1024px) {
  .toolbar { left: 8px; }
  .toolbar-btn { width: 34px; height: 34px; font-size: 14px; }
  .search-container { width: min(400px, calc(100vw - 60px)); }
}

/* Medium mobile: 480-768px — drawer slim on right */
@media (min-width: 480px) and (max-width: 768px) {
  .drawer {
    --drawer-w: 220px;
    width: var(--drawer-w);
  }
  .drawer-body { padding: 8px; }
  .drawer-stats { padding: 6px 12px; font-size: 10px; }
  .drawer-header { padding: 10px 12px; }
  .drawer-header h2 { font-size: 13px; }
  .drawer-toggle { padding: 8px 12px; font-size: 11px; }
}

/* Mobile: <768px */
@media (max-width: 768px) {
  .toolbar { display: none; }
  .mobile-tabs { display: flex; }
  .search-container {
    top: 50px;
    width: calc(100vw - 24px);
    left: 12px;
    transform: none;
    border-radius: var(--radius-md);
  }
  .search-input { padding: 8px 12px 8px 36px; font-size: 13px; }
  .search-icon { left: 12px; font-size: 14px; }
  .drawer { width: min(85vw, 340px); }
  .bottom-sheet-inner { max-height: 85vh; border-radius: var(--radius-xl) var(--radius-xl) 0 0; }
  .sheet-body { padding: 0 16px 16px; }
  .sheet-header { padding: 0 16px 8px; }
  .panel-card { padding: 12px; }
  .header-title { font-size: 13px; }
  .header-link { padding: 3px 8px; font-size: 10px; }
  .bottom-sheet { padding-bottom: 56px; }
}
