* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #f5f5f2;
    --surface: #ffffff;
    --surface-soft: #f8f8f6;
    --ink: #0b0b0b;
    --muted: #676767;
    --faint: #e4e4df;
    --line: #d8d8d1;
    --green: #16803c;
    --green-bg: #e8f7ed;
    --red: #c42b2b;
    --red-bg: #faeaea;
    --amber: #a16207;
    --amber-bg: #fff6db;
    --shadow: 0 18px 55px rgba(12, 12, 12, 0.12);
    --shadow-sm: 0 8px 24px rgba(12, 12, 12, 0.08);
    --radius: 8px;
}

body {
    min-height: 100vh;
    background:
        radial-gradient(circle at 12% 8%, rgba(0, 0, 0, 0.08), transparent 23rem),
        linear-gradient(180deg, #ffffff 0%, var(--bg) 55%);
    color: var(--ink);
    font-family: "Manrope", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    line-height: 1.5;
}

button,
input {
    font: inherit;
}

button {
    user-select: none;
}

.page {
    min-height: 100vh;
}

#dashboard-page {
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

#card-view-page {
    height: 100vh;
    flex-direction: column;
    overflow: hidden;
}

.login-container {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 1.5rem;
    background:
        radial-gradient(circle at 50% 42%, rgba(190, 197, 212, 0.2), transparent 18rem),
        linear-gradient(135deg, #f7f8fb 0%, #eef1f6 100%);
}

.login-box {
    position: relative;
    width: min(100%, 430px);
    overflow: hidden;
    padding: 3rem 2rem 1.55rem;
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 24px 70px rgba(44, 54, 74, 0.14);
}

.login-box::before {
    display: none;
}

.login-box h1 {
    color: #121827;
    font-size: 2.08rem;
    font-weight: 900;
    line-height: 1.1;
    text-align: center;
}

.subtitle {
    margin: 0.65rem 0 1.35rem;
    color: #69748b;
    font-size: 0.95rem;
    text-align: center;
}

#login-form {
    display: grid;
    gap: 0.7rem;
}

.form-group {
    display: grid;
    gap: 0.42rem;
}

.form-group label {
    color: #2c364c;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.form-group input {
    width: 100%;
    min-height: 52px;
    padding: 0.9rem 1rem;
    border: 1px solid #e7eaf1;
    border-radius: 14px;
    background: #f5f7fb;
    color: #121827;
    outline: none;
    box-shadow: inset 0 1px 2px rgba(17, 24, 39, 0.03);
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.form-group input:focus {
    border-color: #c8cfdd;
    background: #ffffff;
    box-shadow: 0 0 0 4px rgba(18, 24, 39, 0.07);
}

.form-group input::placeholder {
    color: #98a3b8;
}

.form-group input.invalid {
    border-color: var(--red);
    background: var(--red-bg);
}

.field-error,
.error-message {
    color: var(--red);
    font-size: 0.78rem;
    font-weight: 700;
}

.field-error:empty,
.error-message:empty {
    display: none;
}

.error-message {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.login-credit {
    margin-top: 2.15rem;
    color: #8c96ad;
    font-size: 0.88rem;
    text-align: center;
}

.btn {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.72rem 1rem;
    border: 1px solid transparent;
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.86rem;
    font-weight: 850;
    line-height: 1;
    transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--ink);
    color: #ffffff;
}

.btn-secondary {
    border-color: var(--line);
    background: #ffffff;
    color: var(--ink);
}

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

.btn-small {
    min-height: 36px;
    padding: 0.58rem 0.75rem;
    font-size: 0.78rem;
}

.btn-block {
    width: 100%;
}

.login-box .btn-primary {
    min-height: 56px;
    margin-top: 0.15rem;
    border-radius: 999px;
    background: #101827;
    box-shadow: 0 14px 26px rgba(16, 24, 39, 0.2);
    font-size: 0.92rem;
}

.login-box .btn-primary:hover {
    box-shadow: 0 18px 32px rgba(16, 24, 39, 0.24);
}

.top-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.95rem 1.5rem;
    min-height: 74px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(16px);
}

.top-bar h1 {
    font-size: 1.28rem;
    font-weight: 950;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.top-bar-right {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
}

.card-view-bar {
    flex: 0 0 auto;
}

.card-view-frame-wrap {
    flex: 1;
    min-height: 0;
    padding: 0;
    background: #ffffff;
}

#card-view-frame {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    background: #ffffff;
}

.dashboard-container {
    display: grid;
    grid-template-columns: minmax(520px, 620px) minmax(420px, 680px);
    gap: 1.25rem;
    width: 100%;
    height: calc(100vh - 74px);
    max-width: 1340px;
    margin: 0 auto;
    padding: 1.25rem;
    overflow: hidden;
}

.card-list-section {
    display: flex;
    min-height: 0;
    flex-direction: column;
}

.section-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.85rem;
}

.section-heading h2 {
    font-size: 0.96rem;
    font-weight: 950;
    text-transform: uppercase;
}

.section-subtitle,
.channel-meta,
.empty-state {
    color: var(--muted);
    font-size: 0.88rem;
}

.filter-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.filter-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
}

.filter-tab {
    min-height: 38px;
    padding: 0 1rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.78);
    color: var(--muted);
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 800;
    transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.filter-tab.active {
    border-color: var(--ink);
    background: var(--ink);
    color: #ffffff;
    box-shadow: 0 10px 24px rgba(11, 11, 11, 0.16);
}

.card-list {
    display: grid;
    flex: 1;
    align-content: start;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 0.25rem;
    gap: 0.65rem;
}

