/* =========================================================
   TAGO Design System v1.0
   
   Colors: Navy, Gold, Sky, Green, Red
   Font:   Inter (headings + body), JetBrains Mono (numbers)
   Style:  Mobile-first, rounded, friendly
   ========================================================= */

/* ---------- RESET ---------- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: #1A2332;
    background: #F5F7FA;
    overflow-x: hidden;
    min-height: 100vh;
}

img, svg {
    display: block;
    max-width: 100%;
}

button, input, select, textarea {
    font: inherit;
    color: inherit;
}

a {
    color: #3B82F6;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ---------- CSS VARIABLES (TAGO Palette) ---------- */
:root {
    /* Brand */
    --tago-navy:      #1A2332;
    --tago-navy-700:  #232E42;
    --tago-navy-500:  #2E3A52;
    --tago-gold:      #F5B041;
    --tago-gold-700:  #D89420;
    --tago-orange:    #E67E22;
    
    /* Functional */
    --tago-sky:       #3B82F6;
    --tago-sky-700:   #2563EB;
    --tago-green:     #10B981;
    --tago-green-700: #059669;
    --tago-red:       #EF4444;
    --tago-red-700:   #DC2626;
    --tago-yellow:    #F59E0B;
    
    /* Neutrals */
    --tago-white:     #FFFFFF;
    --tago-gray-50:   #F9FAFB;
    --tago-gray-100:  #F3F4F6;
    --tago-gray-200:  #E5E7EB;
    --tago-gray-300:  #D1D5DB;
    --tago-gray-400:  #9CA3AF;
    --tago-gray-500:  #6B7280;
    --tago-gray-700:  #374151;
    --tago-gray-900:  #111827;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow:    0 2px 8px rgba(26,35,50,0.08);
    --shadow-md: 0 4px 16px rgba(26,35,50,0.10);
    --shadow-lg: 0 8px 32px rgba(26,35,50,0.14);
    
    /* Radius */
    --radius-sm: 6px;
    --radius:    10px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    
    /* Spacing */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    
    /* Header / nav heights */
    --header-h: 56px;
    --tabbar-h: 64px;
}

/* ---------- TYPOGRAPHY ---------- */
h1, h2, h3, h4 {
    font-weight: 700;
    line-height: 1.2;
    color: var(--tago-navy);
}

h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
h4 { font-size: 16px; }

.mono {
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-feature-settings: 'tnum';
}

.text-muted  { color: var(--tago-gray-500); }
.text-small  { font-size: 13px; }
.text-tiny   { font-size: 11px; }
.text-bold   { font-weight: 700; }
.text-center { text-align: center; }

/* ---------- BUTTONS ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
    min-height: 44px;
    text-decoration: none;
}

.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.98); }

.btn-primary {
    background: var(--tago-sky);
    color: white;
}
.btn-primary:hover { background: var(--tago-sky-700); }

.btn-gold {
    background: var(--tago-gold);
    color: var(--tago-navy);
}
.btn-gold:hover { background: var(--tago-gold-700); }

.btn-danger {
    background: var(--tago-red);
    color: white;
}
.btn-danger:hover { background: var(--tago-red-700); }

.btn-success {
    background: var(--tago-green);
    color: white;
}
.btn-success:hover { background: var(--tago-green-700); }

.btn-outline {
    background: transparent;
    border: 2px solid var(--tago-gray-300);
    color: var(--tago-navy);
}
.btn-outline:hover {
    border-color: var(--tago-sky);
    color: var(--tago-sky);
}

.btn-ghost {
    background: transparent;
    color: var(--tago-navy);
}
.btn-ghost:hover { background: var(--tago-gray-100); }

.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 13px; min-height: 36px; }
.btn-lg { padding: 16px 28px; font-size: 17px; min-height: 52px; }

.btn:disabled,
.btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ---------- CARDS ---------- */
.card {
    background: white;
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow);
}

.card-tight { padding: var(--space-4); }

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--tago-gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-3);
}

/* ---------- FORMS ---------- */
.form-group {
    margin-bottom: var(--space-4);
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--tago-gray-700);
    margin-bottom: var(--space-2);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--tago-gray-200);
    border-radius: var(--radius);
    background: white;
    font-size: 15px;
    transition: border-color 0.15s;
    min-height: 46px;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--tago-sky);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

.form-input::placeholder {
    color: var(--tago-gray-400);
}

.form-hint {
    font-size: 12px;
    color: var(--tago-gray-500);
    margin-top: var(--space-1);
}

.form-error {
    font-size: 12px;
    color: var(--tago-red);
    margin-top: var(--space-1);
}

/* ---------- TOP HEADER BAR ---------- */
.tago-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-h);
    padding: 0 var(--space-4);
    background: var(--tago-navy);
    color: white;
    box-shadow: var(--shadow);
}

