:root {
    color-scheme: dark;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display",
                 "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: #090b0f;
    color: #f5f7fa;
}

main {
    width: min(100% - 32px, 1100px);
    margin: 0 auto;
    padding: 48px 0 80px;
}

header {
    margin-bottom: 40px;
}

.eyebrow {
    margin: 0 0 8px;
    color: #60a5fa;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.14em;
}

h1 {
    margin: 0;
    font-size: clamp(36px, 6vw, 58px);
    letter-spacing: -0.04em;
}

.subtitle {
    margin: 8px 0 0;
    color: #8b949e;
    font-size: 17px;
}

.panel {
    margin-bottom: 24px;
    padding: 24px;
    background: #12151a;
    border: 1px solid #252a32;
    border-radius: 20px;
}

.panel-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 22px;
}

.panel h2 {
    margin: 0;
    font-size: 20px;
}

.date {
    color: #8b949e;
    font-size: 14px;
}

.route-number {
    margin-bottom: 24px;
}

.route-label {
    display: block;
    color: #8b949e;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.1em;
}

.route-value {
    font-size: 42px;
    font-weight: 750;
    letter-spacing: -0.04em;
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

.stat {
    padding: 18px;
    background: #0c0f13;
    border: 1px solid #20252d;
    border-radius: 15px;
}

.stat-label {
    display: block;
    margin-bottom: 5px;
    color: #8b949e;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
}

form {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 18px;
}

label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    color: #aab2bd;
    font-size: 13px;
    font-weight: 600;
}

input {
    width: 100%;
    padding: 13px 14px;
    background: #0c0f13;
    border: 1px solid #2b313a;
    border-radius: 11px;
    color: #f5f7fa;
    font: inherit;
    font-size: 16px;
    outline: none;
}

input:focus {
    border-color: #3b82f6;
}

button {
    min-height: 48px;
    align-self: end;
    border: 0;
    border-radius: 11px;
    background: #2563eb;
    color: white;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

button:hover {
    background: #3b82f6;
}

@media (max-width: 650px) {
    main {
        width: min(100% - 24px, 1100px);
        padding-top: 28px;
    }

    .panel {
        padding: 18px;
    }

    .stats {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .stat {
        padding: 14px 10px;
    }

    .stat-value {
        font-size: 23px;
    }

    form {
        grid-template-columns: 1fr;
    }
}

.timeline {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin-top: 18px;
}

.timeline-item {
    padding: 14px;
    background: #0c0f13;
    border: 1px solid #20252d;
    border-radius: 13px;
}

.timeline-label {
    display: block;
    margin-bottom: 6px;
    color: #8b949e;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.07em;
}

.timeline-time {
    font-size: 19px;
    font-weight: 700;
}

@media (max-width: 650px) {
    .timeline {
        grid-template-columns: 1fr;
    }

    .timeline-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .timeline-label {
        margin-bottom: 0;
    }
}

.event-actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 14px;
}

.event-button {
    min-height: 44px;
    padding: 10px;
    background: #1b2028;
    border: 1px solid #303743;
    color: #d7dde5;
    font-size: 13px;
}

.event-button:hover {
    background: #252c36;
    border-color: #3b82f6;
}

.event-button:disabled {
    opacity: 0.55;
    cursor: default;
}

@media (max-width: 650px) {
    .event-actions {
        grid-template-columns: repeat(2, 1fr);
    }
}

.duration-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #252a32;
}

.duration-card {
    padding: 16px;
    background: #0c0f13;
    border: 1px solid #20252d;
    border-radius: 13px;
}

.duration-label {
    display: block;
    margin-bottom: 6px;
    color: #8b949e;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.07em;
}

.duration-value {
    font-size: 21px;
    font-weight: 700;
}

@media (max-width: 650px) {
    .duration-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.health-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #252a32;
}

.health-heading {
    margin-bottom: 12px;
    color: #8b949e;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.1em;
}

.health-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.health-card {
    padding: 16px;
    background: #0c0f13;
    border: 1px solid #20252d;
    border-radius: 13px;
}

.health-label {
    display: block;
    margin-bottom: 6px;
    color: #8b949e;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.07em;
}

.health-value {
    font-size: 21px;
    font-weight: 700;
}

