/* ================================================================
   TrackFlow · Design System v2.0
   Dark glassmorphism · Inter font · Micro-animations
   ================================================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ── Tokens ──────────────────────────────────────────────────── */
:root {
  /* Surface */
  --tf-bg:        #070b14;
  --tf-surface:   #0d1321;
  --tf-surface-2: #131a2b;
  --tf-surface-3: #192033;
  --tf-glass:     rgba(13,19,33,.72);
  --tf-glass-border: rgba(255,255,255,.06);
  /* Brand */
  --tf-brand:     #0ea5e9;
  --tf-brand-dim: #0284c7;
  --tf-brand-glow:rgba(14,165,233,.18);
  --tf-accent:    #06b6d4;
  /* Text */
  --tf-text:      #e8ecf4;
  --tf-text-2:    #94a3b8;
  --tf-text-3:    #64748b;
  --tf-heading:   #f1f5f9;
  /* Status */
  --tf-ok:        #10b981;
  --tf-ok-dim:    rgba(16,185,129,.15);
  --tf-warn:      #f59e0b;
  --tf-warn-dim:  rgba(245,158,11,.12);
  --tf-err:       #ef4444;
  --tf-err-dim:   rgba(239,68,68,.12);
  --tf-info:      #3b82f6;
  /* Layout */
  --tf-radius:    12px;
  --tf-radius-sm: 8px;
  --tf-radius-lg: 16px;
  --tf-radius-xl: 20px;
  --tf-shadow:    0 8px 32px rgba(0,0,0,.28);
  --tf-shadow-lg: 0 20px 60px rgba(0,0,0,.4);
  --tf-transition: .2s cubic-bezier(.4,0,.2,1);
  /* Rail */
  --tf-rail-w:    72px;
}

