:root {
    --bg-primary: #000000;
    --bg-secondary: #1c1c1e;
    --bg-tertiary: #2c2c2e;
    --bg-card: rgba(44, 44, 46, 0.8);
    --bg-glass: rgba(255, 255, 255, 0.06);
    --bg-input: rgba(118, 118, 128, 0.24);
    --text-primary: #ffffff;
    --text-secondary: rgba(235, 235, 245, 0.6);
    --text-muted: rgba(235, 235, 245, 0.3);
    --accent: #0a84ff;
    --accent-hover: #409cff;
    --success: #30d158;
    --danger: #ff453a;
    --warning: #ffd60a;
    --orange: #ff9f0a;
    --border: rgba(255, 255, 255, 0.08);
    --separator: rgba(84, 84, 88, 0.65);
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 22px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background: var(--bg-primary) url('/static/NMS.png') no-repeat center center fixed;
    background-size: cover;
    color: var(--text-primary);
    font-family: -apple-system, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', system-ui, sans-serif;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── Navbar (iOS nav bar) ── */
.navbar {
    background: rgba(28, 28, 30, 0.72) !important;
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 0.5px solid var(--separator);
    padding: 0.6rem 1.25rem;
    position: sticky;
    top: 0;
    z-index: 100;
}
.navbar-brand {
    color: var(--text-primary) !important;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.02em;
}
.navbar-brand i { color: var(--accent); }

/* ── iOS Buttons ── */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.8rem;
    letter-spacing: -0.01em;
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    border: none;
}
.btn:active { transform: scale(0.96); opacity: 0.85; }

.btn-accent {
    background: var(--accent);
    color: #fff;
    border-radius: var(--radius-sm);
    font-weight: 600;
}
.btn-accent:hover { background: var(--accent-hover); color: #fff; }

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-primary);
    border: none;
}
.btn-secondary:hover { background: rgba(118, 118, 128, 0.36); color: var(--text-primary); }

.btn-outline-secondary {
    color: var(--accent);
    border: none;
    background: transparent;
    font-weight: 500;
}
.btn-outline-secondary:hover { background: var(--bg-glass); color: var(--accent-hover); }

/* iOS-style action buttons */
.ios-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 1rem;
}
.ios-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 8px;
    border-radius: var(--radius-md);
    border: none;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.ios-action-btn:active { transform: scale(0.95); }
.ios-action-btn i { font-size: 1.2rem; }
.ios-action-btn.act-start { background: rgba(48, 209, 88, 0.15); color: var(--success); }
.ios-action-btn.act-start:hover { background: rgba(48, 209, 88, 0.25); }
.ios-action-btn.act-stop { background: rgba(255, 69, 58, 0.15); color: var(--danger); }
.ios-action-btn.act-stop:hover { background: rgba(255, 69, 58, 0.25); }
.ios-action-btn.act-restart { background: rgba(10, 132, 255, 0.15); color: var(--accent); }
.ios-action-btn.act-restart:hover { background: rgba(10, 132, 255, 0.25); }
.ios-action-btn.act-wait { background: rgba(255, 159, 10, 0.15); color: var(--orange); }
.ios-action-btn.act-wait:hover { background: rgba(255, 159, 10, 0.25); }

/* ── iOS Cards (grouped style) ── */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    border: 0.5px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 1.25rem;
    color: var(--text-primary);
    transition: transform 0.2s ease;
}
.card-title {
    color: var(--text-primary);
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.02em;
}

/* ── Status badges (iOS pills) ── */
.status-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 100px;
    letter-spacing: -0.01em;
}
.badge-running { background: rgba(48, 209, 88, 0.18); color: var(--success) !important; }
.badge-waiting { background: rgba(255, 214, 10, 0.18); color: var(--warning) !important; }
.badge-stopped { background: rgba(255, 69, 58, 0.18); color: var(--danger) !important; }
.badge-unknown { background: var(--bg-input); color: var(--text-secondary) !important; }

