:root {
    color-scheme: dark;
    --bg: #07110d;
    --panel: #0d1b15;
    --panel-soft: #11231b;
    --line: rgba(176, 213, 194, 0.13);
    --text: #edf7f1;
    --muted: #8fa99b;
    --green: #4fe391;
    --green-dark: #1b8f58;
    --red: #ff6b6b;
    --amber: #f4bc57;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
    font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
}

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

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(circle at 10% -10%, rgba(40, 151, 91, 0.17), transparent 32rem),
        radial-gradient(circle at 90% 5%, rgba(44, 117, 78, 0.1), transparent 25rem),
        var(--bg);
}

button,
input,
select {
    font: inherit;
}

button {
    color: inherit;
}

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

.login-shell {
    width: min(100%, 440px);
}

.login-panel {
    position: relative;
    overflow: hidden;
    padding: 46px 42px 34px;
    border: 1px solid var(--line);
    border-radius: 24px;
    background: linear-gradient(145deg, rgba(17, 35, 27, 0.96), rgba(10, 23, 17, 0.98));
    box-shadow: var(--shadow);
}

.login-panel::before {
    position: absolute;
    width: 220px;
    height: 220px;
    top: -120px;
    right: -100px;
    border: 1px solid rgba(79, 227, 145, 0.2);
    border-radius: 50%;
    box-shadow: 0 0 80px rgba(79, 227, 145, 0.08);
    content: "";
}

.brand-mark,
.brand-icon {
    display: grid;
    place-items: center;
    width: 50px;
    height: 50px;
    margin-bottom: 26px;
    border: 1px solid rgba(79, 227, 145, 0.35);
    border-radius: 15px;
    background: rgba(79, 227, 145, 0.08);
}

.brand-mark span,
.brand-icon i {
    width: 22px;
    height: 22px;
    border: 2px solid var(--green);
    border-radius: 50%;
    box-shadow: inset 0 0 0 5px var(--panel);
}

.brand-mark span::before,
.brand-icon i::before {
    display: block;
    width: 2px;
    height: 10px;
    margin: -5px auto 0;
    border-radius: 2px;
    background: var(--green);
    content: "";
}

.eyebrow {
    margin: 0 0 9px;
    color: var(--green);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.18em;
}

h1,
h2,
p {
    margin-top: 0;
}

.login-panel h1 {
    margin-bottom: 10px;
    font-size: clamp(28px, 7vw, 36px);
    letter-spacing: -0.04em;
}

.login-description {
    margin-bottom: 32px;
    color: var(--muted);
}

.login-form {
    display: grid;
    gap: 19px;
}

label {
    display: grid;
    gap: 8px;
}

label span {
    color: #b6c9bf;
    font-size: 13px;
    font-weight: 600;
}

input,
select {
    width: 100%;
    height: 48px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 11px;
    outline: none;
    color: var(--text);
    background: rgba(3, 12, 8, 0.48);
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

select {
    appearance: none;
    padding-right: 38px;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--muted) 50%),
        linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position:
        calc(100% - 18px) 21px,
        calc(100% - 13px) 21px;
    background-repeat: no-repeat;
    background-size: 5px 5px, 5px 5px;
}

input:focus,
select:focus {
    border-color: rgba(79, 227, 145, 0.7);
    box-shadow: 0 0 0 3px rgba(79, 227, 145, 0.1);
}

.primary-button,
.ghost-button,
.icon-button,
.control-button,
.add-button,
.task-button {
    border: 0;
    cursor: pointer;
    transition: transform 140ms ease, background 140ms ease, border-color 140ms ease, opacity 140ms ease;
}

.primary-button {
    height: 50px;
    margin-top: 7px;
    border-radius: 11px;
    color: #031109;
    background: var(--green);
    font-weight: 800;
    box-shadow: 0 10px 30px rgba(79, 227, 145, 0.15);
}

.primary-button:hover,
.control-button:hover:not(:disabled) {
    transform: translateY(-1px);
}

.primary-button:active,
.control-button:active:not(:disabled) {
    transform: translateY(0);
}

.primary-button.compact {
    height: 42px;
    margin: 0;
    padding: 0 20px;
}