/* ── Reset & Base ────────────────────────────────────────────── */
*,*::before,*::after{box-sizing:border-box}
html{-webkit-text-size-adjust:100%;text-size-adjust:100%}
body{
  margin:0;
  font-family:'Inter',system-ui,-apple-system,sans-serif;
  font-size:.875rem;
  line-height:1.55;
  color:var(--tf-text);
  background:var(--tf-bg);
  -webkit-font-smoothing:antialiased;
  -moz-osx-font-smoothing:grayscale;
}
h1,h2,h3,h4,h5,h6{color:var(--tf-heading);margin:0 0 .5rem;font-weight:700;line-height:1.3}
h1{font-size:1.5rem}h2{font-size:1.15rem}h3{font-size:1rem}
p{margin:0 0 .75rem;color:var(--tf-text-2)}
a{color:var(--tf-brand);text-decoration:none;transition:color var(--tf-transition)}
a:hover{color:var(--tf-accent)}
::selection{background:var(--tf-brand);color:#fff}

/* ── Buttons ─────────────────────────────────────────────────── */
.tf-btn{
  display:inline-flex;align-items:center;justify-content:center;gap:.4rem;
  padding:.55rem 1rem;border-radius:var(--tf-radius-sm);
  font-family:inherit;font-size:.8rem;font-weight:600;
  cursor:pointer;border:1px solid var(--tf-glass-border);
  background:var(--tf-surface-2);color:var(--tf-text);
  transition:all var(--tf-transition);
  white-space:nowrap;
}
.tf-btn:hover{background:var(--tf-surface-3);border-color:rgba(255,255,255,.12)}
.tf-btn:active{transform:scale(.97)}
.tf-btn:disabled{opacity:.45;pointer-events:none}
.tf-btn svg{width:16px;height:16px;flex-shrink:0}

.tf-btn-primary{
  background:linear-gradient(135deg,var(--tf-brand),var(--tf-brand-dim));
  border:none;color:#fff;
  box-shadow:0 2px 12px var(--tf-brand-glow);
}
.tf-btn-primary:hover{filter:brightness(1.1);box-shadow:0 4px 20px var(--tf-brand-glow)}
.tf-btn-danger{background:var(--tf-err-dim);color:var(--tf-err);border-color:rgba(239,68,68,.2)}
.tf-btn-danger:hover{background:rgba(239,68,68,.2)}
.tf-btn-ghost{background:transparent;border-color:transparent;color:var(--tf-text-2)}
.tf-btn-ghost:hover{color:var(--tf-text);background:var(--tf-surface-2)}
.tf-btn-sm{padding:.35rem .7rem;font-size:.72rem;border-radius:6px}
.tf-btn-block{width:100%}
.tf-btn-icon{width:36px;height:36px;padding:0;border-radius:var(--tf-radius-sm)}

/* Loading state */
.tf-btn.loading{pointer-events:none;position:relative;color:transparent!important}
.tf-btn.loading::after{
  content:'';position:absolute;width:18px;height:18px;
  border:2px solid rgba(255,255,255,.3);border-top-color:#fff;border-radius:50%;
  animation:tf-spin .6s linear infinite;
}
@keyframes tf-spin{to{transform:rotate(360deg)}}

/* ── Inputs ──────────────────────────────────────────────────── */
.tf-input,.tf-select,.tf-textarea{
  width:100%;padding:.6rem .75rem;
  border-radius:var(--tf-radius-sm);
  border:1px solid rgba(255,255,255,.08);
  background:var(--tf-bg);color:var(--tf-text);
  font-family:inherit;font-size:.88rem;
  transition:border-color var(--tf-transition),box-shadow var(--tf-transition);
  outline:none;
}
.tf-input:focus,.tf-select:focus,.tf-textarea:focus{
  border-color:var(--tf-brand);
  box-shadow:0 0 0 3px var(--tf-brand-glow);
}
.tf-input::placeholder{color:var(--tf-text-3)}
.tf-textarea{min-height:80px;resize:vertical}
.tf-label{
  display:block;margin:0 0 .3rem;
  font-size:.72rem;font-weight:600;color:var(--tf-text-3);
  text-transform:uppercase;letter-spacing:.06em;
}
.tf-field{margin-bottom:.85rem}
.tf-field-error .tf-input{border-color:var(--tf-err)}
.tf-field-hint{font-size:.72rem;color:var(--tf-text-3);margin-top:.25rem}

/* ── Cards ───────────────────────────────────────────────────── */
.tf-card{
  background:var(--tf-glass);
  backdrop-filter:blur(16px);-webkit-backdrop-filter:blur(16px);
  border:1px solid var(--tf-glass-border);
  border-radius:var(--tf-radius-lg);
  padding:1.15rem;
  transition:border-color var(--tf-transition);
}
.tf-card:hover{border-color:rgba(255,255,255,.1)}
.tf-card-header{
  display:flex;align-items:center;justify-content:space-between;
  margin-bottom:.85rem;
}
.tf-card-header h3{margin:0}
.tf-card-flush{padding:0}

/* ── Badges ──────────────────────────────────────────────────── */
.tf-badge{
  display:inline-flex;align-items:center;gap:.3rem;
  padding:.15rem .55rem;border-radius:999px;
  font-size:.68rem;font-weight:600;
  line-height:1.4;
}
.tf-badge-ok{background:var(--tf-ok-dim);color:var(--tf-ok)}
.tf-badge-warn{background:var(--tf-warn-dim);color:var(--tf-warn)}
.tf-badge-err{background:var(--tf-err-dim);color:var(--tf-err)}
.tf-badge-info{background:rgba(59,130,246,.12);color:var(--tf-info)}
.tf-badge-brand{background:var(--tf-brand-glow);color:var(--tf-brand)}
.tf-badge-neutral{background:rgba(148,163,184,.1);color:var(--tf-text-2)}

/* ── Tables ──────────────────────────────────────────────────── */
.tf-table{width:100%;border-collapse:collapse;font-size:.82rem}
.tf-table th{
  text-align:left;padding:.55rem .65rem;
  font-size:.68rem;font-weight:700;color:var(--tf-text-3);
  text-transform:uppercase;letter-spacing:.06em;
  border-bottom:1px solid rgba(255,255,255,.06);
}
.tf-table td{
  padding:.6rem .65rem;
  border-bottom:1px solid rgba(255,255,255,.04);
  vertical-align:middle;
}
.tf-table tbody tr{transition:background var(--tf-transition)}
.tf-table tbody tr:hover{background:rgba(255,255,255,.03)}
.tf-table-mono{font-family:'Courier New',monospace;font-size:.7rem;word-break:break-all}

/* ── Modal System ────────────────────────────────────────────── */
.tf-modal-overlay{
  position:fixed;inset:0;z-index:5000;
  background:rgba(0,0,0,.55);
  backdrop-filter:blur(4px);-webkit-backdrop-filter:blur(4px);
  display:flex;align-items:center;justify-content:center;
  padding:1rem;
  opacity:0;pointer-events:none;
  transition:opacity .25s ease;
}
.tf-modal-overlay.open{opacity:1;pointer-events:auto}
.tf-modal{
  background:var(--tf-surface);
  border:1px solid var(--tf-glass-border);
  border-radius:var(--tf-radius-xl);
  width:min(460px,100%);max-height:88vh;
  overflow:hidden;display:flex;flex-direction:column;
  box-shadow:var(--tf-shadow-lg);
  transform:translateY(16px) scale(.97);
  transition:transform .25s ease;
}
.tf-modal-overlay.open .tf-modal{transform:translateY(0) scale(1)}
.tf-modal-header{
  display:flex;align-items:center;justify-content:space-between;
  padding:.9rem 1.15rem;
  border-bottom:1px solid rgba(255,255,255,.06);
  flex-shrink:0;
}
.tf-modal-header h2{margin:0;font-size:1rem}
.tf-modal-close{
  width:32px;height:32px;border-radius:var(--tf-radius-sm);
  border:none;background:var(--tf-surface-2);color:var(--tf-text-2);
  cursor:pointer;display:flex;align-items:center;justify-content:center;
  font-size:1.1rem;transition:all var(--tf-transition);
}
.tf-modal-close:hover{background:var(--tf-surface-3);color:var(--tf-text)}
.tf-modal-body{padding:1rem 1.15rem 1.25rem;overflow-y:auto;flex:1}
.tf-modal-footer{
  padding:.75rem 1.15rem;
  border-top:1px solid rgba(255,255,255,.06);
  display:flex;gap:.5rem;justify-content:flex-end;
  flex-shrink:0;
}

/* ── Toast Notifications ─────────────────────────────────────── */
.tf-toast-container{
  position:fixed;top:1rem;right:1rem;z-index:9000;
  display:flex;flex-direction:column;gap:.5rem;
  pointer-events:none;max-width:380px;width:100%;
}
.tf-toast{
  background:var(--tf-surface-2);
  border:1px solid var(--tf-glass-border);
  border-radius:var(--tf-radius);
  padding:.75rem 1rem;
  display:flex;align-items:flex-start;gap:.6rem;
  box-shadow:var(--tf-shadow);
  pointer-events:auto;
  animation:tf-toast-in .3s ease;
  font-size:.82rem;line-height:1.45;
}
.tf-toast.removing{animation:tf-toast-out .25s ease forwards}
@keyframes tf-toast-in{from{opacity:0;transform:translateX(40px)}to{opacity:1;transform:translateX(0)}}
@keyframes tf-toast-out{to{opacity:0;transform:translateX(40px)}}
.tf-toast-icon{font-size:1.1rem;flex-shrink:0;margin-top:.1rem}
.tf-toast-body{flex:1;min-width:0}
.tf-toast-title{font-weight:600;color:var(--tf-heading);margin-bottom:.1rem}
.tf-toast-msg{color:var(--tf-text-2)}
.tf-toast-close{
  flex-shrink:0;background:none;border:none;color:var(--tf-text-3);
  cursor:pointer;padding:0;font-size:1rem;line-height:1;
}
.tf-toast-close:hover{color:var(--tf-text)}
.tf-toast-success{border-left:3px solid var(--tf-ok)}
.tf-toast-error{border-left:3px solid var(--tf-err)}
.tf-toast-warning{border-left:3px solid var(--tf-warn)}
.tf-toast-info{border-left:3px solid var(--tf-info)}

/* ── Confirm Dialog ──────────────────────────────────────────── */
.tf-confirm-actions{display:flex;gap:.5rem;justify-content:flex-end;margin-top:1rem}

/* ── Sidebar Rail ────────────────────────────────────────────── */
.tf-rail{
  width:var(--tf-rail-w);
  background:var(--tf-surface);
  border-right:1px solid var(--tf-glass-border);
  display:flex;flex-direction:column;align-items:center;
  padding:.75rem 0 1rem;gap:.2rem;flex-shrink:0;
  overflow-y:auto;
}
.tf-rail-brand{
  width:40px;height:40px;margin-bottom:.65rem;
  border-radius:var(--tf-radius);overflow:hidden;
}
.tf-rail-brand img{width:100%;height:100%;object-fit:cover}
.tf-rail-btn{
  width:52px;border:none;background:transparent;
  color:var(--tf-text-3);border-radius:var(--tf-radius);
  padding:.5rem .25rem;cursor:pointer;text-align:center;
  font-size:.6rem;font-weight:500;font-family:inherit;
  display:flex;flex-direction:column;align-items:center;gap:.15rem;
  transition:all var(--tf-transition);position:relative;
}
.tf-rail-btn svg{width:20px;height:20px;stroke:currentColor;fill:none;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
.tf-rail-btn:hover{background:var(--tf-surface-2);color:var(--tf-text)}
.tf-rail-btn.active{color:var(--tf-brand)}
.tf-rail-btn.active::before{
  content:'';position:absolute;left:0;top:50%;transform:translateY(-50%);
  width:3px;height:24px;border-radius:0 3px 3px 0;
  background:var(--tf-brand);
}
.tf-rail-spacer{flex:1}

/* ── Topbar ──────────────────────────────────────────────────── */
.tf-topbar{
  display:flex;align-items:center;gap:.75rem;
  padding:.55rem 1.15rem;
  background:var(--tf-surface);
  border-bottom:1px solid var(--tf-glass-border);
  flex-wrap:wrap;min-height:52px;
}
.tf-topbar-brand{
  font-weight:800;font-size:1rem;color:var(--tf-heading);
  display:flex;align-items:center;gap:.5rem;
  letter-spacing:-.02em;
}
.tf-topbar-brand span{
  font-weight:500;font-size:.72rem;color:var(--tf-text-3);
  background:var(--tf-surface-2);padding:.15rem .5rem;border-radius:999px;
}
.tf-grow{flex:1;min-width:80px}
.tf-search{
  position:relative;max-width:280px;width:100%;
}
.tf-search input{
  padding-left:2.2rem;
  background:var(--tf-surface-2);
  border-color:transparent;
}
.tf-search input:focus{border-color:var(--tf-brand)}
.tf-search-icon{
  position:absolute;left:.7rem;top:50%;transform:translateY(-50%);
  width:16px;height:16px;color:var(--tf-text-3);pointer-events:none;
}
.tf-user-pill{
  font-size:.75rem;color:var(--tf-text-2);
  display:flex;align-items:center;gap:.5rem;
}
.tf-user-pill strong{color:var(--tf-text)}
.tf-user-avatar{
  width:28px;height:28px;border-radius:50%;
  background:linear-gradient(135deg,var(--tf-brand),var(--tf-accent));
  display:flex;align-items:center;justify-content:center;
  font-size:.65rem;font-weight:700;color:#fff;
}

/* ── Layout ──────────────────────────────────────────────────── */
.tf-app{display:flex;height:100vh;overflow:hidden}
.tf-workspace{flex:1;display:flex;flex-direction:column;min-width:0}
.tf-main{flex:1;position:relative;min-height:0;overflow:hidden}
.tf-view{
  position:absolute;inset:0;display:none;
  flex-direction:column;overflow:hidden;
}
.tf-view.active{display:flex}
.tf-scroll{overflow-y:auto;flex:1;padding:1.15rem}
.tf-panel-header{
  padding:1rem 1.15rem;
  border-bottom:1px solid var(--tf-glass-border);
}
.tf-panel-header h1{margin:0 0 .25rem}
.tf-panel-header p{margin:0;font-size:.78rem}

/* ── Map ─────────────────────────────────────────────────────── */
.tf-map-wrap{flex:1;position:relative;min-height:0}
.tf-map-wrap #map{position:absolute;inset:0;width:100%;height:100%}
.tf-map-empty{
  position:absolute;bottom:1rem;left:1rem;z-index:500;
  max-width:min(340px,calc(100% - 2rem));
  background:var(--tf-glass);
  backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);
  border:1px solid var(--tf-glass-border);
  border-radius:var(--tf-radius-lg);
  padding:.85rem 1rem;
  font-size:.78rem;line-height:1.45;
  color:var(--tf-text-2);
}
.tf-map-stats{
  position:absolute;top:.75rem;right:.75rem;z-index:500;
  display:flex;gap:.4rem;
}
.tf-map-stats .tf-badge{
  background:var(--tf-glass);
  backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px);
  border:1px solid var(--tf-glass-border);
  padding:.3rem .6rem;font-size:.7rem;
}