/* Status dot pulse */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}
.status-dot.dot-running { background: var(--success); box-shadow: 0 0 6px var(--success); animation: pulse 2s infinite; }
.status-dot.dot-stopped { background: var(--danger); }
.status-dot.dot-waiting { background: var(--warning); animation: pulse 2s infinite; }
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ── iOS Forms ── */
.form-control, .form-select {
    background: var(--bg-input);
    border: none;
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    padding: 8px 12px;
}
.form-control:focus, .form-select:focus {
    background: rgba(118, 118, 128, 0.36);
    border: none;
    color: var(--text-primary);
    box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.3);
}
.form-control::placeholder { color: var(--text-muted); }
.form-label {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    margin-bottom: 4px;
}
.form-select option { background: var(--bg-tertiary); color: var(--text-primary); }

/* ── iOS Grouped List (accordion) ── */
.accordion-item {
    background: transparent;
    border: none;
}
.accordion-item + .accordion-item {
    border-top: 0.5px solid var(--separator);
}
.accordion-button {
    background: transparent;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 12px 0;
    box-shadow: none !important;
    letter-spacing: -0.01em;
}
.accordion-button i { color: var(--text-secondary); }
.accordion-button:not(.collapsed) { color: var(--accent); background: transparent; }
.accordion-button:not(.collapsed) i { color: var(--accent); }
.accordion-button::after {
    filter: invert(1);
    width: 14px;
    height: 14px;
    background-size: 14px;
}
.accordion-body { padding: 0 0 12px; }
.accordion-collapse { background: transparent; }

/* iOS section header */
.ios-section-header {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0 0 6px;
}

/* ── Log viewer (iOS terminal) ── */
.log-viewer {
    background: rgba(0, 0, 0, 0.6);
    color: #98d8a0;
    font-family: 'SF Mono', 'Menlo', 'Monaco', 'Cascadia Code', monospace;
    font-size: 0.72rem;
    line-height: 1.5;
    padding: 12px;
    margin: 0;
    max-height: 350px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    letter-spacing: -0.01em;
}

/* Log tabs */
.log-tabs {
    display: flex;
    background: rgba(118, 118, 128, 0.12);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    padding: 3px;
    gap: 2px;
}
.log-tab {
    flex: 1;
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 5px 8px;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s;
}
.log-tab.active {
    background: var(--bg-tertiary);
    color: var(--text-primary) !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.log-tab:hover:not(.active) { color: var(--text-primary); }
.log-tab-refresh {
    width: 32px;
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    background: transparent;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}
.log-tab-refresh:hover { color: var(--accent); background: var(--bg-glass); }

/* ── Fleet & Account lists (iOS grouped rows) ── */
.ios-list {
    max-height: 250px;
    overflow-y: auto;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
}
.ios-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    font-size: 0.82rem;
    transition: background 0.15s;
}
.ios-list-item + .ios-list-item {
    border-top: 0.5px solid var(--separator);
}
.ios-list-item:hover { background: var(--bg-glass); }
.ios-list-item-text {
    flex: 1;
    min-width: 0;
}
.ios-list-item-title {
    font-weight: 600;
    color: var(--text-primary);
}
.ios-list-item-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ios-list-item-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
.ios-icon-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.15s;
}
.ios-icon-btn:active { transform: scale(0.9); }
.ios-icon-btn.edit { background: rgba(10, 132, 255, 0.15); color: var(--accent); }
.ios-icon-btn.edit:hover { background: rgba(10, 132, 255, 0.3); }
.ios-icon-btn.delete { background: rgba(255, 69, 58, 0.15); color: var(--danger); }
.ios-icon-btn.delete:hover { background: rgba(255, 69, 58, 0.3); }
.ios-icon-btn.save { background: rgba(48, 209, 88, 0.15); color: var(--success); }
.ios-icon-btn.save:hover { background: rgba(48, 209, 88, 0.3); }
.ios-icon-btn.cancel { background: var(--bg-input); color: var(--text-secondary); }
.ios-icon-btn.cancel:hover { background: rgba(118, 118, 128, 0.36); }

