@font-face {
    font-family: 'Space Grotesk';
    src: url('SpaceGrotesk-VariableFont_wght.ttf') format('truetype');
    font-weight: 300 700;
    font-display: swap;
}

:root {
    --red: #FF003E;
    --red-dark: #AC0023;
    --red-deep: #780015;
    --pink-soft: #FFCFDF;
    --violet: #8200FF;
    --violet-dark: #5600B0;
    --blue-deep: #21004C;
    --gray-1: #E9E7E8;
    --gray-2: #D6D0D1;
    --gray-6: #806B6F;
    --gray-9: #22171A;
    --surface: #FFFFFF;
    --canvas: #F5F3F4;
    --text: #22171A;
    --muted: #806B6F;
    --shadow: 0 18px 50px rgba(33, 0, 76, .08);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body {
    margin: 0;
    min-width: 320px;
    background: var(--canvas);
    color: var(--text);
    font-family: "Space Grotesk", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { cursor: pointer; }

.hero {
    position: relative;
    overflow: hidden;
    color: #fff;
    background:
        radial-gradient(circle at 78% 20%, rgba(130,0,255,.32), transparent 34%),
        linear-gradient(115deg, #21004C 0%, #3D005F 52%, #780015 100%);
}
.hero-pattern {
    position: absolute;
    inset: -40% -6% -40% 52%;
    opacity: .25;
    background: repeating-conic-gradient(from 220deg at 50% 50%, rgba(255,255,255,.9) 0deg 1.2deg, transparent 1.2deg 7deg);
    mask-image: radial-gradient(circle at center, #000 0 48%, transparent 72%);
    transform: rotate(7deg);
}
.hero-inner {
    position: relative;
    z-index: 1;
    max-width: 1480px;
    margin: 0 auto;
    padding: 34px 36px 42px;
    display: grid;
    grid-template-columns: 190px 1fr auto;
    gap: 32px;
    align-items: center;
}
.brand-card {
    background: #fff;
    border-radius: 18px;
    padding: 16px 18px;
    height: 102px;
    display: flex;
    align-items: center;
    box-shadow: 0 15px 40px rgba(0,0,0,.14);
}
.brand-card img { width: 100%; height: 100%; object-fit: contain; }
.eyebrow, .section-kicker {
    text-transform: uppercase;
    letter-spacing: .12em;
    font-size: 12px;
    font-weight: 700;
}
.eyebrow { color: #FF9FBD; }
.hero-copy h1 { margin: 5px 0 4px; font-size: clamp(32px, 4vw, 54px); line-height: .98; font-weight: 600; letter-spacing: -.04em; }
.hero-copy p { margin: 9px 0 0; color: rgba(255,255,255,.78); font-size: 16px; }
.hero-status {
    display: inline-flex;
    gap: 9px;
    align-items: center;
    align-self: start;
    margin-top: 4px;
    padding: 9px 13px;
    border: 1px solid rgba(255,255,255,.18);
    border-radius: 999px;
    background: rgba(255,255,255,.09);
    backdrop-filter: blur(8px);
    font-size: 13px;
    font-weight: 600;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #FF9FBD; box-shadow: 0 0 0 5px rgba(255,159,189,.12); }
.hero-status.ok .status-dot { background: #9BE3B7; box-shadow: 0 0 0 5px rgba(155,227,183,.12); }
.hero-status.error .status-dot { background: #FF8A9F; }

.main-content { max-width: 1480px; margin: -18px auto 0; padding: 0 36px 40px; position: relative; z-index: 2; }
.control-panel, .chart-card, .battery-card, .info-card {
    background: var(--surface);
    border: 1px solid rgba(33,0,76,.07);
    border-radius: 24px;
    box-shadow: var(--shadow);
}
.control-panel { padding: 24px; }
.control-head, .chart-head, .section-head-inline { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.section-kicker { color: var(--red); }
h2 { margin: 4px 0 0; font-size: 24px; letter-spacing: -.025em; color: var(--blue-deep); }
.period-shortcuts { display: flex; gap: 7px; background: var(--gray-1); border-radius: 12px; padding: 4px; }
.ghost-btn { border: 0; border-radius: 9px; padding: 8px 12px; background: transparent; color: var(--blue-deep); font-weight: 600; }
.ghost-btn.active { background: #fff; color: var(--red); box-shadow: 0 4px 12px rgba(33,0,76,.08); }

.controls-grid { display: grid; grid-template-columns: minmax(320px, 1.5fr) 1fr 1fr auto; gap: 14px; align-items: end; margin-top: 20px; }
.field { min-width: 0; }
.field label { display: block; margin: 0 0 7px; color: var(--gray-6); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.field input, .route-button {
    width: 100%;
    height: 52px;
    border: 1px solid var(--gray-2);
    border-radius: 13px;
    background: #fff;
    color: var(--text);
    outline: none;
    transition: border-color .18s ease, box-shadow .18s ease;
}
.field input { padding: 0 14px; }
.field input:focus, .route-button:focus { border-color: var(--violet); box-shadow: 0 0 0 4px rgba(130,0,255,.08); }
.route-picker { position: relative; }
.route-button { display: flex; justify-content: space-between; align-items: center; padding: 6px 13px 6px 15px; text-align: left; }
.route-button-main { display: flex; flex-direction: column; min-width: 0; }
.route-count { font-weight: 650; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.route-hint { font-size: 11px; color: var(--muted); margin-top: 2px; }
.chevron { font-size: 20px; color: var(--violet-dark); }
.route-menu {
    position: absolute;
    z-index: 20;
    left: 0;
    right: 0;
    top: calc(100% + 8px);
    background: #fff;
    border: 1px solid var(--gray-2);
    border-radius: 16px;
    box-shadow: 0 22px 60px rgba(33,0,76,.18);
    overflow: hidden;
}
.route-menu-actions { display: flex; justify-content: space-between; gap: 10px; padding: 11px 13px; border-bottom: 1px solid var(--gray-1); background: #FBFAFB; }
.route-menu-actions button { border: 0; background: transparent; color: var(--violet-dark); font-weight: 700; font-size: 12px; }
.route-options { max-height: 320px; overflow: auto; padding: 7px; }
.route-option { display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 10px; cursor: pointer; }
.route-option:hover { background: #F8F4FF; }
.route-option input { accent-color: var(--red); width: 17px; height: 17px; }
.route-option span { font-size: 13px; font-weight: 550; }
.primary-btn { height: 52px; border: 0; border-radius: 13px; padding: 0 20px; color: #fff; background: var(--red); font-weight: 700; box-shadow: 0 11px 24px rgba(255,0,62,.22); }
.primary-btn:hover { background: #E80038; }
.route-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 14px; min-height: 25px; }
.route-chip { display: inline-flex; align-items: center; gap: 7px; padding: 6px 10px; border-radius: 999px; background: #F7F4F7; color: var(--blue-deep); font-size: 12px; font-weight: 650; border: 1px solid var(--gray-1); }
.route-chip i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.kpi-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin: 14px 0; }
.kpi-card { position: relative; min-height: 132px; padding: 20px; background: #fff; border: 1px solid rgba(33,0,76,.07); border-radius: 20px; overflow: hidden; }
.kpi-card::after { content: ""; position: absolute; width: 90px; height: 90px; border-radius: 50%; right: -45px; bottom: -45px; background: #F8F4FF; }
.kpi-card.feature { background: var(--blue-deep); color: #fff; border-color: var(--blue-deep); }
.kpi-card.feature::after { background: rgba(130,0,255,.32); }
.kpi-card.feature .kpi-label, .kpi-card.feature .kpi-unit { color: #E7CFFF; }
.kpi-label { display: block; color: var(--muted); font-size: 12px; font-weight: 650; }
.kpi-card strong { display: inline-block; margin-top: 15px; font-size: 36px; letter-spacing: -.04em; line-height: 1; }
.kpi-unit { margin-left: 5px; color: var(--muted); font-size: 12px; font-weight: 600; }
.kpi-card.alert { border-color: rgba(255,0,62,.28); background: #FFF4F7; }
.kpi-card.alert strong { color: var(--red-dark); }

.chart-card { padding: 24px 24px 16px; }
.chart-head p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.range-legend { color: var(--muted); font-size: 12px; margin-top: 6px; }
.range-legend span { display: flex; align-items: center; gap: 7px; }
.legend-band { width: 25px; height: 10px; border-radius: 3px; background: rgba(255,0,62,.10); border: 1px solid rgba(255,0,62,.28); }
.chart-wrap { position: relative; min-height: 520px; margin-top: 10px; }
#temperatureChart { width: 100%; height: 520px; }
.chart-loading { position: absolute; inset: 0; z-index: 4; display: flex; align-items: center; justify-content: center; gap: 10px; background: rgba(255,255,255,.82); backdrop-filter: blur(2px); color: var(--blue-deep); font-weight: 650; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--gray-2); border-top-color: var(--red); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.chart-footer { display: flex; justify-content: space-between; gap: 20px; padding: 10px 4px 0; color: var(--muted); font-size: 11px; border-top: 1px solid var(--gray-1); }

.lower-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(310px, .75fr); gap: 14px; margin-top: 14px; }
.battery-card, .info-card { padding: 24px; }
.independent-badge { display: inline-flex; align-items: center; padding: 7px 10px; border-radius: 999px; background: #F3E9FF; color: var(--violet-dark); font-size: 11px; font-weight: 700; }
.battery-list { margin-top: 18px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.battery-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 16px; align-items: center; padding: 12px 14px; border: 1px solid var(--gray-1); border-radius: 14px; background: #FCFBFC; }
.battery-route { min-width: 0; }
.battery-route strong { display: block; font-size: 13px; color: var(--blue-deep); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.battery-route span { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.battery-value { min-width: 62px; text-align: right; font-size: 18px; font-weight: 700; color: var(--blue-deep); }
.battery-bar { grid-column: 1 / -1; height: 4px; border-radius: 999px; background: var(--gray-1); overflow: hidden; margin-top: -7px; }
.battery-bar i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--red), var(--violet)); }
.battery-row.low { background: #FFF4F7; border-color: rgba(255,0,62,.2); }
.battery-row.low .battery-value { color: var(--red-dark); }
.empty-state { color: var(--muted); font-size: 13px; padding: 20px 0; }
.info-card { background: linear-gradient(165deg, #21004C 0%, #320063 100%); color: #fff; border-color: transparent; }
.info-card .section-kicker { color: #FF9FBD; }
.info-card h2 { color: #fff; margin-bottom: 18px; }
.info-row { display: grid; grid-template-columns: 56px 1fr; gap: 14px; align-items: start; padding: 13px 0; border-top: 1px solid rgba(255,255,255,.12); }
.info-number { color: #FF7BA4; font-size: 22px; font-weight: 700; }
.info-row strong { font-size: 13px; }
.info-row p { margin: 3px 0 0; color: rgba(255,255,255,.65); font-size: 11px; line-height: 1.45; }
.notice { margin-top: 14px; border-radius: 14px; padding: 12px 14px; background: #FFF4F7; border: 1px solid rgba(255,0,62,.2); color: var(--red-deep); font-size: 12px; font-weight: 600; }

footer { max-width: 1480px; margin: 0 auto; padding: 0 36px 30px; display: flex; justify-content: space-between; gap: 18px; color: var(--muted); font-size: 11px; }

@media (max-width: 1050px) {
    .hero-inner { grid-template-columns: 160px 1fr; }
    .hero-status { grid-column: 1 / -1; justify-self: start; }
    .controls-grid { grid-template-columns: 1fr 1fr; }
    .route-field { grid-column: 1 / -1; }
    .apply-field { align-self: end; }
    .kpi-grid { grid-template-columns: repeat(3, 1fr); }
    .lower-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
    .hero-inner { padding: 24px 18px 34px; grid-template-columns: 128px 1fr; gap: 18px; }
    .brand-card { height: 78px; padding: 10px; border-radius: 14px; }
    .hero-copy h1 { font-size: 31px; }
    .hero-copy p { font-size: 13px; }
    .main-content { padding: 0 14px 28px; }
    .control-panel, .chart-card, .battery-card, .info-card { border-radius: 18px; padding: 18px; }
    .control-head, .chart-head, .section-head-inline { flex-direction: column; }
    .controls-grid { grid-template-columns: 1fr; }
    .route-field { grid-column: auto; }
    .primary-btn { width: 100%; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .kpi-card { min-height: 118px; padding: 16px; }
    .kpi-card strong { font-size: 30px; }
    .chart-wrap, #temperatureChart { height: 430px; min-height: 430px; }
    .chart-footer { flex-direction: column; gap: 5px; }
    .battery-list { grid-template-columns: 1fr; }
    footer { padding: 0 18px 22px; flex-direction: column; }
}
@media (max-width: 440px) {
    .hero-inner { grid-template-columns: 1fr; }
    .brand-card { width: 150px; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .period-shortcuts { width: 100%; }
    .ghost-btn { flex: 1; }
}

/* Ensure elements using the HTML hidden attribute are actually hidden. */
.header-actions { display: flex; flex-direction: column; gap: 10px; align-items: flex-end; align-self: start; }
.logout-form { margin: 0; }
.logout-form .ghost-btn { color: white; border: 1px solid rgba(255,255,255,.35); background: transparent; }
.logout-form .ghost-btn:hover { background: rgba(255,255,255,.15); }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-box { width: 100%; max-width: 420px; padding: 32px; background: white; border: 1px solid var(--gray-2); border-radius: 12px; box-shadow: var(--shadow); }
.login-logo { display: block; width: 190px; max-width: 100%; height: 80px; object-fit: contain; margin-bottom: 24px; }
.login-box h1 { color: var(--blue-deep); font-size: 28px; line-height: 1.15; margin: 8px 0 24px; }
.login-box form { display: grid; gap: 10px; }
.login-box label { color: var(--blue-deep); font-size: 14px; font-weight: 600; }
.login-box input:not([type=hidden]) { width: 100%; min-width: 0; padding: 12px; border: 1px solid var(--gray-2); border-radius: 6px; margin-bottom: 8px; }
.login-box input:focus { outline: 2px solid var(--violet); outline-offset: 2px; }
.login-box .primary-btn { width: 100%; margin-top: 6px; }
.login-error { padding: 12px; background: #FFF4F7; color: var(--red-deep); border: 1px solid var(--pink-soft); border-radius: 6px; font-size: 14px; }
.login-footer { color: var(--muted); font-size: 12px; margin: 24px 0 0; }
@media (max-width: 1050px) {
    .header-actions { grid-column: 1 / -1; align-items: center; flex-direction: row; flex-wrap: wrap; }
}
@media (max-width: 440px) { .login-box { padding: 24px; } }

[hidden] {
    display: none !important;
}

.header-link { color: white; font-weight: 600; font-size: 14px; padding: 8px 0; }
.assignment-header { display: flex; flex-wrap: wrap; gap: 20px; align-items: center; padding: 18px max(20px, calc((100vw - 1200px) / 2)); background: white; border-bottom: 1px solid var(--gray-2); }
.assignment-header img { width: 160px; height: 64px; object-fit: contain; margin-right: auto; }
.assignment-header a { color: var(--blue-deep); font-weight: 600; }
.assignment-header form { margin: 0; }
.assignment-main { max-width: 1240px; margin: auto; padding: 32px 20px 60px; }
.assignment-title { display: flex; gap: 20px; align-items: center; justify-content: space-between; }
.assignment-title h1 { color: var(--blue-deep); font-size: clamp(28px, 4vw, 40px); margin: 8px 0; }
.assignment-title p, .assignment-overview > p { color: var(--muted); line-height: 1.5; }
.assignment-notice { min-height: 46px; background: #F3E9FF; color: var(--blue-deep); border-left: 4px solid var(--violet); padding: 12px 16px; line-height: 1.5; }
.assignment-notice.error { color: var(--red-deep); background: #FFF4F7; border-color: var(--red); }
.assignment-notice.success { border-color: #247342; background: #EAF6ED; color: #18552D; }
.assignment-editor { background: white; border: 1px solid var(--gray-2); border-radius: 10px; padding: 28px; display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); gap: 28px; }
.assignment-editor h2 { display: flex; gap: 10px; align-items: center; color: var(--blue-deep); font-size: 19px; margin: 0 0 20px; }
.assignment-editor h2 span { display: inline-grid; place-items: center; background: var(--blue-deep); color: white; width: 30px; height: 30px; border-radius: 50%; font-size: 15px; flex-shrink: 0; }
.assignment-step { min-width: 0; }
.assignment-step label { display: block; margin: 12px 0 8px; font-size: 14px; font-weight: 600; color: var(--blue-deep); }
.assignment-step select, .assignment-step input { font: inherit; width: 100%; min-width: 0; padding: 12px; border: 1px solid var(--gray-2); border-radius: 6px; background: white; color: var(--text); }
.assignment-step select:focus, .assignment-step input:focus { outline: 2px solid var(--violet); outline-offset: 2px; }
.assignment-step select[size] { padding: 6px; font-size: 13px; }
.assignment-step option { padding: 10px 6px; }
.assignment-detail { color: var(--blue-deep); background: #F7F4FA; padding: 14px; font-size: 14px; line-height: 1.7; overflow-wrap: anywhere; }
.assignment-confirm { grid-column: 1 / -1; padding-top: 24px; border-top: 1px solid var(--gray-2); }
.assignment-confirm p { line-height: 1.7; overflow-wrap: anywhere; }
.transfer-check { display: flex; gap: 12px; align-items: flex-start; padding: 14px; background: #FFF4F7; color: var(--red-deep); margin: 16px 0; line-height: 1.5; }
.transfer-check input { width: 20px; height: 20px; flex-shrink: 0; }
.assignment-confirm button { margin-top: 8px; }
.assignment-editor button:disabled { opacity: .5; cursor: default; }
.assignment-overview { padding-top: 28px; }
.assignment-overview h2 { font-size: 22px; color: var(--blue-deep); }
.assignment-table-wrap { overflow-x: auto; background: white; border: 1px solid var(--gray-2); border-radius: 8px; }
.assignment-table-wrap table { width: 100%; border-collapse: collapse; text-align: left; }
.assignment-table-wrap th { font-size: 13px; color: var(--blue-deep); background: #F3E9FF; }
.assignment-table-wrap th, .assignment-table-wrap td { padding: 14px 16px; border-bottom: 1px solid var(--gray-1); }
.assignment-table-wrap td { font-size: 14px; line-height: 1.5; }
.assignment-history { font-size: 14px; line-height: 1.7; color: var(--muted); }
.assignment-history p { border-bottom: 1px solid var(--gray-2); padding-bottom: 12px; overflow-wrap: anywhere; }
@media (max-width: 720px) {
    .assignment-editor { grid-template-columns: 1fr; padding: 18px; gap: 24px; }
    .assignment-title { align-items: flex-start; flex-direction: column; }
    .assignment-header { gap: 14px; padding: 12px 18px; }
    .assignment-header img { width: 135px; height: 52px; }
    .assignment-main { padding: 24px 14px 40px; }
}