.security-note {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 26px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.status-dot,
.state-light {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 10px var(--green);
}

.alert {
    margin-bottom: 20px;
    padding: 11px 13px;
    border-radius: 9px;
    font-size: 13px;
}

.alert-error {
    border: 1px solid rgba(255, 107, 107, 0.24);
    color: #ffc1c1;
    background: rgba(255, 107, 107, 0.08);
}

.topbar {
    position: sticky;
    z-index: 10;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 78px;
    padding: 13px max(24px, calc((100vw - 1180px) / 2));
    border-bottom: 1px solid var(--line);
    background: rgba(7, 17, 13, 0.83);
    backdrop-filter: blur(20px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 13px;
    color: inherit;
    text-decoration: none;
}

.brand-icon {
    width: 42px;
    height: 42px;
    margin: 0;
    border-radius: 12px;
}

.brand-icon i {
    width: 18px;
    height: 18px;
}

.brand strong,
.brand small {
    display: block;
}

.brand strong {
    font-size: 15px;
}

.brand small {
    margin-top: 3px;
    color: var(--muted);
    font-size: 11px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.main-nav {
    position: absolute;
    left: 50%;
    display: flex;
    gap: 5px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: rgba(255, 255, 255, 0.025);
    transform: translateX(-50%);
}

.main-nav a {
    min-width: 96px;
    padding: 9px 14px;
    border-radius: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    transition: color 140ms ease, background 140ms ease;
}

.main-nav a:hover {
    color: var(--text);
}

.main-nav a.active {
    color: #06130c;
    background: var(--green);
}

.user-chip {
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: #b8cbbf;
    font-size: 12px;
}

.ghost-button,
.icon-button {
    border: 1px solid var(--line);
    border-radius: 9px;
    color: #b8cbbf;
    background: rgba(255, 255, 255, 0.02);
}

.ghost-button {
    min-height: 36px;
    padding: 0 13px;
}

.ghost-button:hover,
.icon-button:hover {
    border-color: rgba(79, 227, 145, 0.35);
    color: var(--text);
}

.dashboard {
    width: min(calc(100% - 48px), 1180px);
    margin: 0 auto;
    padding: 32px 0 64px;
}

.hero {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 30px;
    margin-bottom: 20px;
}

.hero h1 {
    margin-bottom: 6px;
    font-size: clamp(28px, 4vw, 36px);
    letter-spacing: -0.05em;
}

.hero > div > p:last-child {
    margin-bottom: 0;
    color: var(--muted);
}

.server-state {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 210px;
    padding: 11px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(17, 35, 27, 0.7);
}

.server-state strong,
.server-state small {
    display: block;
}

.server-state strong {
    font-size: 13px;
}

.server-state small {
    margin-top: 3px;
    color: var(--muted);
    font-size: 11px;
}

.server-state.offline .state-light {
    background: var(--red);
    box-shadow: 0 0 10px var(--red);
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 34px;
}

.metric-card,
.device-card,
.activity-list {
    border: 1px solid var(--line);
    background: linear-gradient(145deg, rgba(17, 35, 27, 0.82), rgba(10, 23, 17, 0.9));
}

.metric-card {
    padding: 14px 18px;
    border-radius: 13px;
}

.metric-card span,
.metric-card small {
    display: block;
    color: var(--muted);
    font-size: 11px;
}

.metric-card strong {
    display: block;
    margin: 5px 0 4px;
    font-size: 23px;
    letter-spacing: -0.04em;
}

.content-section + .content-section {
    margin-top: 48px;
}

.section-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 17px;
}

.section-heading h2 {
    margin: 0;
    font-size: 22px;
    letter-spacing: -0.03em;
}

.icon-button {
    width: 38px;
    height: 38px;
    font-size: 20px;
}

.add-button {
    min-height: 38px;
    padding: 0 15px;
    border: 1px solid rgba(79, 227, 145, 0.35);
    border-radius: 9px;
    color: var(--green);
    background: rgba(79, 227, 145, 0.07);
    font-size: 12px;
    font-weight: 700;
}

.add-button:hover {
    background: rgba(79, 227, 145, 0.12);
}

.section-note {
    margin: -6px 0 17px;
    color: var(--muted);
    font-size: 11px;
}

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

.device-card {
    padding: 22px;
    border-radius: 18px;
}

.device-card.offline {
    opacity: 0.76;
}

.device-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    padding-bottom: 19px;
    border-bottom: 1px solid var(--line);
}

.device-title-line {
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.rename-button {
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 7px;
    color: var(--muted);
    background: transparent;
    cursor: pointer;
}

.rename-button:hover {
    color: var(--green);
    background: rgba(79, 227, 145, 0.07);
}

.imei {
    margin: 6px 0 0;
    color: var(--muted);
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 11px;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 9px;
    border-radius: 999px;
    color: var(--green);
    background: rgba(79, 227, 145, 0.09);
    font-size: 11px;
    font-weight: 700;
}

.badge::before {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    content: "";
}

.badge.offline {
    color: var(--muted);
    background: rgba(143, 169, 155, 0.08);
}

.relay-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 18px 0 16px;
}

.relay-info strong,
.relay-info small {
    display: block;
}

.relay-info strong {
    font-size: 14px;
}

.relay-info small {
    margin-top: 5px;
    color: var(--muted);
    font-size: 11px;
}

.relay-state {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 12px;
}

.relay-state i {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #55675d;
}

.relay-state.on {
    color: var(--green);
}

.relay-state.on i {
    background: var(--green);
    box-shadow: 0 0 11px rgba(79, 227, 145, 0.7);
}

.control-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 9px;
}