/* Inline edit row */
.ios-edit-row {
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 8px 12px;
    background: rgba(10, 132, 255, 0.06);
    border-top: 0.5px solid var(--separator);
}
.ios-edit-row input {
    flex: 1;
    min-width: 0;
}

/* ── Toast (iOS notification) ── */
.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 9999; }
.alert {
    background: var(--bg-card) !important;
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    color: var(--text-primary) !important;
    border: 0.5px solid var(--separator) !important;
    border-radius: var(--radius-md) !important;
    font-size: 0.85rem;
    font-weight: 500;
}
.alert-danger { border-left: 3px solid var(--danger) !important; }
.alert-success { border-left: 3px solid var(--success) !important; }
.btn-close { filter: invert(1) brightness(0.8); }

/* ── Info row ── */
.info-row { font-size: 0.78rem; color: var(--text-secondary); }
.info-row small {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-right: 12px;
    margin-bottom: 2px;
}

/* ── App logos ── */
.app-logo {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    flex-shrink: 0;
}

/* ── Misc ── */
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
h1,h2,h3,h4,h5,h6 { color: var(--text-primary); letter-spacing: -0.02em; }
hr { border-color: var(--separator); opacity: 0.5; }
.text-muted { color: var(--text-secondary) !important; }

/* ── Scrollbar (thin, iOS-like) ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.15) transparent; }

/* ── iOS Search bar ── */
.ios-search-wrap {
    position: relative;
}
.ios-search-wrap > i {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.75rem;
    pointer-events: none;
    z-index: 1;
}
.ios-search {
    padding-left: 30px !important;
    background: var(--bg-glass) !important;
    border-radius: 10px !important;
    font-size: 0.82rem !important;
}
.ios-search:focus {
    background: var(--bg-input) !important;
}

/* Hide filtered items */
.ios-list-item.filtered-out {
    display: none !important;
}
.acc-group-header.filtered-out {
    display: none !important;
}
.ios-list.filtered-out {
    display: none !important;
}

/* ── iOS add form ── */
.ios-add-form {
    display: flex;
    gap: 6px;
    padding-top: 8px;
}
.ios-add-form input {
    flex: 1;
    min-width: 0;
}

/* ── Account group header ── */
.acc-group-header {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 10px 12px 4px;
}

/* ── Responsive ── */
@media (max-width: 767px) {
    .card { padding: 1rem; border-radius: var(--radius-lg); }
    .ios-actions { grid-template-columns: 1fr 1fr; gap: 6px; }
    .ios-action-btn { padding: 8px 6px; font-size: 0.65rem; }
    .ios-action-btn i { font-size: 1rem; }
}
@media (max-width: 576px) {
    .row.g-4 { --bs-gutter-x: 0.5rem; }
    .px-3 { padding-left: 0.5rem !important; padding-right: 0.5rem !important; }
}

/* ── Navbar user info ── */
.nav-user-info {
    display: flex;
    align-items: center;
    gap: 8px;
}
.nav-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1.5px solid var(--separator);
}
.nav-email {
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 500;
    letter-spacing: -0.01em;
}
@media (max-width: 576px) {
    .nav-email { display: none; }
}

/* ── Google sign-in button ── */
.google-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 12px 16px;
    background: #fff;
    color: #3c4043;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
}
.google-btn:hover {
    background: #f7f8f8;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    color: #3c4043;
    text-decoration: none;
}
.google-btn:active { transform: scale(0.98); }

/* Run Modal */
.run-check {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    cursor: pointer;
    user-select: none;
}
.run-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}
.run-firm-btn.active, .run-city-mode.active {
    background: var(--accent) !important;
    color: #fff !important;
    border-color: var(--accent) !important;
}
#runModal .modal-content {
    color: var(--text-primary);
    background: var(--bg-secondary) !important;
    border: 1px solid var(--separator) !important;
}
#runModal .modal-backdrop, .modal-backdrop {
    background: rgba(0,0,0,0.85) !important;
    opacity: 1 !important;
}
#runModal .form-label { color: var(--text-secondary); }