/* ── List items ──────────────────────────────────────────────── */
.tf-list{list-style:none;margin:0;padding:0}
.tf-list-item{
  padding:.75rem .85rem;
  border-bottom:1px solid rgba(255,255,255,.04);
  display:flex;align-items:flex-start;gap:.75rem;
  transition:background var(--tf-transition);
}
.tf-list-item:last-child{border-bottom:0}
.tf-list-item:hover{background:rgba(255,255,255,.02)}
.tf-list-avatar{
  width:36px;height:36px;border-radius:var(--tf-radius-sm);flex-shrink:0;
  background:var(--tf-surface-3);
  display:flex;align-items:center;justify-content:center;
  font-size:.85rem;
}
.tf-list-content{flex:1;min-width:0}
.tf-list-title{font-weight:600;color:var(--tf-heading);font-size:.85rem}
.tf-list-sub{font-size:.72rem;color:var(--tf-text-3)}
.tf-list-actions{display:flex;gap:.35rem;flex-wrap:wrap;margin-top:.4rem}

/* ── Empty state ─────────────────────────────────────────────── */
.tf-empty{
  padding:2.5rem 1.5rem;text-align:center;
  color:var(--tf-text-3);
}
.tf-empty-icon{font-size:2.5rem;margin-bottom:.75rem;opacity:.5}
.tf-empty-title{font-size:.92rem;font-weight:600;color:var(--tf-text-2);margin-bottom:.25rem}
.tf-empty-desc{font-size:.78rem}

