:root {
    color-scheme: light;
    --bg: #f7f4ff;
    --card: #ffffff;
    --text: #1f2333;
    --muted: #747b94;
    --line: #ece8f7;
    --primary: #7b8cff;
    --primary-2: #95a6ff;
    --primary-hover: #6d7eff;
    --ok: #2a7f5f;
    --ok-bg: #e4f8ef;
    --off: #a65c6e;
    --off-bg: #fdeaf0;
    --shadow: 0 14px 30px rgba(71, 80, 130, 0.12);
    --radius: 16px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(1200px 700px at 8% -10%, #efe9ff 0%, transparent 65%),
        radial-gradient(1000px 650px at 95% 10%, #e6f7ff 0%, transparent 60%),
        linear-gradient(180deg, #faf7ff 0%, var(--bg) 100%);
    color: var(--text);
    line-height: 1.4;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 280px 1fr;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    background: linear-gradient(165deg, #ffffff 0%, #f4f2ff 55%, #eef6ff 100%);
    color: var(--text);
    padding: 22px 16px;
    border-right: 1px solid var(--line);
    box-shadow: inset -1px 0 0 rgba(180, 170, 230, 0.15);
}

.brand {
    font-weight: 700;
    font-size: 21px;
    margin-bottom: 18px;
    padding: 0 10px;
    color: #4753a6;
}

.menu {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.menu-item {
    color: #50556c;
    text-decoration: none;
    padding: 11px 13px;
    border-radius: 12px;
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

.menu-item:hover,
.menu-item.active {
    background: linear-gradient(135deg, #f3eeff 0%, #eaf3ff 100%);
    border-color: #ddd6fa;
    color: #2f3560;
    transform: translateX(2px);
}

.content-area {
    display: flex;
    flex-direction: column;
    min-width: 0;
    width: 100%;
    overflow-x: hidden;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 24px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px);
}

.topbar p {
    margin: 4px 0 0;
}

.page {
    width: 100%;
    max-width: none;
    margin: 18px 0 0;
    padding: 0 22px 24px;
    animation: pageFade 0.25s ease;
}

.page.page-admin {
    margin-top: 14px;
}

.card {
    background: linear-gradient(180deg, #ffffff 0%, #fcfbff 100%);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    width: 100%;
    min-width: 0;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 18px 34px rgba(71, 80, 130, 0.14);
}

.auth-card {
    max-width: 460px;
    margin: 0 auto;
}

h1 {
    margin: 0 0 6px;
    font-size: 30px;
    letter-spacing: -0.02em;
}

.muted {
    color: var(--muted);
}

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

.form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 20px 0;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    align-items: end;
}

label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 14px;
}

input {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 11px 12px;
    font-size: 14px;
    outline: none;
    background: #fff;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

select {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 14px;
    background: #fff;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(123, 140, 255, 0.18);
}

.checkbox {
    flex-direction: row;
    align-items: center;
}

button {
    border: none;
    border-radius: 12px;
    padding: 11px 14px;
    font-weight: 600;
    cursor: pointer;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-2) 100%);
    color: #fff;
    transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
    box-shadow: 0 8px 18px rgba(123, 140, 255, 0.35);
}

button:hover {
    filter: brightness(1.03);
    transform: translateY(-1px);
}

button.ghost {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--line);
    box-shadow: none;
}

button.ghost:hover {
    background: #f6f4ff;
}

a.ghost {
    display: inline-block;
    text-decoration: none;
    background: #fff;
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 9px 12px;
    font-size: 14px;
    margin-left: 6px;
    transition: all 0.2s ease;
}

a.ghost:hover {
    background: #f6f4ff;
    transform: translateY(-1px);
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    font-size: 14px;
}

thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: linear-gradient(180deg, #fbfaff 0%, #f7f4ff 100%);
}

pre.json-cell {
    margin: 8px 0 0;
    padding: 10px;
    background: #f7f4ff;
    border: 1px solid var(--line);
    border-radius: 10px;
    max-width: 520px;
    max-height: 280px;
    overflow: auto;
    font-size: 12px;
    white-space: pre;
}

.center {
    text-align: center;
}

.badge {
    display: inline-flex;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.badge.ok {
    color: var(--ok);
    background: var(--ok-bg);
}

.badge.off {
    color: var(--off);
    background: var(--off-bg);
}

.alerts {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
    animation: slideDown 0.24s ease;
}

.alert {
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 14px;
    border: 1px solid transparent;
}

.alert.success {
    color: #166534;
    background: #dcfce7;
    border-color: #86efac;
}

.alert.error {
    color: #991b1b;
    background: #fee2e2;
    border-color: #fca5a5;
}

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

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

@media (max-width: 980px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: sticky;
        top: 0;
        height: auto;
        z-index: 30;
        border-right: none;
        border-bottom: 1px solid var(--line);
    }

    .menu {
        flex-direction: row;
        overflow-x: auto;
    }

    .topbar {
        top: 68px;
    }

    .page {
        padding: 0 12px 20px;
    }
}

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