* {
    box-sizing: border-box;
}

:root {
    --bg: #f3f7fb;
    --surface: #ffffff;
    --surface-soft: #f8fbfd;
    --ink: #111827;
    --muted: #64748b;
    --line: #dbe5ef;
    --brand: #2563eb;
    --brand-dark: #153e75;
    --nav: #143d46;
    --teal: #0f766e;
    --green: #16a34a;
    --red: #dc2626;
    --amber: #d97706;
    --shadow: 0 18px 44px rgba(15, 23, 42, .10);
    --shadow-soft: 0 8px 22px rgba(15, 23, 42, .08);
}

html {
    min-height: 100%;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(circle at 24% 12%, rgba(37, 99, 235, .10), transparent 28%),
        radial-gradient(circle at 86% 6%, rgba(15, 118, 110, .10), transparent 24%),
        linear-gradient(135deg, #f8fbfd 0%, #eef5f8 48%, #f9fafb 100%);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
    font: inherit;
}

button {
    border: 0;
    cursor: pointer;
}

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

button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 3px solid rgba(37, 99, 235, .22);
    outline-offset: 2px;
}

.hidden {
    display: none !important;
}

.auth-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 22% 18%, rgba(37, 99, 235, .10), transparent 30%),
        linear-gradient(135deg, #f8fbfd 0%, #eef5f8 100%) !important;
}

.auth-card {
    width: min(500px, 100%);
    padding: 30px !important;
    border: 1px solid rgba(219, 229, 239, .96) !important;
    border-radius: 8px !important;
    box-shadow: var(--shadow) !important;
}

.auth-card h1 {
    color: #0f172a;
    font-size: 34px !important;
    letter-spacing: 0;
}

.auth-card p,
.auth-muted {
    color: var(--muted) !important;
}

.auth-card input,
.auth-card select {
    height: 50px;
    border: 1px solid var(--line) !important;
    border-radius: 8px !important;
    background: #ffffff;
}

.layout {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 28px 18px;
    color: #f8fafc;
    background: linear-gradient(180deg, var(--nav) 0%, #172033 100%);
    border-right: 1px solid rgba(255, 255, 255, .10);
}

.brand {
    padding: 4px 10px 28px;
}

.brand h2 {
    margin: 0;
    font-size: 26px;
    line-height: 1;
    letter-spacing: 0;
}

.brand span {
    display: block;
    margin-top: 8px;
    color: rgba(248, 250, 252, .72);
    font-size: 13px;
    font-weight: 800;
}

.sidebar nav {
    display: grid;
    gap: 10px;
}

.menu {
    width: 100%;
    min-height: 54px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 14px;
    color: rgba(248, 250, 252, .80);
    background: transparent;
    border-radius: 8px;
    text-align: left;
    transition: background .18s ease, color .18s ease, transform .18s ease;
}

.menu:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, .08);
}

.menu.active {
    color: #0f172a;
    background: #ffffff;
    box-shadow: 0 10px 24px rgba(0, 0, 0, .16);
}

.menu-icon {
    width: 34px;
    height: 34px;
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    color: inherit;
    background: rgba(255, 255, 255, .10);
    border-radius: 8px;
    font-size: 17px;
}

.menu.active .menu-icon {
    color: #ffffff;
    background: var(--teal);
}

.content {
    min-width: 0;
    padding: 34px clamp(20px, 4vw, 52px) 58px;
}

.page-title {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.page-subtitle {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

.page-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin: 14px 0 20px;
}

.page-strip article {
    display: grid;
    gap: 4px;
    padding: 14px 16px;
    background: rgba(255, 255, 255, .92);
    border: 1px solid rgba(219, 229, 239, .96);
    border-radius: 8px;
    box-shadow: var(--shadow-soft);
}

.page-strip strong {
    color: #0f4f55;
    font-size: 28px;
    line-height: 1;
}

.page-strip span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
}

.page-title h1 {
    margin: 0;
    color: #0f172a;
    font-size: clamp(32px, 4.2vw, 52px);
    line-height: 1.02;
    letter-spacing: 0;
}

