/* ============================================================
   Instapack GPS Tracker — Styles
   Colors: Primary #4AB8D8, Dark #2C3E50, Green #4CAF50,
           Red #E53935, Orange #FF9800, BG #F5F7FA
   ============================================================ */

:root {
    --primary: #4AB8D8;
    --primary-light: #E0F7FA;
    --dark: #2C3E50;
    --green: #4CAF50;
    --red: #E53935;
    --orange: #FF9800;
    --gray: #90A4AE;
    --bg: #F5F7FA;
    --white: #FFFFFF;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
    --radius-btn: 24px;
    --radius-card: 12px;
    --radius-input: 8px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, sans-serif;
    --transition: 200ms ease;
}

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

html, body {
    margin: 0;
    padding: 0;
    height: 100dvh;
    overflow: hidden;
}
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--dark);
    font-size: 14px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
}

/* ============ SCREENS ============ */
.screen {
    display: none;
    width: 100%;
    height: 100dvh;
    max-width: 480px;
    margin: 0 auto;
    overflow: hidden;
}
.screen.active {
    display: flex;
    flex-direction: column;
}
.screen.scrollable {
    overflow-y: auto;
}

/* ============ LOGIN SCREEN ============ */
.login-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    max-width: 400px;
    margin: 0 auto;
    width: 100%;
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}
.logo-img {
    width: 160px;
    height: auto;
    margin-bottom: 16px;
}
.login-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
}
.login-subtitle {
    font-size: 13px;
    color: var(--gray);
}

.login-form {
    width: 100%;
}
.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--gray);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #dce3e8;
    border-radius: var(--radius-input);
    font-size: 15px;
    font-family: var(--font);
    color: var(--dark);
    background: var(--white);
    transition: border-color var(--transition);
    outline: none;
}
.form-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(74, 184, 216, 0.15);
}
.form-group input::placeholder {
    color: #b0bec5;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 24px;
    font-size: 13px;
    color: var(--gray);
    cursor: pointer;
}
.checkbox-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

/* ============ ROLE SELECTOR ============ */
.role-buttons {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.btn-role {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 24px 16px;
    border-radius: var(--radius-card);
    border: 2px solid #dce3e8;
    background: var(--white);
    cursor: pointer;
    transition: all var(--transition);
    text-transform: none;
    letter-spacing: normal;
}
.btn-role:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}
.btn-role:active {
    transform: translateY(0);
}
.btn-role svg {
    color: var(--primary);
}
.role-label {
    font-size: 18px;
    font-weight: 700;
    color: var(--dark);
}
.role-desc {
    font-size: 12px;
    color: var(--gray);
    font-weight: 400;
}
.btn-role-driver:hover {
    border-color: var(--green);
}
.btn-role-driver:hover svg { color: var(--green); }
.btn-role-manager:hover {
    border-color: var(--primary);
}

.btn-back {
    margin-top: 16px;
    background: none;
    border: none;
    color: var(--gray);
    font-size: 13px;
    cursor: pointer;
    font-family: var(--font);
    text-decoration: underline;
    padding: 8px;
}

/* ============ BUTTONS ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    font-family: var(--font);
    font-weight: 700;
    transition: all var(--transition);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.btn:active {
    transform: scale(0.97);
}
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
    padding: 14px 32px;
    border-radius: var(--radius-btn);
    font-size: 15px;
    box-shadow: 0 2px 8px rgba(74, 184, 216, 0.3);
}
.btn-primary:hover:not(:disabled) {
    background: #3da8c8;
}

.btn-login {
    width: 100%;
    padding: 16px;
    font-size: 16px;
    margin-top: 8px;
}

.btn-track {
    width: 100%;
    padding: 18px;
    font-size: 16px;
    border-radius: var(--radius-btn);
    box-shadow: var(--shadow-lg);
}
.btn-start {
    background: var(--green);
    color: var(--white);
    box-shadow: 0 3px 12px rgba(76, 175, 80, 0.35);
}
.btn-start:hover:not(:disabled) {
    background: #43a047;
}
.btn-stop {
    background: var(--red);
    color: var(--white);
    box-shadow: 0 3px 12px rgba(229, 57, 53, 0.35);
}
.btn-stop:hover:not(:disabled) {
    background: #d32f2f;
}

.login-error {
    margin-top: 16px;
    padding: 12px 16px;
    background: #ffebee;
    border-left: 3px solid var(--red);
    border-radius: var(--radius-input);
    font-size: 13px;
    color: var(--red);
}

.login-footer {
    margin-top: 32px;
    font-size: 11px;
    color: var(--gray);
}

/* ============ APP HEADER ============ */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: var(--primary);
    color: var(--white);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 100;
}
.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}
.header-logo {
    height: 28px;
    width: auto;
    filter: brightness(0) invert(1);
}
.header-brand {
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 1px;
}
.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}
.header-device {
    font-size: 12px;
    font-weight: 600;
    opacity: 0.9;
}
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}
.status-dot.off {
    background: var(--gray);
}
.status-dot.on {
    background: #76ff03;
    box-shadow: 0 0 6px #76ff03;
    animation: pulse-dot 1.5s ease infinite;
}
@keyframes pulse-dot {
    0%, 100% { opacity: 1; box-shadow: 0 0 6px #76ff03; }
    50% { opacity: 0.7; box-shadow: 0 0 12px #76ff03; }
}
.status-text {
    font-size: 11px;
    font-weight: 700;
}

/* ============ MAP ============ */
.map-container {
    position: relative;
    flex: 1;
    min-height: 200px;
    overflow: hidden;
}
.map {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}
.btn-center {
    position: absolute;
    bottom: 12px;
    right: 12px;
    z-index: 500;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--white);
    border: none;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--dark);
    transition: all var(--transition);
}
.btn-center:active {
    background: var(--primary-light);
}