/* ── Row / Flex ──────────────────────────────────────────────── */
.tf-row{display:flex;gap:.5rem;flex-wrap:wrap;align-items:center}
.tf-row-between{justify-content:space-between}
.tf-stack{display:flex;flex-direction:column;gap:.65rem}

/* ── Switch ──────────────────────────────────────────────────── */
.tf-switch{
  position:relative;display:inline-block;width:44px;height:24px;
}
.tf-switch input{opacity:0;width:0;height:0}
.tf-switch-track{
  position:absolute;inset:0;cursor:pointer;
  background:var(--tf-surface-3);border-radius:999px;
  transition:background var(--tf-transition);
}
.tf-switch-track::before{
  content:'';position:absolute;width:18px;height:18px;
  left:3px;bottom:3px;background:#fff;border-radius:50%;
  transition:transform var(--tf-transition);
}
.tf-switch input:checked + .tf-switch-track{background:var(--tf-ok)}
.tf-switch input:checked + .tf-switch-track::before{transform:translateX(20px)}

/* ── Pulse / Status dot ──────────────────────────────────────── */
.tf-pulse{
  width:8px;height:8px;border-radius:50%;
  background:var(--tf-ok);
  animation:tf-pulse-anim 2s ease-in-out infinite;
}
@keyframes tf-pulse-anim{0%,100%{box-shadow:0 0 0 0 rgba(16,185,129,.4)}50%{box-shadow:0 0 0 6px rgba(16,185,129,0)}}
.tf-pulse-warn{background:var(--tf-warn)}
.tf-pulse-warn{animation-name:tf-pulse-warn-anim}
@keyframes tf-pulse-warn-anim{0%,100%{box-shadow:0 0 0 0 rgba(245,158,11,.4)}50%{box-shadow:0 0 0 6px rgba(245,158,11,0)}}
.tf-pulse-err{background:var(--tf-err);animation:none}