.health-value small {
    color: #8b949e;
    font-size: 11px;
    font-weight: 600;
}

@media (max-width: 650px) {
    .health-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.health-section {
    margin-top: 24px;
}

.health-section h3 {
    margin: 0 0 12px;
    font-size: 0.85rem;
    letter-spacing: 0.08em;
}

.health-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.health-card {
    padding: 16px;
    border: 1px solid rgba(128, 128, 128, 0.25);
    border-radius: 12px;
}

.health-label {
    display: block;
    margin-bottom: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    opacity: 0.7;
}

.health-metrics {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.9rem;
}

@media (max-width: 700px) {
    .health-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.history-shift {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    padding: 16px 18px;
    margin-bottom: 10px;
    background: #0d1015;
    border: 1px solid #252a32;
    border-radius: 12px;
    color: #f5f7fa;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.history-shift:hover {
    background: #181c22;
    border-color: #3a414c;
}

.history-shift-main {
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-shift strong {
    color: #f5f7fa;
    font-size: 1rem;
}

.history-shift span {
    color: #8b949e;
}

.history-shift-workload {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 14px;
}

@media (max-width: 700px) {
    .history-shift {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .history-shift-workload {
        flex-wrap: wrap;
        gap: 8px 14px;
    }
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
}

.app-nav a {
    display: inline-flex;
    align-items: center;
    padding: 10px 16px;
    background: #12151a;
    border: 1px solid #252a32;
    border-radius: 10px;
    color: #f5f7fa;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.app-nav a:hover {
    background: #181c22;
    border-color: #3a414c;
}

@media (max-width: 600px) {
    .app-header {
        flex-direction: column;
        gap: 20px;
    }
}

/* Stats - Recent Performance */

.recent-table {
    overflow: hidden;
    border: 1px solid #252a32;
    border-radius: 12px;
}

.recent-row {
    display: grid;
    grid-template-columns: 1.4fr 1fr 1fr;
    align-items: center;
    padding: 15px 18px;
    border-bottom: 1px solid #252a32;
}

.recent-row:last-child {
    border-bottom: none;
}

.recent-row > span:not(:first-child),
.recent-row > strong {
    text-align: right;
}

.recent-row > span:first-child {
    font-weight: 600;
}

.recent-header {
    color: #8f98a8;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.recent-row strong {
    font-size: 1.05rem;
}

/* Stats - Route Selector */

.route-selector {
    min-width: 190px;
    padding: 10px 36px 10px 14px;
    border: 1px solid #2a3039;
    border-radius: 10px;
    background: #0d1015;
    color: inherit;
    font: inherit;
    font-weight: 600;
}

.route-detail {
    margin-top: 20px;
}

.route-detail-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 20px;
}

.route-detail-heading > div {
    display: flex;
    flex-direction: column;
}

.route-detail-number {
    font-size: 2.5rem;
    line-height: 1;
    font-weight: 800;
}

.route-shift-count {
    color: #8f98a8;
    font-weight: 600;
}

.route-detail .duration-grid {
    margin-top: 20px;
}

/* Route-specific recent performance */

.route-comparison {
    margin-top: 28px;
    padding-top: 24px;
    border-top: 1px solid #252a32;
}

.route-comparison-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.route-comparison-heading h3 {
    margin: 0;
}

.route-comparison-heading span {
    color: #8f98a8;
    font-size: 0.9rem;
}

/* Shift History Filters */

.history-filters {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 22px;
}

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

.history-filter label {
    color: #8f98a8;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.history-filter select,
.history-filter input {
    min-height: 42px;
    padding: 9px 12px;
    border: 1px solid #2a3039;
    border-radius: 10px;
    background: #0d1015;
    color: inherit;
    font: inherit;
}

.history-clear {
    min-height: 42px;
    padding: 9px 18px;
    border: 1px solid #2a3039;
    border-radius: 10px;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.history-clear:hover {
    background: #171b22;
}

@media (max-width: 700px) {
    .history-filters {
        grid-template-columns: 1fr 1fr;
    }

    .history-clear {
        width: 100%;
    }
}

/* Stats Charts */

.chart-container {
    position: relative;
    width: 100%;
    height: 360px;
    margin-top: 10px;
}

@media (max-width: 700px) {
    .chart-container {
        height: 300px;
    }
}

.trend-chart-block + .trend-chart-block {
    margin-top: 28px;
    padding-top: 24px;
    border-top: 1px solid #252a32;
}

.trend-chart-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 8px;
}

.trend-chart-heading h3 {
    margin: 0;
}

.trend-chart-heading span {
    color: #8f98a8;
    font-size: 0.85rem;
}

.chart-container-small {
    height: 300px;
}

@media (max-width: 700px) {
    .chart-container-small {
        height: 260px;
    }
}

.chart-insight {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 18px;
    padding: 16px 18px;
    border: 1px solid #252a32;
    border-radius: 12px;
    background: #0d1015;
}

.chart-insight span {
    color: #8f98a8;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.chart-insight strong {
    font-size: 1.35rem;
}

.shift-status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-top: 6px;
    color: #8f98a8;
    font-size: 0.85rem;
    font-weight: 600;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #34d399;
    box-shadow: 0 0 8px rgba(52, 211, 153, 0.55);
}

.duration-card-active {
    border-color: rgba(52, 211, 153, 0.55);
    box-shadow: 0 0 0 1px rgba(52, 211, 153, 0.10);
}

.duration-card-active .duration-label {
    color: #34d399;
}

.last-received {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin: 14px 0 20px;
    padding: 14px 16px;
    border: 1px solid #252a32;
    border-radius: 12px;
    background: #0d1015;
}

.last-received > div:first-child {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.last-received-label {
    color: #8f98a8;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.last-received strong {
    font-size: 0.95rem;
}

.last-received-time {
    color: #34d399;
    font-size: 1rem;
    font-weight: 700;
}

.weekly-nav {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 18px;
    flex-wrap: wrap;
}

@media (max-width: 700px) {
    .weekly-nav {
        justify-content: flex-start;
        margin-top: 12px;
    }
}

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

.weekly-shift {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    padding: 16px 18px;
    border: 1px solid #252a32;
    border-radius: 12px;
    background: #0d1015;
    color: inherit;
    text-decoration: none;
}

.weekly-shift:hover {
    background: #151920;
}

.weekly-shift-main {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.weekly-shift-date {
    color: #8f96a3;
}

.weekly-shift-route {
    white-space: nowrap;
}

.weekly-shift-pivot {
    color: #8f96a3;
    white-space: nowrap;
}

.weekly-shift-metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(65px, 1fr));
    gap: 22px;
    text-align: right;
}

.weekly-shift-metrics span {
    font-weight: 700;
}

.weekly-shift-metrics small {
    display: block;
    margin-bottom: 3px;
    color: #8f96a3;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
}

@media (max-width: 700px) {
    .weekly-shift {
        flex-direction: column;
        align-items: stretch;
    }

    .weekly-shift-main {
        justify-content: space-between;
    }

    .weekly-shift-metrics {
        grid-template-columns: repeat(4, 1fr);
        gap: 10px;
        text-align: left;
    }
}

/* Weekly navigation */

.weekly-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.week-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0 14px;

    border: 1px solid #2b313b;
    border-radius: 10px;

    background: #0d1015;
    color: #aeb6c2;

    font-size: 0.82rem;
    font-weight: 700;
    text-decoration: none;

    transition: 0.15s ease;
}

.week-button:hover {
    border-color: #3b82f6;
    background: #151922;
    color: #ffffff;
}

.week-button-current {
    border-color: #3b82f6;
    background: #172033;
    color: #ffffff;
}

.week-button-disabled {
    opacity: 0.35;
    cursor: default;
}

@media (max-width: 700px) {
    .weekly-nav {
        width: 100%;
        margin-top: 12px;
    }

    .week-button {
        flex: 1;
        padding: 0 8px;
    }
}

/* ========================================
   Responsive app layout
   ======================================== */

@media (max-width: 600px) {

    /* Main page header */
    .app-header {
        flex-direction: column;
        align-items: stretch;
        gap: 20px;
    }

    /* Main app navigation */
    .app-nav {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        width: 100%;
        gap: 8px;
    }

    .app-nav a {
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 0;
        padding: 12px 8px;
        text-align: center;
        white-space: nowrap;
    }
}

@media (max-width: 600px) {
    /* History filters */
    .history-filters {
        grid-template-columns: minmax(0, 1fr);
        gap: 14px;
    }

    .history-filter {
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }

    .history-filter select,
    .history-filter input {
        display: block;
        width: 100%;
        min-width: 0;
        max-width: 100%;
        box-sizing: border-box;
    }

    .history-filter input[type="date"] {
        -webkit-appearance: none;
        appearance: none;
    }

    .history-clear {
        width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }
}
@media (max-width: 600px) {

    /* Weekly Summary heading + week navigation */
    .panel-heading {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
    }

    .weekly-nav {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        width: 100%;
        gap: 8px;
        margin-top: 0;
    }

    .week-button {
        width: 100%;
        min-width: 0;
        box-sizing: border-box;
        padding: 0 6px;
        white-space: nowrap;
    }
}
/* Weekly summary cards */
.panel .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel .stat {
    min-width: 0;
}

/* Settings - Devices */

.device-add-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 24px;
}

.device-add-form label {
    grid-column: 1 / -1;
}

.device-add-form input {
    grid-column: 1;
}

.device-add-button {
    grid-column: 2;
    min-width: 140px;
    padding: 0 20px;
}

.device-card {
    padding: 18px;
    margin-top: 12px;
    background: #0c0f13;
    border: 1px solid #20252d;
    border-radius: 15px;
}

.device-card strong {
    display: block;
    margin-bottom: 10px;
    font-size: 17px;
}

.device-card p {
    margin: 6px 0;
    color: #8b949e;
}

.device-revoke-form {
    display: block;
    margin-top: 16px;
}

.device-revoke-button {
    min-height: 40px;
    padding: 0 16px;
    background: transparent;
    border: 1px solid #3a414c;
    color: #f5f7fa;
}

.device-revoke-button:hover {
    background: #20252d;
}

@media (max-width: 650px) {
    .device-add-form {
        grid-template-columns: 1fr;
    }

    .device-add-button {
        width: 100%;
    }
}

/* App Footer */

.app-footer {
    display: flex;
    justify-content: center;
    padding: 28px 0 12px;
}

.app-footer a {
    color: #8b949e;
    font-size: 14px;
    text-decoration: none;
}

.app-footer a:hover {
    color: #f5f7fa;
}

/* Settings */

.settings-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 16px 18px;
    margin-top: 16px;
    background: #0c0f13;
    border: 1px solid #20252d;
    border-radius: 14px;
    color: #f5f7fa;
    text-decoration: none;
}