.tago-header-logo {
    display: flex;
    flex-direction: column;
    line-height: 1;
    cursor: pointer;
}

.tago-header-logo .name {
    font-size: 20px;
    font-weight: 800;
    color: var(--tago-gold);
    letter-spacing: 0.02em;
}

.tago-header-logo .tagline {
    font-size: 10px;
    color: rgba(255,255,255,0.6);
    margin-top: 2px;
    letter-spacing: 0.02em;
}

.tago-header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.tago-header-btn {
    position: relative;
    background: transparent;
    border: none;
    color: white;
    padding: 6px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    min-height: 40px;
}

.tago-header-btn:hover { background: rgba(255,255,255,0.1); }

.tago-header-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    background: var(--tago-red);
    color: white;
    font-size: 10px;
    font-weight: 700;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--tago-navy);
}

.tago-header-badge.hidden { display: none; }

/* ---------- BOTTOM TAB BAR ---------- */
.tago-tabbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--tabbar-h);
    background: var(--tago-navy);
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    z-index: 100;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.15);
    padding-bottom: env(safe-area-inset-bottom);
}

.tago-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: rgba(255,255,255,0.55);
    font-size: 11px;
    font-weight: 500;
    text-decoration: none;
    padding: 8px 4px;
    transition: color 0.15s;
    min-height: 44px;
    cursor: pointer;
    border: none;
    background: transparent;
}

.tago-tab:hover { text-decoration: none; color: white; }

.tago-tab.active {
    color: var(--tago-gold);
}

.tago-tab .icon {
    font-size: 22px;
    line-height: 1;
}

.tago-tab .label {
    font-size: 10px;
    letter-spacing: 0.02em;
}

/* Center floating TIGO logo tab */
.tago-tab.tago-tab-center {
    position: relative;
}

.tago-tab.tago-tab-center .icon {
    width: 52px;
    height: 52px;
    margin-top: -28px;
    background: var(--tago-navy);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tago-gold);
    font-weight: 800;
    font-size: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    border: 3px solid #F5F7FA;
}

/* ---------- PAGE LAYOUT ---------- */
.page {
    padding: var(--space-4);
    padding-bottom: calc(var(--tabbar-h) + var(--space-6));
    max-width: 480px;
    margin: 0 auto;
}

.page-full {
    padding: 0;
    padding-bottom: var(--tabbar-h);
    max-width: none;
}

.page-title {
    font-size: 24px;
    font-weight: 800;
    color: var(--tago-navy);
    margin-bottom: var(--space-4);
}

.section {
    margin-bottom: var(--space-6);
}

/* ---------- STAT CARDS ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: var(--space-4);
    box-shadow: var(--shadow-sm);
}

.stat-label {
    font-size: 11px;
    color: var(--tago-gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-1);
}

.stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 22px;
    font-weight: 700;
    color: var(--tago-navy);
}

.stat-unit {
    font-size: 12px;
    color: var(--tago-gray-500);
    font-weight: 400;
    margin-left: 2px;
}

/* ---------- LIST ITEMS ---------- */
.list {
    background: white;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.list-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4);
    border-bottom: 1px solid var(--tago-gray-100);
    cursor: pointer;
    transition: background 0.1s;
    text-decoration: none;
    color: inherit;
}

.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--tago-gray-50); text-decoration: none; }

.list-item-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: var(--tago-gray-100);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.list-item-content {
    flex: 1;
    min-width: 0;
}

.list-item-title {
    font-weight: 600;
    font-size: 15px;
    color: var(--tago-navy);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-item-subtitle {
    font-size: 13px;
    color: var(--tago-gray-500);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-item-arrow {
    color: var(--tago-gray-400);
    font-size: 18px;
}

/* ---------- STATUS PILLS ---------- */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.pill-online  { background: rgba(16,185,129,0.12); color: var(--tago-green-700); }
.pill-offline { background: rgba(107,114,128,0.12); color: var(--tago-gray-500); }
.pill-moving  { background: rgba(59,130,246,0.12);  color: var(--tago-sky-700); }
.pill-idle    { background: rgba(245,158,11,0.12);  color: var(--tago-yellow); }
.pill-danger  { background: rgba(239,68,68,0.12);   color: var(--tago-red-700); }

.pill-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.pill-online  .pill-dot { animation: pulse 1.5s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.4; }
}

/* ---------- ALERTS ---------- */
.alert-item {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-4);
    background: white;
    border-bottom: 1px solid var(--tago-gray-100);
    text-decoration: none;
    color: inherit;
}

.alert-item:hover { background: var(--tago-gray-50); text-decoration: none; }
.alert-item:last-child { border-bottom: none; }

.alert-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 18px;
}