.card-item {
    position: relative;
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.88);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.035);
    cursor: pointer;
    transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.card-item:hover {
    transform: translateY(-2px);
    border-color: #a9a9a2;
    background: #ffffff;
    box-shadow: var(--shadow-sm);
}

.card-item.active {
    border-color: #9b9b93;
    background: linear-gradient(180deg, #ffffff, #fbfbf8);
    box-shadow: 0 14px 34px rgba(12, 12, 12, 0.1);
}

.card-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.8rem;
}

.card-item-name {
    display: block;
    font-size: 0.95rem;
    font-weight: 950;
}

.card-type {
    display: inline-flex;
    margin-top: 0.18rem;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 750;
    text-transform: capitalize;
}

.card-item-details {
    display: flex;
    align-items: center;
    min-height: 40px;
    padding-right: 8rem;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 750;
}

.card-item-actions {
    position: absolute;
    right: 1rem;
    bottom: 1rem;
    display: flex;
    gap: 0.55rem;
}

.btn-icon svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.open-text-action,
.reboot-text-action {
    display: inline-flex;
    min-width: 78px;
    height: 38px;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 999px;
    background: var(--ink);
    color: #ffffff;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 850;
    transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.open-text-action {
    background: var(--ink);
    color: #ffffff;
}

.reboot-text-action {
    background: var(--red);
    color: #ffffff;
}

.open-text-action:hover,
.reboot-text-action:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn-icon-text {
    min-height: 38px;
    padding: 0.55rem 0.85rem;
    white-space: nowrap;
}

.btn-icon {
    display: inline-grid;
    place-items: center;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: 26px;
    padding: 0.26rem 0.7rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 950;
    white-space: nowrap;
}

.status-pill::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.status-pill.online {
    background: var(--green-bg);
    color: var(--green);
}

.status-pill.offline {
    background: var(--red-bg);
    color: var(--red);
}

.status-pill.rebooting,
.status-pill.checking {
    background: var(--amber-bg);
    color: var(--amber);
}

.channel-details-section {
    min-width: 0;
    align-self: start;
    margin-top: 7.1rem;
    max-height: calc(100vh - 114px);
    overflow: auto;
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.86);
    box-shadow: var(--shadow-sm);
}

#channel-header {
    display: grid;
    gap: 0.25rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--line);
}

#channel-header h2 {
    font-size: 1.06rem;
    font-weight: 950;
}

.channel-list {
    display: none;
    margin-top: 0.85rem;
    overflow-x: auto;
}

.channel-list.active {
    display: block;
}

.channel-table {
    width: 100%;
    min-width: 560px;
    border-collapse: separate;
    border-spacing: 0;
}

.channel-table thead {
    background: var(--ink);
    color: #ffffff;
}

.channel-table th,
.channel-table td {
    padding: 0.68rem 0.7rem;
    text-align: left;
}

.channel-table th {
    font-size: 0.75rem;
    font-weight: 950;
    text-transform: uppercase;
}

.channel-table td {
    border-bottom: 1px solid var(--line);
    font-size: 0.88rem;
}

.channel-table tbody tr:hover {
    background: var(--surface-soft);
}

.empty-state {
    padding: 1.25rem 0;
}

.toast-container {
    position: fixed;
    top: 1rem;
    left: 50%;
    z-index: 9999;
    display: grid;
    gap: 0.7rem;
    transform: translateX(-50%);
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: min(390px, calc(100vw - 2rem));
    padding: 0.9rem 1rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: var(--shadow-sm);
    animation: slideIn 0.2s ease-out;
}

.toast.success,
.toast.info {
    border-color: rgba(22, 128, 60, 0.25);
    background: var(--green-bg);
    color: var(--green);
}

.toast.error {
    border-color: rgba(196, 43, 43, 0.25);
    background: var(--red-bg);
    color: var(--red);
}

.toast.warning {
    border-left-color: var(--amber);
}

.toast-close {
    margin-left: auto;
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-size: 1.2rem;
}

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

.modal {
    position: fixed;
    inset: 0;
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.62);
    backdrop-filter: blur(8px);
}

.modal-content {
    width: min(100%, 440px);
    padding: 1.35rem;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: var(--shadow);
}

.modal-content h2 {
    margin-bottom: 0.55rem;
    font-size: 1.2rem;
    font-weight: 950;
}

.modal-content p {
    margin-bottom: 1.2rem;
    color: var(--muted);
}

.modal-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.7rem;
}

@media (max-width: 820px) {
    #dashboard-page {
        height: auto;
        overflow: visible;
    }

    #card-view-page {
        height: 100vh;
        overflow: hidden;
    }

    .top-bar {
        position: static;
        align-items: stretch;
        flex-direction: column;
    }

    .top-bar-right {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }

    .dashboard-container {
        grid-template-columns: 1fr;
        height: auto;
        overflow: visible;
        padding: 1rem;
    }

    .card-list {
        overflow: visible;
    }

    .channel-details-section {
        margin-top: 0;
        max-height: none;
    }
}

@media (max-width: 520px) {
    .login-box {
        padding: 1.55rem;
    }

    .login-box h1 {
        font-size: 1.62rem;
    }

    .top-bar-right,
    .modal-buttons {
        grid-template-columns: 1fr;
    }

    .card-item-details {
        padding-right: 0;
    }

    .card-item-actions {
        position: static;
        margin-top: 0.75rem;
    }

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

    .toast-container {
        right: 0.75rem;
        left: 0.75rem;
        transform: none;
    }

    .toast {
        width: 100%;
    }
}
