:root {
    color-scheme: light;
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-soft: #eef2f7;
    --line: #dfe5ee;
    --text: #18202b;
    --muted: #697586;
    --accent: #1677ff;
    --accent-soft: #e8f1ff;
    --green: #1c9b5f;
    --yellow: #c99400;
    --red: #d33f49;
    --shadow: 0 18px 50px rgba(19, 32, 52, .08);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    min-height: 100vh;
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at 8% 0%, rgba(22, 119, 255, .08), transparent 26rem),
        linear-gradient(180deg, #fbfcff 0%, var(--bg) 21rem);
}

button,
input {
    font: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

.login-body {
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(420px, 100%);
    padding: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, .9);
    box-shadow: var(--shadow);
    animation: rise .38s ease both;
}

.login-card img {
    display: block;
    width: 72px;
    height: 72px;
    margin-bottom: 18px;
    border-radius: 8px;
    object-fit: cover;
}

.login-card h1 {
    margin: 0 0 6px;
    font-size: 30px;
}

.login-card p {
    margin: 0 0 24px;
    color: var(--muted);
    line-height: 1.5;
}

.login-card label {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-size: 14px;
}

.login-card input {
    height: 52px;
    padding: 0 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    background: white;
    font-size: 22px;
    letter-spacing: 0;
    text-align: center;
}

.login-card button {
    width: 100%;
    height: 52px;
    margin-top: 16px;
    border: 0;
    border-radius: 8px;
    color: white;
    background: var(--accent);
    cursor: pointer;
    transition: transform .18s ease, background .18s ease;
}

.login-card button:hover,
.icon-button:hover,
.segmented button:hover {
    transform: translateY(-1px);
}

.alert {
    margin-bottom: 18px;
    padding: 12px 14px;
    border: 1px solid rgba(211, 63, 73, .25);
    border-radius: 8px;
    color: #9d2630;
    background: #fff1f2;
}

.app-shell {
    width: min(1240px, 100%);
    margin: 0 auto;
    padding: max(18px, env(safe-area-inset-top)) 18px 36px;
}

.app-topbar,
.toolbar,
.status-strip,
.device-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, .88);
    box-shadow: 0 10px 30px rgba(19, 32, 52, .05);
}

.app-topbar {
    position: sticky;
    top: 10px;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px;
    backdrop-filter: blur(18px);
}

.brand {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 12px;
}

.brand img {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    object-fit: cover;
}

.brand h1 {
    margin: 0;
    font-size: 22px;
    line-height: 1.1;
}

.brand p {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.top-actions {
    display: flex;
    gap: 8px;
}

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
    background: white;
    cursor: pointer;
    transition: transform .18s ease, border-color .18s ease, color .18s ease;
}

.icon-button span {
    font-size: 24px;
    line-height: 1;
}

.toolbar {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto auto;
    gap: 12px;
    align-items: end;
    margin-top: 14px;
    padding: 14px;
}

.field {
    display: grid;
    gap: 6px;
}

.field label {
    color: var(--muted);
    font-size: 12px;
}

.date-input {
    width: 100%;
    height: 42px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    background: white;
    cursor: pointer;
}

.segmented {
    display: flex;
    min-height: 42px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
}

.segmented button {
    min-width: 72px;
    padding: 0 12px;
    border: 0;
    border-radius: 6px;
    color: var(--muted);
    background: transparent;
    cursor: pointer;
    transition: transform .18s ease, color .18s ease, background .18s ease;
}

.segmented button.is-active {
    color: var(--text);
    background: white;
    box-shadow: 0 4px 14px rgba(19, 32, 52, .08);
}

.status-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
    padding: 12px 14px;
    color: var(--muted);
    font-size: 13px;
}

.status-strip span {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--muted);
}