.alert-icon.red    { background: rgba(239,68,68,0.12);  color: var(--tago-red); }
.alert-icon.yellow { background: rgba(245,158,11,0.12); color: var(--tago-yellow); }
.alert-icon.blue   { background: rgba(59,130,246,0.12); color: var(--tago-sky); }
.alert-icon.green  { background: rgba(16,185,129,0.12); color: var(--tago-green); }
.alert-icon.gray   { background: rgba(107,114,128,0.12); color: var(--tago-gray-500); }

.alert-content { flex: 1; min-width: 0; }
.alert-title   { font-weight: 600; color: var(--tago-navy); font-size: 14px; }
.alert-message { font-size: 13px; color: var(--tago-gray-700); margin-top: 2px; }
.alert-time    { font-size: 11px; color: var(--tago-gray-400); margin-top: 4px; }

.alert-item.unread .alert-title::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--tago-red);
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}

/* ---------- MAP ---------- */
.map-container {
    position: relative;
    width: 100%;
    height: calc(100vh - var(--header-h) - var(--tabbar-h));
}

#map { width: 100%; height: 100%; }

.map-overlay {
    position: absolute;
    top: var(--space-3);
    left: var(--space-3);
    right: var(--space-3);
    z-index: 400;
    pointer-events: none;
}

.map-overlay > * {
    pointer-events: auto;
}

.map-card {
    background: white;
    border-radius: var(--radius);
    padding: var(--space-3) var(--space-4);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.map-actions {
    position: absolute;
    bottom: var(--space-4);
    left: var(--space-3);
    right: var(--space-3);
    z-index: 400;
    display: flex;
    gap: var(--space-2);
}

.map-actions .btn {
    flex: 1;
    box-shadow: var(--shadow-md);
}

/* ---------- LOGIN / SIGNUP SCREEN ---------- */
.auth-screen {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, var(--tago-navy) 0%, var(--tago-navy-700) 55%, #F5F7FA 55%);
    padding: var(--space-6);
}

.auth-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-8) 0 var(--space-10);
    color: white;
}

.auth-brand-name {
    font-size: 44px;
    font-weight: 800;
    color: var(--tago-gold);
    letter-spacing: 0.02em;
    line-height: 1;
}

.auth-brand-tagline {
    font-size: 12px;
    color: rgba(255,255,255,0.65);
    letter-spacing: 0.08em;
    margin-top: var(--space-2);
    text-transform: uppercase;
}

.auth-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    box-shadow: var(--shadow-lg);
    flex: 1;
    max-width: 420px;
    width: 100%;
    margin: 0 auto;
}

.auth-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--tago-navy);
    margin-bottom: var(--space-2);
}

.auth-subtitle {
    font-size: 14px;
    color: var(--tago-gray-500);
    margin-bottom: var(--space-5);
}

.auth-switch {
    text-align: center;
    margin-top: var(--space-5);
    font-size: 14px;
    color: var(--tago-gray-500);
}

.auth-switch a {
    color: var(--tago-sky);
    font-weight: 600;
}

/* ---------- LOADING / EMPTY STATES ---------- */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-10) var(--space-4);
    color: var(--tago-gray-500);
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--tago-gray-200);
    border-top-color: var(--tago-sky);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: var(--space-3);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.empty-state {
    text-align: center;
    padding: var(--space-10) var(--space-4);
    color: var(--tago-gray-500);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: var(--space-3);
    opacity: 0.4;
}

.empty-state-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--tago-navy);
    margin-bottom: var(--space-2);
}

/* ---------- TOAST / NOTIFICATIONS ---------- */
.toast {
    position: fixed;
    bottom: calc(var(--tabbar-h) + var(--space-4));
    left: var(--space-4);
    right: var(--space-4);
    max-width: 420px;
    margin: 0 auto;
    background: var(--tago-navy);
    color: white;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    z-index: 9999;
    animation: slideUp 0.25s ease;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

.toast.success { background: var(--tago-green-700); }
.toast.error   { background: var(--tago-red-700); }
.toast.warning { background: var(--tago-yellow); color: var(--tago-navy); }

/* ---------- DIVIDER ---------- */
.divider {
    height: 1px;
    background: var(--tago-gray-200);
    margin: var(--space-4) 0;
    border: none;
}

/* ---------- UTILITY ---------- */
.flex         { display: flex; }
.flex-col     { flex-direction: column; }
.flex-between { justify-content: space-between; }
.flex-center  { align-items: center; justify-content: center; }
.flex-wrap    { flex-wrap: wrap; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.flex-1 { flex: 1; }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.p-4  { padding: var(--space-4); }
.hidden { display: none !important; }
.w-full { width: 100%; }

/* ---------- RESPONSIVE ---------- */
@media (min-width: 768px) {
    body { font-size: 16px; }
    .page { max-width: 720px; }
    .stat-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 1024px) {
    .page { max-width: 960px; }
}