/* ============ INFO BAR ============ */
.info-bar {
    padding: 10px 16px;
    background: var(--white);
    border-bottom: 1px solid #e8edf1;
}
.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.info-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 700;
}
.gps-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--gray);
    display: inline-block;
}
.gps-dot.active {
    background: var(--green);
    box-shadow: 0 0 4px var(--green);
}
.gps-dot.error {
    background: var(--red);
}
.info-value {
    font-size: 12px;
    color: var(--gray);
    font-family: "SF Mono", "Fira Code", monospace;
}
.info-secondary {
    margin-top: 4px;
    font-size: 11px;
    color: var(--gray);
    gap: 12px;
}

/* ============ ACTION CONTAINER ============ */
.action-container {
    padding: 12px 16px;
    background: var(--white);
}

/* ============ STATS BAR ============ */
.stats-bar {
    padding: 12px 16px;
    background: var(--white);
    border-top: 1px solid #e8edf1;
}
.stat-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}
.stat-row:last-child {
    margin-bottom: 0;
}
.stat-item {
    flex: 1;
    text-align: center;
}
.stat-label {
    display: block;
    font-size: 10px;
    color: var(--gray);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 2px;
}
.stat-value {
    display: block;
    font-size: 14px;
    font-weight: 700;
    color: var(--dark);
}

/* ============ LOGOUT ============ */
.logout-row {
    padding: 8px 16px 16px;
    background: var(--white);
    text-align: center;
}
.btn-logout {
    background: var(--red);
    border: none;
    color: var(--white);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 10px 24px;
    font-family: var(--font);
    border-radius: var(--radius-btn);
}

/* ============ MANAGER HEADER ============ */
.manager-header {
    background: var(--dark);
}
.btn-header-logout {
    background: rgba(255,255,255,0.15);
    border: none;
    color: var(--white);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font);
}
.btn-header-logout:active {
    background: rgba(255,255,255,0.25);
}

/* ============ MANAGER DASHBOARD ============ */
.manager-drivers-section {
    flex: 1;
    background: var(--white);
    overflow-y: auto;
}

.manager-drivers-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid #e8edf1;
    position: sticky;
    top: 0;
    background: var(--white);
    z-index: 10;
}
.manager-drivers-header h3 {
    font-size: 14px;
    font-weight: 700;
    color: var(--dark);
}
.manager-count {
    background: var(--primary);
    color: var(--white);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
}
.manager-update-time {
    margin-left: auto;
    font-size: 11px;
    color: var(--gray);
}

.manager-driver-list {
    padding: 8px 16px;
}

.manager-loading {
    text-align: center;
    padding: 24px;
    color: var(--gray);
    font-size: 13px;
}

.driver-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius-card);
    border: 1px solid #e8edf1;
    margin-bottom: 8px;
    transition: all var(--transition);
}
.driver-card:active {
    background: var(--primary-light);
}

.driver-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.driver-status-dot.online {
    background: var(--green);
    box-shadow: 0 0 4px var(--green);
}
.driver-status-dot.offline {
    background: var(--gray);
}

.driver-info {
    flex: 1;
    min-width: 0;
}
.driver-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.driver-meta {
    font-size: 11px;
    color: var(--gray);
    margin-top: 2px;
}

.driver-speed {
    font-size: 12px;
    font-weight: 700;
    color: var(--dark);
    text-align: right;
    white-space: nowrap;
}
.driver-battery {
    font-size: 10px;
    color: var(--gray);
    text-align: right;
}

/* ============ INSTALL BANNER ============ */
.install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--dark);
    color: var(--white);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.2);
}
.btn-install {
    background: var(--primary);
    color: var(--white);
    padding: 8px 16px;
    border-radius: var(--radius-btn);
    font-size: 12px;
    white-space: nowrap;
}
.btn-dismiss {
    background: none;
    border: none;
    color: var(--gray);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    margin-left: auto;
}

/* ============ TOAST ============ */
.toast-container {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 90%;
    max-width: 380px;
    pointer-events: none;
}
.toast {
    padding: 12px 16px;
    border-radius: var(--radius-card);
    background: var(--white);
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--primary);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: toastSlide 0.3s ease;
    pointer-events: auto;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.warning { border-left-color: var(--orange); }
.toast-icon { font-size: 16px; flex-shrink: 0; }
@keyframes toastSlide {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
@keyframes toastFade {
    from { opacity: 1; }
    to { opacity: 0; transform: translateY(-10px); }
}

/* ============ MODAL ============ */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.modal-content {
    background: var(--white);
    border-radius: var(--radius-card);
    padding: 24px;
    max-width: 360px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-lg);
}
.modal-content h3 {
    font-size: 16px;
    margin-bottom: 12px;
    color: var(--dark);
}
.modal-content p {
    font-size: 13px;
    color: var(--gray);
    margin-bottom: 20px;
    line-height: 1.6;
}

/* ============ OFFLINE BANNER ============ */
.offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1500;
    background: var(--orange);
    color: var(--white);
    text-align: center;
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 600;
}

/* ============ SPINNER ============ */
.spinner-inline {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: var(--white);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ RESPONSIVE ============ */
@media (max-width: 480px) {
    .map-container {
        min-height: 35vh;
    }
}
@media (min-width: 481px) {
    .screen {
        box-shadow: var(--shadow-lg);
    }
    #screen-login, #screen-role, #screen-manager-login {
        background: linear-gradient(135deg, var(--primary-light) 0%, var(--bg) 100%);
    }
}

/* Leaflet overrides */
.leaflet-control-attribution {
    font-size: 9px !important;
}
