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

:root {
    --bg-1: #667eea;
    --bg-2: #764ba2;
    --accent: #5b3da8;
    --action-bar-h: 84px;
}

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
    background: linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 100%);
    background-attachment: fixed;
    min-height: 100vh;
    min-height: 100dvh;
    color: #2b2b35;
}

.app {
    max-width: 540px;
    margin: 0 auto;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    position: sticky;
    top: 0;
    z-index: 50;
    padding: calc(env(safe-area-inset-top) + 16px) 16px 16px;
    background: linear-gradient(160deg, rgba(102,126,234,0.96), rgba(118,75,162,0.96));
    backdrop-filter: blur(8px);
}

.app-header-inner {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ferry-icon {
    font-size: 2rem;
    line-height: 1;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.title {
    font-size: 1.6rem;
    color: #fff;
    font-weight: 800;
    letter-spacing: -0.02em;
    text-shadow: 0 2px 6px rgba(0,0,0,0.25);
}

.subtitle {
    color: rgba(255,255,255,0.82);
    font-size: 0.85rem;
    margin-top: 2px;
}

/* Content */
.content {
    flex: 1;
    padding: 16px 16px calc(var(--action-bar-h) + env(safe-area-inset-bottom) + 16px);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.card {
    background: #fff;
    padding: 18px;
    border-radius: 18px;
    box-shadow: 0 8px 26px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.field { display: flex; flex-direction: column; }

.field label {
    font-weight: 600;
    color: #555;
    font-size: 0.85rem;
    margin-bottom: 7px;
}

.field input,
.field select {
    width: 100%;
    padding: 14px;
    border: 2px solid #e6e8ef;
    border-radius: 12px;
    font-size: 16px; /* >=16px prevents iOS zoom-on-focus */
    background: #fff;
    color: #2b2b35;
    transition: border-color 0.2s ease;
    appearance: none;
    -webkit-appearance: none;
}

.field select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='8' viewBox='0 0 14 8'%3E%3Cpath fill='%23888' d='M1 1l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    padding-right: 40px;
}

.field input:focus,
.field select:focus {
    outline: none;
    border-color: var(--bg-1);
}

.field-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* Segmented control (vehicle type) */
.segmented {
    display: flex;
    background: #eef0f6;
    border-radius: 12px;
    padding: 4px;
    gap: 4px;
}

.seg {
    flex: 1;
    border: none;
    background: transparent;
    padding: 12px;
    border-radius: 9px;
    font-size: 0.95rem;
    font-weight: 600;
    color: #666;
    cursor: pointer;
    transition: all 0.2s ease;
}

.seg.active {
    background: #fff;
    color: var(--accent);
    box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}

/* Toggle switch */
.switch {
    position: relative;
    display: inline-block;
    width: 58px;
    height: 32px;
    margin-top: 2px;
}

.switch input { display: none; }

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #ccc;
    border-radius: 32px;
    transition: 0.3s;
}

.slider::before {
    content: "";
    position: absolute;
    height: 26px;
    width: 26px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: 0.3s;
}

.switch input:checked + .slider { background: var(--bg-1); }
.switch input:checked + .slider::before { transform: translateX(26px); }

/* Status banner */
.status {
    display: flex;
    align-items: center;
    gap: 14px;
    background: #fff;
    padding: 16px 18px;
    border-radius: 16px;
    box-shadow: 0 8px 26px rgba(0,0,0,0.18);
}

.spinner {
    width: 30px;
    height: 30px;
    border: 4px solid #eef0f6;
    border-top: 4px solid var(--bg-1);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    flex-shrink: 0;
}

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

.status p { font-size: 0.9rem; color: #555; font-weight: 500; }

/* Results */
.results {
    background: #fff;
    padding: 18px;
    border-radius: 18px;
    box-shadow: 0 8px 26px rgba(0,0,0,0.18);
}

.results h3 { font-size: 1.1rem; margin-bottom: 14px; color: #2b2b35; }

.history { display: flex; flex-direction: column; gap: 10px; }

.history:empty::after {
    content: "No checks yet. Tap Start monitoring.";
    color: #999;
    font-size: 0.9rem;
}

.history-item {
    padding: 14px;
    border-radius: 12px;
    border-left: 4px solid;
    background: #f6f7fa;
}

.history-item.available { border-left-color: #28a745; background: #e3f6e9; }
.history-item.not-available { border-left-color: #dc3545; background: #fae3e6; }
.history-item.error { border-left-color: #ffc107; background: #fff5d6; }

.history-item .message { font-weight: 600; font-size: 0.92rem; line-height: 1.4; }
.history-item.available .message { color: #156a2c; }
.history-item.not-available .message { color: #9c1f2b; }
.history-item.error .message { color: #856404; }

.history-item .timestamp { font-size: 0.78rem; color: #777; margin-top: 5px; }

.ticket-details {
    margin-top: 10px;
    padding: 8px 10px;
    background: rgba(255,255,255,0.75);
    border-radius: 8px;
}

.ticket {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid rgba(0,0,0,0.06);
}

.ticket:last-child { border-bottom: none; }
.ticket-time { font-weight: 600; color: #156a2c; font-size: 0.88rem; }

.ticket-count {
    background: #28a745;
    color: #fff;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
}

/* Sticky action bar */
.action-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(10px);
    box-shadow: 0 -4px 20px rgba(0,0,0,0.12);
}

.action-bar .scan-btn,
.action-bar .stop-btn {
    display: block;
    width: 100%;
    max-width: 540px;
    margin: 0 auto;
    padding: 16px;
    border: none;
    border-radius: 14px;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    color: #fff;
    transition: transform 0.15s ease, filter 0.15s ease;
}

.scan-btn { background: linear-gradient(135deg, var(--bg-1), var(--bg-2)); }
.stop-btn { background: linear-gradient(135deg, #ff6b6b, #ee5a24); }
.action-bar button:active { transform: scale(0.98); filter: brightness(0.95); }

/* matagi badge - sits above the action bar */
.matagi-badge {
    position: fixed;
    right: 14px;
    bottom: calc(var(--action-bar-h) + env(safe-area-inset-bottom) + 14px);
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 13px;
    background: rgba(0,0,0,0.62);
    color: #fff;
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    border-radius: 999px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
    backdrop-filter: blur(4px);
    z-index: 65;
    transition: transform 0.2s ease;
}

.matagi-badge:active { transform: scale(0.96); }
.matagi-badge img { height: 15px; width: auto; display: block; }

/* Larger screens: relax the app-like full-bleed look slightly */
@media (min-width: 560px) {
    .app { padding: 24px 0; }
    .app-header { border-radius: 18px 18px 0 0; }
    .action-bar {
        position: sticky;
        border-radius: 0 0 18px 18px;
        box-shadow: 0 6px 20px rgba(0,0,0,0.15);
    }
    .matagi-badge { bottom: 18px; }
}