.settings-link:hover {
    background: #11151a;
}

.settings-link strong {
    display: block;
    margin-bottom: 4px;
}

.settings-link span {
    color: #8b949e;
    font-size: 14px;
}

.settings-link .settings-chevron {
    color: #8b949e;
    font-size: 28px;
    line-height: 1;
}

.settings-logout {
    display: inline-block;
    margin-top: 12px;
    padding: 10px 14px;
    border: 1px solid #3a414c;
    border-radius: 10px;
    color: #f5f7fa;
    text-decoration: none;
}

.settings-logout:hover {
    background: #20252d;
}

.invitation-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 0;
    border-bottom: 1px solid #252a33;
}

.invitation-row:last-child {
    border-bottom: 0;
}

.invitation-email {
    min-width: 0;
    overflow-wrap: anywhere;
}

.invitation-status {
    flex-shrink: 0;
    padding: 5px 10px;
    border: 1px solid #343a46;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}

.invitation-status-accepted {
    color: #62d98b;
}

.invitation-status-pending {
    color: #f0bd5a;
}

.invitation-status-expired {
    color: #8f98a8;
}

.error-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.error-card {
    width: 100%;
    max-width: 520px;
    padding: 32px;
    border: 1px solid #2a2f38;
    border-radius: 16px;
    background: #11151b;
    text-align: center;
}

.error-code {
    margin-bottom: 8px;
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: #8b95a5;
}

.error-card h1 {
    margin: 0 0 12px;
}

.error-card p {
    margin: 0 0 24px;
    color: #9ca5b3;
}

.error-card .button {
    display: inline-block;
    padding: 12px 20px;
    border-radius: 10px;
    background: #2f6fed;
    color: #fff;
    font-weight: 700;
    text-decoration: none;
}