.control-button {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: #bdd0c5;
    background: rgba(255, 255, 255, 0.025);
    font-size: 13px;
    font-weight: 700;
}

.control-button.on-button {
    border-color: rgba(79, 227, 145, 0.3);
    color: var(--green);
    background: rgba(79, 227, 145, 0.07);
}

.control-button.off-button {
    border-color: rgba(255, 107, 107, 0.2);
    color: #ff9b9b;
    background: rgba(255, 107, 107, 0.055);
}

.control-button:disabled {
    cursor: not-allowed;
    opacity: 0.36;
}

.empty-state {
    grid-column: 1 / -1;
    display: grid;
    place-items: center;
    min-height: 210px;
    padding: 30px;
    border: 1px dashed rgba(176, 213, 194, 0.17);
    border-radius: 18px;
    color: var(--muted);
    text-align: center;
}

.schedule-list {
    display: grid;
    gap: 11px;
}

.schedule-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 20px;
    padding: 18px 20px;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: linear-gradient(145deg, rgba(17, 35, 27, 0.82), rgba(10, 23, 17, 0.9));
}

.schedule-item.disabled {
    opacity: 0.62;
}

.schedule-title-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 9px;
}

.schedule-title-row strong {
    font-size: 14px;
}

.task-type {
    padding: 4px 7px;
    border-radius: 6px;
    color: var(--green);
    background: rgba(79, 227, 145, 0.08);
    font-size: 10px;
    font-weight: 700;
}

.schedule-rule {
    margin: 7px 0 0;
    color: #c0d2c8;
    font-size: 12px;
}

.schedule-meta {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 10px;
}

.schedule-actions {
    display: flex;
    align-items: center;
    gap: 7px;
}

.task-button {
    min-height: 34px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: #b8cbbf;
    background: rgba(255, 255, 255, 0.02);
    font-size: 11px;
}

.task-button:hover {
    border-color: rgba(79, 227, 145, 0.32);
    color: var(--text);
}

.task-button.toggle-active {
    border-color: rgba(79, 227, 145, 0.28);
    color: var(--green);
    background: rgba(79, 227, 145, 0.06);
}

.task-button.delete-armed {
    border-color: rgba(255, 107, 107, 0.34);
    color: #ff9b9b;
    background: rgba(255, 107, 107, 0.06);
}

.empty-state p {
    margin: 15px 0 0;
}

.empty-state strong {
    color: var(--text);
}

.empty-state small {
    display: block;
    max-width: 500px;
    margin-top: 8px;
    line-height: 1.7;
}

.loader {
    width: 22px;
    height: 22px;
    border: 2px solid rgba(79, 227, 145, 0.2);
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin 800ms linear infinite;
}

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

.activity-list {
    overflow: hidden;
    border-radius: 16px;
}

