:root {
    --primary: #0056d2;
    --primary-dark: #0045a9;
    --primary-soft: #e9f1ff;
    --ink: #172033;
    --muted: #667085;
    --line: #e5e9f2;
    --surface: #ffffff;
    --canvas: #f6f8fc;
    --danger: #c9302c;
    --danger-soft: #fff0ef;
    --success: #12783d;
    --success-soft: #eaf8ef;
    --warning: #a65a00;
    --warning-soft: #fff6e6;
    --shadow: 0 14px 36px rgba(20, 45, 92, .08);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
    min-height: 100%;
    margin: 0;
    color: var(--ink);
    background: var(--canvas);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

button, input, select, textarea { font: inherit; }
button, .btn { cursor: pointer; }

:focus-visible {
    outline: 3px solid rgba(0, 86, 210, .32);
    outline-offset: 2px;
}

.layout { min-height: 100vh; }

.sidebar {
    position: fixed;
    z-index: 30;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    width: 272px;
    padding: 24px 14px 18px;
    color: #f7f9ff;
    background: #102a5c;
}

.brand, .auth-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    color: inherit;
}

.brand { padding: 5px 11px 24px; }
.brand:hover { color: #fff; }

.brand-mark {
    display: grid;
    flex: 0 0 38px;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 12px;
    color: #fff;
    background: var(--primary);
    font-size: 18px;
    font-weight: 800;
}

.brand strong, .auth-brand strong { display: block; font-size: 17px; line-height: 1.1; }
.brand small { display: block; margin-top: 3px; color: #afc3ea; font-size: 12px; }

.guardian-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 7px 22px;
    padding: 10px;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 14px;
    background: rgba(255,255,255,.07);
}

.guardian-avatar, .user-avatar {
    display: grid;
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: 50%;
    color: var(--primary);
    background: #e5efff;
    font-weight: 800;
}

.guardian-chip strong { display: block; overflow: hidden; max-width: 170px; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.guardian-chip span { display: block; margin-top: 1px; color: #afc3ea; font-size: 12px; }

.nav-label {
    margin: 17px 12px 7px;
    color: #9fb5df;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.side-nav { display: grid; gap: 3px; }

.side-nav a, .logout-link {
    display: flex;
    align-items: center;
    min-height: 43px;
    padding: 0 12px;
    border-radius: 10px;
    color: #d8e4fb;
    font-size: 14px;
    font-weight: 650;
}

.side-nav a span, .logout-link span {
    display: inline-grid;
    width: 22px;
    margin-right: 8px;
    place-items: center;
    color: #a8c4f5;
    font-size: 16px;
}

.side-nav a:hover, .side-nav a.active, .logout-link:hover {
    color: #fff;
    background: rgba(255,255,255,.12);
}

.side-nav a.active {
    box-shadow: inset 3px 0 0 #67a4ff;
    background: rgba(0, 86, 210, .62);
}

.sidebar-footer { margin-top: auto; padding: 18px 7px 0; }
.logout-link { color: #ffd6d6; }
.logout-link:hover { background: rgba(201, 48, 44, .22); }

.nav-backdrop { display: none; }

.content {
    min-height: 100vh;
    margin-left: 272px;
    padding: 0 clamp(20px, 4vw, 54px) 42px;
}

.topbar {
    position: sticky;
    z-index: 20;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 82px;
    margin: 0 calc(clamp(20px, 4vw, 54px) * -1);
    padding: 0 clamp(20px, 4vw, 54px);
    border-bottom: 1px solid rgba(229, 233, 242, .86);
    background: rgba(246, 248, 252, .92);
    backdrop-filter: blur(14px);
}

.topbar-left, .topbar-actions { display: flex; align-items: center; gap: 13px; }
.topbar h1 { margin: 0; font-size: clamp(20px, 2vw, 27px); letter-spacing: -.03em; }
.eyebrow { margin: 0 0 1px; color: var(--primary); font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }

.menu-toggle {
    display: none;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 9px;
    color: var(--ink);
    background: var(--surface);
    font-size: 21px;
}

.icon-button {
    display: grid;
    width: 39px;
    height: 39px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 50%;
    color: var(--ink);
    background: var(--surface);
    font-size: 18px;
}

.icon-button:hover { border-color: #b7c8e6; background: var(--primary-soft); }
.user-avatar { width: 39px; height: 39px; font-size: 14px; }
.alert-link, .top-avatar {
    display: grid;
    width: 39px;
    height: 39px;
    place-items: center;
    border-radius: 50%;
}
.alert-link { border: 1px solid var(--line); color: var(--ink); background: var(--surface); }
.alert-link:hover { color: var(--primary); background: var(--primary-soft); }
.top-avatar { color: var(--primary); background: #e5efff; font-size: 14px; font-weight: 800; }

.page-content { width: 100%; max-width: 1440px; margin: 31px auto 0; }

h2, h3, h4 { color: var(--ink); letter-spacing: -.02em; }
h2 { margin: 0 0 18px; font-size: clamp(22px, 2.5vw, 31px); }
h3 { margin: 0 0 13px; font-size: 18px; }
h4 { margin: 0 0 8px; font-size: 15px; }
p { margin-top: 0; }

.header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 22px;
}

.header-row > :last-child { flex-shrink: 0; }

.cards, .task-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 16px;
}

.card, .panel {
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.card { min-height: 122px; padding: 21px; }
.card .small { display: block; margin-bottom: 7px; }
.card strong { display: block; font-size: 27px; line-height: 1.2; }
.panel { margin-bottom: 19px; padding: clamp(18px, 2.5vw, 27px); }

.panel > :last-child { margin-bottom: 0; }

.auth-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding: 64px 20px;
    color: var(--ink);
}

.auth-brand { margin-bottom: 22px; color: var(--ink); }
.auth-brand:hover { color: var(--primary); }
.auth-brand .brand-mark { background: var(--primary); }
.auth-brand small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }

.auth-card {
    width: min(100%, 475px);
    padding: clamp(25px, 5vw, 40px);
    border: 1px solid var(--line);
    border-radius: 22px;
    background: var(--surface);
    box-shadow: 0 22px 60px rgba(22, 42, 80, .1);
}

.auth-card h1 { margin-top: 0; font-size: 28px; }

.form-group { margin-bottom: 17px; }
.form-group label { display: block; margin-bottom: 7px; color: #34415d; font-size: 13px; font-weight: 750; }

input, select, textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid #cbd5e5;
    border-radius: 10px;
    outline: none;
    color: var(--ink);
    background: #fff;
}

textarea { min-height: 94px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,86,210,.12); }

button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 42px;
    padding: 9px 15px;
    border: 1px solid var(--primary);
    border-radius: 10px;
    color: #fff;
    background: var(--primary);
    font-size: 14px;
    font-weight: 750;
    line-height: 1.2;
    transition: background .18s ease, border-color .18s ease, transform .18s ease;
}

button:hover, .btn:hover { border-color: var(--primary-dark); color: #fff; background: var(--primary-dark); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled, .btn:disabled { cursor: not-allowed; opacity: .56; }

.btn-secondary { border-color: #c7d2e5; color: #33435f; background: #fff; }
.btn-secondary:hover { border-color: #aab9d1; color: #24344e; background: #f4f7fc; }
.btn-danger { border-color: var(--danger); background: var(--danger); }
.btn-danger:hover { border-color: #aa201c; background: #aa201c; }

.inline-form, .search-form {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 10px;
}

.inline-form .form-group, .search-form .form-group { flex: 1 1 180px; margin: 0; }

.table-wrapper { overflow-x: auto; margin: 0 -2px; border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: #52627e; background: #f7f9fd; font-size: 11px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcff; }

.alert { margin: 0 0 18px; padding: 12px 14px; border-radius: 11px; font-size: 14px; }
.alert-error { border: 1px solid #fac9c7; color: #8d201d; background: var(--danger-soft); }
.alert-success { border: 1px solid #b8e6c7; color: #12633a; background: var(--success-soft); }

.badge, .status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 25px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 750;
    white-space: nowrap;
}

.badge-high { color: #9f241f; background: #ffe8e6; }
.badge-medium { color: #8d5700; background: #fff2d4; }
.badge-low, .badge-info { color: #165aaf; background: #e9f2ff; }
.status-pill { color: #12633a; background: var(--success-soft); }

.app-icon, .app-icon-fallback {
    display: inline-grid;
    width: 42px;
    height: 42px;
    place-items: center;
    overflow: hidden;
    border-radius: 11px;
    color: var(--primary);
    background: var(--primary-soft);
    font-size: 14px;
    font-weight: 800;
    vertical-align: middle;
}

.app-icon { object-fit: cover; }
.code-box { display: inline-block; padding: 11px 15px; border: 1px dashed #91afd9; border-radius: 11px; color: var(--primary-dark); background: #f5f9ff; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 18px; font-weight: 850; letter-spacing: .12em; }

.battery { display: inline-flex; align-items: center; gap: 7px; }
.battery-bar { width: 66px; height: 8px; overflow: hidden; border-radius: 99px; background: #e5eaf3; }
.battery-level { height: 100%; border-radius: inherit; background: var(--success); }
.battery-low { background: var(--danger); }
.battery-medium { background: #d98700; }

.empty { padding: 35px 18px; color: var(--muted); text-align: center; }
.small, .muted { color: var(--muted); font-size: 13px; }

@media (max-width: 900px) {
    .sidebar {
        width: min(286px, calc(100vw - 52px));
        box-shadow: 16px 0 40px rgba(10, 30, 69, .22);
        transform: translateX(-105%);
        transition: transform .22s ease;
    }

    body.menu-open { overflow: hidden; }
    body.menu-open .sidebar { transform: translateX(0); }
    .nav-backdrop { position: fixed; z-index: 25; inset: 0; background: rgba(9, 21, 47, .48); }
    body.menu-open .nav-backdrop { display: block; }
    .content { margin-left: 0; padding: 0 20px 32px; }
    .topbar { min-height: 70px; margin: 0 -20px; padding: 0 20px; }
    .menu-toggle { display: grid; place-items: center; }
    .page-content { margin-top: 24px; }
}

@media (max-width: 620px) {
    .topbar h1 { font-size: 20px; }
    .topbar-actions { gap: 8px; }
    .user-avatar { width: 35px; height: 35px; }
    .icon-button { width: 35px; height: 35px; }
    .header-row { display: block; }
    .header-row > :last-child { display: inline-flex; margin-top: 12px; }
    .panel { padding: 17px; border-radius: 14px; }
    .card { padding: 18px; }
    th, td { padding: 11px; }
    .inline-form > .btn, .search-form > .btn { width: 100%; }
    .auth-content { padding: 42px 18px; }
    .auth-card { padding: 25px 20px; }
}