.top-user {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.site-pill {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    padding: 0 15px !important;
    color: #0f766e !important;
    background: #e8f7f5 !important;
    border: 1px solid rgba(15, 118, 110, .20);
    border-radius: 999px !important;
    font-weight: 900;
}

.primary-btn,
.secondary-btn,
.success-btn,
.danger-btn,
.icon-btn,
.filter-btn {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 16px;
    border-radius: 8px;
    font-weight: 850;
    line-height: 1;
    white-space: nowrap;
    transition: background .18s ease, border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

.primary-btn {
    color: #ffffff;
    background: var(--brand);
    box-shadow: 0 10px 22px rgba(37, 99, 235, .22);
}

.primary-btn:hover {
    background: #1d4ed8;
    transform: translateY(-1px);
}

.secondary-btn {
    color: #0f172a;
    background: #ffffff;
    border: 1px solid var(--line);
}

.secondary-btn:hover {
    border-color: #b8c8d8;
    box-shadow: var(--shadow-soft);
}

.success-btn {
    color: #ffffff;
    background: var(--green);
}

.danger-btn {
    color: #ffffff;
    background: var(--red);
}

.icon-btn {
    width: 42px;
    padding: 0;
    color: var(--brand-dark);
    background: #ffffff;
    border: 1px solid var(--line);
    font-size: 19px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(140px, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

.stat-card {
    min-height: 142px;
    display: grid;
    grid-template-columns: 1fr auto;
    align-content: space-between;
    justify-items: start;
    padding: 22px;
    color: var(--ink);
    background: rgba(255, 255, 255, .94);
    border: 1px solid rgba(219, 229, 239, .96);
    border-radius: 8px;
    box-shadow: var(--shadow-soft);
    text-align: left;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.stat-card strong {
    grid-column: 1 / 2;
    color: #0f4f55;
    font-size: 44px;
    line-height: 1;
}

.stat-card > span:last-child {
    grid-column: 1 / -1;
    color: var(--muted);
    font-size: 14px;
    font-weight: 950;
    text-transform: uppercase;
}

.stat-icon {
    grid-column: 2 / 3;
    grid-row: 1 / 2;
    width: 34px;
    height: 34px;
    display: inline-grid;
    place-items: center;
    color: var(--brand);
    background: #eff6ff;
    border-radius: 8px;
    font-size: 14px;
}

.home-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(320px, .9fr);
    gap: 16px;
    margin-top: 18px;
}

.family-internet-card,
.today-card,
.dashboard-section {
    background: rgba(255, 255, 255, .94);
    border: 1px solid rgba(219, 229, 239, .96);
    border-radius: 8px;
    box-shadow: var(--shadow-soft);
}

.family-internet-card {
    min-height: 190px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 18px;
    align-items: center;
    padding: 26px;
    background:
        linear-gradient(135deg, rgba(37, 99, 235, .10), rgba(15, 118, 110, .10)),
        #ffffff;
}

.family-internet-card h2,
.today-card h2,
.dashboard-section h2 {
    margin: 4px 0 0;
    color: #0f172a;
    font-size: 22px;
    line-height: 1.15;
    letter-spacing: 0;
}

.family-internet-card p {
    max-width: 560px;
    margin: 10px 0 0;
    color: var(--muted);
    line-height: 1.55;
}

.section-kicker {
    color: var(--teal);
    font-size: 12px;
    font-weight: 950;
    letter-spacing: 0;
    text-transform: uppercase;
}

.internet-actions {
    display: grid;
    gap: 10px;
    min-width: 220px;
}

.today-card {
    padding: 22px;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.mini-list {
    display: grid;
    gap: 10px;
}

.mini-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    min-height: 58px;
    padding: 12px 14px;
    background: var(--surface-soft);
    border: 1px solid #e7eef5;
    border-radius: 8px;
}

.mini-item strong {
    display: block;
    overflow: hidden;
    color: #172033;
    font-size: 15px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mini-item span {
    color: var(--muted);
    font-size: 13px;
}

.mini-badge {
    padding: 7px 10px;
    border-radius: 999px;
    background: #e8f7f5;
    color: #0f766e;
    font-size: 12px;
    font-weight: 900;
}

.dashboard-section {
    margin-top: 16px;
    padding: 22px;
}

.family-device-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(180px, 1fr));
    gap: 12px;
}

.family-tile {
    min-height: 106px;
    display: grid;
    gap: 12px;
    padding: 16px;
    background: var(--surface-soft);
    border: 1px solid #e7eef5;
    border-radius: 8px;
}

.family-tile-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.family-tile h3 {
    margin: 0;
    overflow: hidden;
    color: #111827;
    font-size: 17px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.family-tile p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

.member-avatar {
    width: 40px;
    height: 40px;
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    color: #0f766e;
    background: #dff7f1;
    border-radius: 8px;
    font-weight: 950;
}

.device-mini-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.device-chip {
    max-width: 100%;
    padding: 7px 9px;
    overflow: hidden;
    color: #334155;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.device-chip.blocked {
    color: #991b1b;
    background: #fef2f2;
    border-color: #fecaca;
}

.filter-bar {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 6px;
    margin-bottom: 20px;
    background: rgba(255, 255, 255, .74);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.filter-btn {
    color: #334155;
    background: transparent;
}

.filter-btn.active {
    color: #ffffff;
    background: #0f172a;
}

.devices-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(260px, 1fr));
    gap: 16px;
}

.device-card {
    display: grid;
    gap: 18px;
    padding: 22px;
    background: rgba(255, 255, 255, .96);
    border: 1px solid rgba(219, 229, 239, .96);
    border-radius: 8px;
    box-shadow: var(--shadow-soft);
    min-width: 0;
}

.device-card:hover,
.family-tile:hover,
.rule-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.device-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.device-head h3 {
    margin: 0;
    overflow: hidden;
    color: #0f172a;
    font-size: 22px;
    line-height: 1.16;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.device-head span:not(.status-dot) {
    display: block;
    margin-top: 6px;
    color: var(--muted);
}

.status-dot {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
    border: 2px solid #0f172a;
    border-radius: 50%;
}

.status-dot.online {
    background: #22c55e;
}

.status-dot.offline {
    background: #ef4444;
}

.device-card dl {
    display: grid;
    gap: 10px;
    margin: 0;
}

.device-card dl div {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    gap: 12px;
}

.device-card dt {
    color: #64748b;
}

.device-card dd {
    margin: 0;
    overflow: hidden;
    color: #0f172a;
    font-weight: 850;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.device-card.is-hidden-device {
    border-style: dashed;
    opacity: .88;
}

.device-card.is-hidden-device .status-dot {
    border-color: #64748b;
}

.rules-list {
    display: grid;
    gap: 14px;
}

.rule-card {
    padding: 22px;
    background: rgba(255, 255, 255, .96);
    border: 1px solid rgba(219, 229, 239, .96);
    border-radius: 8px;
    box-shadow: var(--shadow-soft);
}

.rule-card.is-disabled {
    opacity: .82;
    border-style: dashed;
}

.rule-card h3 {
    margin: 0 0 12px;
    color: #0f172a;
}

.rule-main {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.rule-main p {
    margin: 0;
    color: var(--muted);
    font-weight: 800;
}

.rule-meta {
    display: grid;
    gap: 8px;
    color: var(--muted);
}

.pill {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 0 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 950;
}

.pill.enabled {
    color: #166534;
    background: #dcfce7;
}

.pill.disabled {
    color: #475569;
    background: #e2e8f0;
}

.rule-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
}

.empty {
    padding: 22px;
    color: var(--muted);
    background: rgba(255, 255, 255, .92);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.empty.compact {
    width: 100%;
    padding: 12px;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 22px;
    background: rgba(15, 23, 42, .42);
}

.modal-content {
    width: min(680px, 100%);
    max-height: min(760px, 92vh);
    overflow: auto;
    padding: 24px;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.small-modal {
    width: min(520px, 100%);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.modal-header h2 {
    margin: 0;
}

.modal-content label {
    display: grid;
    gap: 8px;
    margin-bottom: 14px;
    color: #334155;
    font-weight: 850;
}

.modal-content input,
.modal-content select {
    min-height: 44px;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 12px;
    background: #ffffff;
}

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

.toggle-row,
.apply-option {
    display: flex !important;
    align-items: center;
    gap: 10px !important;
}

.toggle-row input,
.apply-option input {
    width: auto;
    min-height: auto;
}

.field-title {
    margin: 14px 0 8px;
    color: #334155;
    font-weight: 900;
}

.apply-mode,
.chip-grid,
.device-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip-grid label,
.device-picker label,
.apply-option {
    padding: 10px 12px;
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
}

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

@media (max-width: 1160px) {
    .stats {
        grid-template-columns: repeat(2, minmax(160px, 1fr));
    }

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

    .family-device-grid,
    .devices-grid {
        grid-template-columns: repeat(2, minmax(220px, 1fr));
    }
}

@media (max-width: 820px) {
    body {
        background: #f6f9fc;
    }

    .layout {
        display: block;
        padding-bottom: 76px;
    }

    .sidebar {
        position: fixed;
        inset: auto 12px 12px;
        z-index: 10;
        height: 64px;
        padding: 8px;
        background: rgba(20, 61, 70, .96);
        border: 1px solid rgba(255, 255, 255, .16);
        border-radius: 8px;
        box-shadow: 0 14px 34px rgba(15, 23, 42, .20);
    }

    .brand {
        display: none;
    }

    .sidebar nav {
        grid-template-columns: repeat(3, 1fr);
        height: 100%;
        gap: 6px;
    }

    .menu {
        min-height: 48px;
        justify-content: center;
        gap: 6px;
        padding: 0 8px;
        font-size: 13px;
    }

    .menu-icon {
        width: 26px;
        height: 26px;
        font-size: 13px;
    }

    .content {
        padding: 24px 16px 96px;
    }

    .page-title {
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .page-title h1 {
        width: 100%;
        font-size: 38px;
    }

    .top-user {
        margin-left: 0;
    }

    .stats,
    .family-device-grid,
    .devices-grid {
        grid-template-columns: 1fr;
    }

    .family-internet-card {
        grid-template-columns: 1fr;
        padding: 20px;
    }

    .internet-actions {
        min-width: 0;
    }

    .section-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .device-head h3 {
        white-space: normal;
    }
}

@media (max-width: 520px) {
    .auth-card {
        padding: 22px !important;
    }

    .auth-actions,
    .modal-actions,
    .card-actions {
        flex-direction: column;
        align-items: stretch;
    }

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

    .device-card dl div {
        grid-template-columns: 1fr;
        gap: 3px;
    }

    .device-card dd {
        text-align: left;
    }
}