.activity-item {
    display: grid;
    grid-template-columns: 10px minmax(0, 1fr) auto;
    align-items: center;
    gap: 13px;
    min-height: 58px;
    padding: 11px 18px;
    border-bottom: 1px solid var(--line);
}

.activity-item:last-child {
    border-bottom: 0;
}

.activity-item > i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green);
}

.activity-item strong,
.activity-item small {
    display: block;
}

.activity-item strong {
    font-size: 12px;
    font-weight: 600;
}

.activity-item small {
    margin-top: 4px;
    color: var(--muted);
    font-size: 11px;
}

.activity-time,
.muted {
    color: var(--muted);
    font-size: 11px;
}

.activity-list > .muted {
    margin: 0;
    padding: 28px;
    text-align: center;
}

.toast {
    position: fixed;
    z-index: 40;
    right: 22px;
    bottom: 22px;
    max-width: min(380px, calc(100vw - 44px));
    padding: 13px 16px;
    border: 1px solid rgba(79, 227, 145, 0.3);
    border-radius: 11px;
    color: #dff8e9;
    background: rgba(12, 35, 24, 0.96);
    box-shadow: var(--shadow);
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.error {
    border-color: rgba(255, 107, 107, 0.35);
    color: #ffd0d0;
    background: rgba(47, 18, 18, 0.97);
}

.modal-backdrop {
    position: fixed;
    z-index: 30;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 22px;
    background: rgba(1, 8, 5, 0.78);
    backdrop-filter: blur(8px);
}

.modal-backdrop[hidden] {
    display: none;
}

.modal {
    width: min(100%, 410px);
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.schedule-modal {
    width: min(100%, 620px);
    max-height: calc(100vh - 44px);
    overflow-y: auto;
}

.schedule-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 17px;
}

.field-full {
    grid-column: 1 / -1;
}

.weekday-field > span {
    display: block;
    margin-bottom: 8px;
    color: #b6c9bf;
    font-size: 13px;
    font-weight: 600;
}

.weekday-options {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 7px;
}

.weekday-options label {
    display: block;
    position: relative;
}

.weekday-options input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.weekday-options b {
    display: grid;
    place-items: center;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    font-size: 12px;
}

.weekday-options input:checked + b {
    border-color: rgba(79, 227, 145, 0.42);
    color: var(--green);
    background: rgba(79, 227, 145, 0.09);
}

.enable-field {
    display: flex;
    align-items: center;
    grid-template-columns: none;
    gap: 9px;
}

.enable-field input {
    width: 17px;
    height: 17px;
    accent-color: var(--green);
}

.enable-field span {
    color: #b6c9bf;
    font-size: 12px;
}

[hidden] {
    display: none !important;
}

.modal h2 {
    margin-bottom: 22px;
    font-size: 21px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 9px;
    margin-top: 22px;
}

@media (max-width: 760px) {
    .topbar {
        flex-wrap: wrap;
        padding: 12px 18px;
    }

    .brand small,
    .user-chip {
        display: none;
    }

    .main-nav {
        position: static;
        order: 3;
        width: 100%;
        margin-top: 10px;
        transform: none;
    }

    .main-nav a {
        flex: 1;
    }

    .dashboard {
        width: min(calc(100% - 30px), 1180px);
        padding-top: 38px;
    }

    .hero {
        align-items: stretch;
        flex-direction: column;
    }

    .server-state {
        min-width: 0;
    }

    .metric-grid {
        grid-template-columns: 1fr;
        margin-bottom: 40px;
    }

    .metric-card {
        display: grid;
        grid-template-columns: 1fr auto;
        align-items: center;
    }

    .metric-card strong {
        grid-row: 1 / span 2;
        grid-column: 2;
    }

    .device-grid {
        grid-template-columns: 1fr;
    }

    .schedule-item {
        grid-template-columns: 1fr;
    }

    .schedule-actions {
        justify-content: flex-start;
    }

    .activity-item {
        grid-template-columns: 9px minmax(0, 1fr);
    }

    .activity-time {
        display: none;
    }
}

@media (max-width: 480px) {
    .login-panel {
        padding: 36px 25px 28px;
    }

    .device-card {
        padding: 18px;
    }

    .control-group {
        grid-template-columns: 1fr;
    }

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

    .field-full {
        grid-column: auto;
    }

    .weekday-options {
        gap: 4px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
