:root {
    --bg: #f2f2f7;
    --bg-elevated: #ffffff;
    --bg-grouped: #f2f2f7;
    --bg-glass: rgba(255, 255, 255, 0.72);
    --bg-glass-thick: rgba(255, 255, 255, 0.92);
    --fill: rgba(120, 120, 128, 0.2);
    --fill-secondary: rgba(120, 120, 128, 0.16);
    --separator: rgba(60, 60, 67, 0.12);
    --label: #000000;
    --label-secondary: rgba(60, 60, 67, 0.6);
    --label-tertiary: rgba(60, 60, 67, 0.3);
    --accent: #007aff;
    --accent-light: rgba(0, 122, 255, 0.12);
    --green: #34c759;
    --green-light: rgba(52, 199, 89, 0.12);
    --red: #ff3b30;
    --red-light: rgba(255, 59, 48, 0.12);
    --orange: #ff9500;
    --orange-light: rgba(255, 149, 0, 0.12);
    --yellow: #ffcc00;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.12), 0 2px 10px rgba(0, 0, 0, 0.06);
    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 10px;
    --radius-xs: 8px;
    --ease: cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --spring: cubic-bezier(0.175, 0.885, 0.32, 1.1);
    --tab-height: 80px;
    --header-height: 56px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html { height: 100%; }

body {
    font-family: -apple-system, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', system-ui, sans-serif;
    background: var(--bg);
    color: var(--label);
    min-height: 100%;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 430px;
    margin: 0 auto;
    position: relative;
}

/* Header */
#header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-glass-thick);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    padding: 0 20px;
    height: var(--header-height);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
}

#page-title {
    font-size: 34px;
    font-weight: 700;
    letter-spacing: 0.37px;
    color: var(--label);
}

.status-badge {
    font-size: 12px;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 16px;
    letter-spacing: -0.08px;
    background: var(--green-light);
    color: var(--green);
}

.status-badge.inactive { background: var(--red-light); color: var(--red); }

/* Main Content */
#content {
    flex: 1;
    padding: 8px 20px 20px;
    padding-bottom: calc(var(--tab-height) + 16px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.page {
    display: none;
    animation: fadeSlideIn 0.35s var(--ease);
}

.page.active { display: block; }

@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Tab Bar */
#tab-bar {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 430px;
    height: var(--tab-height);
    background: var(--bg-glass-thick);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-top: 0.5px solid var(--separator);
    display: flex;
    align-items: flex-start;
    justify-content: space-around;
    padding: 6px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 12px);
    z-index: 100;
}

.tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--label-tertiary);
    cursor: pointer;
    padding: 6px 8px 0;
    border-radius: var(--radius-sm);
    transition: color 0.2s var(--ease);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.07px;
    flex: 1;
}

.tab-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
}

.tab svg {
    width: 22px;
    height: 22px;
    stroke-width: 1.6;
    transition: transform 0.3s var(--spring);
}

.tab.active { color: var(--accent); }
.tab.active svg { transform: scale(1.05); }
.tab:active { transform: scale(0.9); }

/* Cards */
.card {
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.card:active {
    transform: scale(0.98);
    box-shadow: var(--shadow-md);
}

.card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--label-secondary);
    text-transform: uppercase;
    letter-spacing: -0.08px;
    margin-bottom: 12px;
    padding-left: 4px;
}

/* Order Card */
.order-card {
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}

.order-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent), var(--green));
}

.order-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 18px;
    padding: 5px 12px;
    border-radius: 20px;
    letter-spacing: -0.08px;
}

.order-status.active, .order-status.performing { background: var(--orange-light); color: var(--orange); }
.order-status.completed, .order-status.complete { background: var(--green-light); color: var(--green); }
.order-status.cancelled { background: var(--red-light); color: var(--red); }

.order-status .pulse {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse 2s var(--ease) infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.85); }
}

.order-route {
    display: flex;
    align-items: stretch;
    gap: 14px;
    margin-bottom: 20px;
}

.route-dots {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding: 6px 0;
}

.route-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
    box-shadow: 0 0 0 3px var(--accent-light);
}

.route-line {
    width: 1.5px;
    flex: 1;
    background: var(--fill-secondary);
    min-height: 28px;
    margin: 4px 0;
}

.route-dot.end {
    background: var(--red);
    box-shadow: 0 0 0 3px var(--red-light);
}

.route-addresses {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 14px;
}

.route-point {
    font-size: 15px;
    font-weight: 500;
    line-height: 1.35;
    letter-spacing: -0.24px;
}

.route-point .label {
    font-size: 12px;
    font-weight: 500;
    color: var(--label-secondary);
    text-transform: uppercase;
    letter-spacing: 0.07px;
    margin-bottom: 3px;
}