.dot.ok { background: var(--green); }
.dot.warn { background: var(--yellow); }
.dot.bad { background: var(--red); }
.dot.mute { background: #939dad; }

.content-state,
.devices-grid {
    display: grid;
    gap: 14px;
    margin-top: 14px;
}

.content-state.is-hidden {
    display: none;
}

.skeleton-card {
    height: 170px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: linear-gradient(90deg, #eef2f7 0%, #fafbfc 50%, #eef2f7 100%);
    background-size: 220% 100%;
    animation: shimmer 1.15s linear infinite;
}

.device-card {
    overflow: clip;
    animation: rise .28s ease both;
}

.device-main {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) 1.35fr auto;
    gap: 18px;
    padding: 18px;
}

.device-title {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.status-badge {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    background: var(--accent-soft);
}

.status-badge.state-0 { background: #e9f8f0; color: var(--green); }
.status-badge.state-1 { background: #fff7dc; color: var(--yellow); }
.status-badge.state-2,
.status-badge.state-5 { background: #ffe9eb; color: var(--red); }
.status-badge.state-3 { background: #eef2f7; color: #667085; }

.device-title h2 {
    margin: 0;
    font-size: 18px;
}

.device-title p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.device-meta {
    display: grid;
    gap: 8px;
    margin-top: 18px;
}

.meta-row {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
}

.meta-row img {
    width: 18px;
    height: 18px;
    object-fit: contain;
}

.toners {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.toner {
    min-width: 46px;
    padding: 5px 7px;
    border: 1px solid transparent;
    border-radius: 6px;
    color: white;
    font-size: 12px;
    text-align: center;
}

.toner.low {
    border-color: var(--red);
    box-shadow: 0 0 0 2px rgba(211, 63, 73, .12);
}

.toner.cyan { background: #00a7c7; }
.toner.magenta { background: #c2187a; }
.toner.yellow { color: #2b2b2b; background: #ffd84d; }
.toner.black { background: #151515; }
.toner.gray { color: var(--text); background: #e8edf4; }

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

.metric {
    min-height: 76px;
    padding: 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcff;
}

.metric span {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.metric strong {
    display: block;
    margin-top: 8px;
    font-size: 18px;
    line-height: 1.2;
}

.card-actions {
    display: grid;
    align-content: start;
    gap: 8px;
}

.plain-button,
.bot-link {
    min-width: 116px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    background: white;
    cursor: pointer;
    transition: transform .18s ease, border-color .18s ease, color .18s ease;
}

.plain-button.primary {
    border-color: rgba(22, 119, 255, .3);
    color: var(--accent);
    background: var(--accent-soft);
}

.plain-button:hover,
.bot-link:hover {
    transform: translateY(-1px);
    border-color: rgba(22, 119, 255, .4);
}

.details {
    display: none;
    padding: 0 18px 18px;
    border-top: 1px solid var(--line);
    background: #fbfcff;
}

.device-card.is-open .details {
    display: block;
    animation: fade .22s ease both;
}

.charts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.chart-box {
    height: 260px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
    overflow: hidden;
}

.chart-box h3,
.orders h3 {
    margin: 0 0 12px;
    font-size: 16px;
}

.chart-canvas {
    position: relative;
    width: 100%;
    height: 198px;
    overflow: hidden;
    contain: size layout paint;
}

.chart-canvas canvas {
    position: absolute;
    inset: 0;
    display: block;
    width: 100% !important;
    height: 198px !important;
    max-height: 198px !important;
}

.orders {
    margin-top: 12px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
}

.day-row {
    border-top: 1px solid var(--line);
}

.day-summary {
    display: grid;
    grid-template-columns: 1.2fr repeat(7, minmax(72px, 1fr));
    gap: 10px;
    align-items: center;
    width: 100%;
    padding: 12px 0;
    border: 0;
    color: var(--text);
    background: transparent;
    text-align: left;
    cursor: pointer;
}

.day-summary span {
    color: var(--muted);
    font-size: 12px;
}

.order-table-wrap {
    display: none;
    overflow-x: auto;
    padding-bottom: 12px;
}

.day-row.is-open .order-table-wrap {
    display: block;
}

.orders table {
    width: 100%;
    min-width: 840px;
    border-collapse: collapse;
    font-size: 14px;
}

.orders th,
.orders td {
    padding: 9px 8px;
    border-top: 1px solid var(--line);
    vertical-align: middle;
    text-align: left;
}

.orders th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.small-icon {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.params {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

.empty {
    padding: 24px;
    color: var(--muted);
    text-align: center;
}

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 40;
    max-width: min(420px, calc(100vw - 36px));
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
    box-shadow: var(--shadow);
    animation: rise .2s ease both;
}

@keyframes shimmer {
    to { background-position: -220% 0; }
}

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

@keyframes fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@media (max-width: 960px) {
    .toolbar,
    .device-main {
        grid-template-columns: 1fr;
    }

    .summary-grid,
    .charts {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .card-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 620px) {
    .app-shell {
        padding-inline: 10px;
    }

    .app-topbar {
        top: 6px;
    }

    .brand p {
        display: none;
    }

    .toolbar {
        padding: 10px;
    }

    .segmented {
        width: 100%;
    }

    .segmented button {
        flex: 1;
        min-width: 0;
    }

    .summary-grid,
    .charts,
    .card-actions {
        grid-template-columns: 1fr;
    }

    .day-summary {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