/* ── Skeleton loader ─────────────────────────────────────────── */
.tf-skeleton{
  background:linear-gradient(90deg,var(--tf-surface-2) 25%,var(--tf-surface-3) 50%,var(--tf-surface-2) 75%);
  background-size:200% 100%;
  animation:tf-shimmer 1.5s infinite;
  border-radius:var(--tf-radius-sm);
  height:1rem;
}
@keyframes tf-shimmer{0%{background-position:200% 0}100%{background-position:-200% 0}}

/* ── Divider ─────────────────────────────────────────────────── */
.tf-divider{height:1px;background:rgba(255,255,255,.06);margin:1rem 0;border:0}

/* ── Leaflet overrides ───────────────────────────────────────── */
.leaflet-container{background:var(--tf-bg)!important;font-family:inherit!important}
.tf-truck-marker{background:transparent!important;border:none!important}
.leaflet-popup-content-wrapper{
  background:var(--tf-surface)!important;color:var(--tf-text)!important;
  border-radius:var(--tf-radius)!important;border:1px solid var(--tf-glass-border)!important;
  box-shadow:var(--tf-shadow)!important;
}
.leaflet-popup-tip{background:var(--tf-surface)!important}
.leaflet-tooltip{
  background:var(--tf-surface-2)!important;color:var(--tf-text)!important;
  border:1px solid var(--tf-glass-border)!important;
  border-radius:var(--tf-radius-sm)!important;
  font-family:inherit!important;font-size:.72rem!important;
  box-shadow:var(--tf-shadow)!important;padding:.3rem .55rem!important;
}
.leaflet-tooltip-top::before{border-top-color:var(--tf-surface-2)!important}
.leaflet-control-zoom a{
  background:var(--tf-surface)!important;color:var(--tf-text)!important;
  border-color:var(--tf-glass-border)!important;
}
.leaflet-control-zoom a:hover{background:var(--tf-surface-2)!important}

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar{width:6px;height:6px}
::-webkit-scrollbar-track{background:transparent}
::-webkit-scrollbar-thumb{background:rgba(255,255,255,.08);border-radius:999px}
::-webkit-scrollbar-thumb:hover{background:rgba(255,255,255,.15)}

/* ── Hidden utility ──────────────────────────────────────────── */
.hidden{display:none!important}

/* ── Responsive ──────────────────────────────────────────────── */
@media(max-width:768px){
  .tf-rail{width:0;display:none}
  .tf-topbar{padding:.5rem .75rem;gap:.5rem}
  .tf-search{max-width:100%}
  .tf-modal{max-height:95vh;border-radius:var(--tf-radius-lg) var(--tf-radius-lg) 0 0}
  .tf-modal-overlay{align-items:flex-end;padding:0}
}