.order-price {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    background: var(--bg-grouped);
    border-radius: var(--radius-md);
    margin-bottom: 18px;
}

.price-label {
    font-size: 15px;
    font-weight: 500;
    color: var(--label-secondary);
}

.price-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--label);
    letter-spacing: 0.37px;
}

.price-value .currency {
    font-size: 18px;
    font-weight: 500;
    color: var(--label-secondary);
}

/* Buttons */
.btn-group {
    display: flex;
    gap: 10px;
}

.btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 14px 20px;
    border-radius: var(--radius-md);
    border: none;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.41px;
    cursor: pointer;
    transition: transform 0.2s var(--spring), opacity 0.2s var(--ease);
    position: relative;
    overflow: hidden;
}

.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.15);
    opacity: 0;
    transition: opacity 0.2s;
}

.btn:active { transform: scale(0.96); }
.btn:active::after { opacity: 1; }

.btn-primary {
    background: var(--green);
    color: white;
    box-shadow: 0 2px 8px rgba(52, 199, 89, 0.3);
}

.btn-danger {
    background: var(--red);
    color: white;
    box-shadow: 0 2px 8px rgba(255, 59, 48, 0.3);
}

.btn-outline {
    background: var(--fill);
    color: var(--label);
    box-shadow: none;
}
.btn-outline::after { display: none; }

.btn-accent {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

.btn-full { width: 100%; }

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 64px 20px;
    text-align: center;
}

.empty-state svg {
    width: 56px;
    height: 56px;
    color: var(--label-tertiary);
    margin-bottom: 16px;
    opacity: 0.6;
}

.empty-state h3 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--label);
    letter-spacing: 0.38px;
}

.empty-state p {
    font-size: 15px;
    color: var(--label-secondary);
    letter-spacing: -0.24px;
}

/* Stats */
.date-filter {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    padding: 4px;
    box-shadow: var(--shadow-sm);
}

.date-btn {
    flex: 1;
    padding: 8px 0;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--label-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s var(--ease);
}

.date-btn.active {
    background: var(--accent);
    color: white;
}

.clickable { cursor: pointer; }
.selected { background: var(--accent-light) !important; }

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    padding: 18px 16px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.stat-value {
    font-size: 34px;
    font-weight: 700;
    color: var(--label);
    margin-bottom: 2px;
    letter-spacing: 0.37px;
}

.stat-value.accent { color: var(--accent); }
.stat-value.success { color: var(--green); }

.stat-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--label-secondary);
    text-transform: uppercase;
    letter-spacing: 0.07px;
}

.stat-card.wide {
    grid-column: 1 / -1;
    background: linear-gradient(135deg, var(--accent) 0%, #5856d6 100%);
    box-shadow: 0 4px 16px rgba(0, 122, 255, 0.3);
}

.stat-card.wide .stat-value {
    font-size: 48px;
    color: white;
}

.stat-card.wide .stat-label {
    color: rgba(255, 255, 255, 0.7);
}

/* Settings */
.settings-group {
    margin-bottom: 24px;
}

.settings-group-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--label-secondary);
    text-transform: uppercase;
    letter-spacing: -0.08px;
    margin-bottom: 8px;
    padding-left: 20px;
}

.setting-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--bg-elevated);
    margin-bottom: 0.5px;
    cursor: pointer;
    transition: background 0.15s var(--ease);
}

.setting-item:first-of-type { border-radius: var(--radius-md) var(--radius-md) 0 0; }
.setting-item:last-of-type { border-radius: 0 0 var(--radius-md) var(--radius-md); margin-bottom: 0; }
.setting-item:only-of-type { border-radius: var(--radius-md); }
.setting-item:active { background: var(--fill-secondary); }

.setting-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.setting-icon {
    width: 30px;
    height: 30px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.setting-icon.yellow { background: var(--orange-light); }
.setting-icon.blue { background: var(--accent-light); }
.setting-icon.green { background: var(--green-light); }
.setting-icon.red { background: var(--red-light); }

.setting-text h4 {
    font-size: 17px;
    font-weight: 400;
    letter-spacing: -0.41px;
}

.setting-text p {
    font-size: 13px;
    color: var(--label-secondary);
    letter-spacing: -0.08px;
}

/* iOS Toggle */
.toggle {
    position: relative;
    width: 51px;
    height: 31px;
    background: var(--fill);
    border-radius: 16px;
    cursor: pointer;
    transition: background 0.25s var(--ease);
    border: none;
    padding: 0;
    flex-shrink: 0;
}

.toggle.active { background: var(--green); }

.toggle::after {
    content: '';
    position: absolute;
    width: 27px;
    height: 27px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.25s var(--spring);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15), 0 1px 1px rgba(0, 0, 0, 0.1);
}

.toggle.active::after { transform: translateX(20px); }

/* Orders list */
.order-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: var(--bg-elevated);
    margin-bottom: 0.5px;
    transition: background 0.15s var(--ease);
}

.order-item:first-child { border-radius: var(--radius-md) var(--radius-md) 0 0; }
.order-item:last-child { border-radius: 0 0 var(--radius-md) var(--radius-md); margin-bottom: 0; }
.order-item:only-child { border-radius: var(--radius-md); }
.order-item:active { background: var(--fill-secondary); }

.order-item-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.order-item-icon.completed { background: var(--green-light); }
.order-item-icon.cancelled { background: var(--red-light); }

.order-item-info {
    flex: 1;
    min-width: 0;
}

.order-item-info h4 {
    font-size: 17px;
    font-weight: 400;
    letter-spacing: -0.41px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.order-item-info p {
    font-size: 13px;
    color: var(--label-secondary);
    letter-spacing: -0.08px;
}

.order-item-price {
    font-size: 17px;
    font-weight: 400;
    color: var(--label);
    flex-shrink: 0;
    letter-spacing: -0.41px;
}

/* Support */
.support-card {
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    padding: 32px 24px;
    text-align: center;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

.support-card svg {
    width: 44px;
    height: 44px;
    color: var(--accent);
    margin-bottom: 14px;
    opacity: 0.9;
}

.support-card h3 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 6px;
    letter-spacing: 0.38px;
}

.support-card p {
    font-size: 15px;
    color: var(--label-secondary);
    margin-bottom: 20px;
    line-height: 1.4;
    letter-spacing: -0.24px;
}

.faq-item {
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    padding: 16px 18px;
    margin-bottom: 8px;
    box-shadow: var(--shadow-sm);
}

.faq-item h4 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--accent);
    letter-spacing: -0.24px;
}

.faq-item p {
    font-size: 15px;
    color: var(--label-secondary);
    line-height: 1.47;
    letter-spacing: -0.24px;
}

/* Driver info */
.driver-info {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 18px 20px;
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

.driver-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent) 0%, #5856d6 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.25);
}

.driver-details h3 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 2px;
    letter-spacing: 0.38px;
}

.driver-details p {
    font-size: 15px;
    color: var(--label-secondary);
    letter-spacing: -0.24px;
}

/* Loading */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
}

.spinner {
    width: 28px;
    height: 28px;
    border: 2.5px solid var(--fill);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: var(--bg-glass-thick);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    color: var(--label);
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 500;
    z-index: 1000;
    transition: transform 0.4s var(--spring);
    box-shadow: var(--shadow-lg);
    letter-spacing: -0.24px;
}

.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.32);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s var(--ease);
}

.modal-overlay.show { opacity: 1; pointer-events: all; }

.modal {
    background: var(--bg-glass-thick);
    -webkit-backdrop-filter: saturate(180%) blur(40px);
    backdrop-filter: saturate(180%) blur(40px);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    width: 100%;
    max-width: 430px;
    padding: 8px 24px 32px;
    transform: translateY(100%);
    transition: transform 0.35s var(--spring);
}

.modal-overlay.show .modal { transform: translateY(0); }

.modal-handle {
    width: 36px;
    height: 5px;
    background: var(--fill);
    border-radius: 3px;
    margin: 0 auto 20px;
}

.modal h3 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
    text-align: center;
    letter-spacing: 0.38px;
}

.modal p {
    font-size: 15px;
    color: var(--label-secondary);
    margin-bottom: 24px;
    line-height: 1.47;
    text-align: center;
    letter-spacing: -0.24px;
}

@media (max-width: 360px) {
    .stats-grid { grid-template-columns: 1fr; }
    .stat-card.wide .stat-value { font-size: 38px; }
}

/* Dark theme */
.tg-theme-dark,
body.dark {
    --bg: #000000;
    --bg-elevated: #1c1c1e;
    --bg-grouped: #000000;
    --bg-glass: rgba(28, 28, 30, 0.72);
    --bg-glass-thick: rgba(28, 28, 30, 0.92);
    --fill: rgba(120, 120, 128, 0.36);
    --fill-secondary: rgba(120, 120, 128, 0.32);
    --separator: rgba(84, 84, 88, 0.65);
    --label: #ffffff;
    --label-secondary: rgba(235, 235, 245, 0.6);
    --label-tertiary: rgba(235, 235, 245, 0.3);
    --accent: #0a84ff;
    --accent-light: rgba(10, 132, 255, 0.18);
    --green: #30d158;
    --green-light: rgba(48, 209, 88, 0.18);
    --red: #ff453a;
    --red-light: rgba(255, 69, 58, 0.18);
    --orange: #ff9f0a;
    --orange-light: rgba(255, 159, 10, 0.18);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.5);
}
