:root{
    --bg:#0b1220;
    --bg2:#070b14;
    --card:#121a2b;
    --muted:#a8b3cf;
    --text:#e7ecff;
    --accent:#4f7cff;
    --warn:#ffb020;
    --danger:#ff4d4d;
    --border:#24314f;

    --radius:14px;
    --radius-sm:10px;
    --radius-pill:999px;

    --shadow: 0 8px 24px rgba(0,0,0,.25);
    --shadow-lg: 0 12px 40px rgba(0,0,0,.45);

    --focus: 0 0 0 3px rgba(79,124,255,.18);
}

*,
*::before,
*::after{ box-sizing:border-box; }

html, body{ height:100%; }

body{
    margin:0;
    font-family:system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    background:linear-gradient(180deg,var(--bg),var(--bg2));
    color:var(--text);
}

/* -------- Topbar -------- */
.topbar{
    display:flex;
    justify-content:space-between;
    align-items:center;
    padding:14px 18px;
    border-bottom:1px solid var(--border);
    background:rgba(10,16,30,.7);
    backdrop-filter: blur(8px);
    position:sticky;
    top:0;
    z-index:80;
}

.brand{ font-weight:700; letter-spacing:.2px; }
.me{ display:flex; gap:12px; align-items:center; }

/* -------- Layout -------- */
.container{
    max-width:1100px;
    margin:18px auto;
    padding:0 16px;
}

.card{
    background:var(--card);
    border:1px solid var(--border);
    border-radius:var(--radius);
    padding:16px;
    box-shadow: var(--shadow);
}

.card.inner{ padding:14px; }

h2,h3{ margin:0 0 12px; }

.row{
    display:flex;
    flex-direction:column;
    gap:6px;
    margin:10px 0;
}

.row-inline{
    display:flex;
    gap:10px;
    align-items:center;
    margin:10px 0;
    flex-wrap:wrap;
}

label{
    color:var(--muted);
    font-size:14px;
}

/* -------- Inputs -------- */
input,select,textarea{
    background:#0e1627;
    border:1px solid var(--border);
    color:var(--text);
    border-radius:var(--radius-sm);
    padding:10px 10px;
    outline:none;
}

textarea{ width:100%; resize:vertical; }

input:focus,select:focus,textarea:focus{
    border-color:var(--accent);
    box-shadow: var(--focus);
}

::placeholder{ color:rgba(168,179,207,.75); }

/* -------- Buttons -------- */
.btn{
    background:var(--accent);
    border:none;
    color:white;
    border-radius:var(--radius-sm);
    padding:10px 12px;
    cursor:pointer;
    font-weight:600;
    line-height:1.1;
}

.btn:hover{ filter:brightness(1.05); }

.btn:focus{
    outline:none;
    box-shadow: var(--focus);
}

.btn.ghost{
    background:transparent;
    border:1px solid var(--border);
}

.btn.warn{
    background:var(--warn);
    color:#111;
}

.btn.danger{
    background:transparent;
    border:1px solid rgba(255,77,77,.45);
    color:#ffd2d2;
}

.btn.danger:hover{ background:rgba(255,77,77,.12); }

.danger-btn{
    border-color: rgba(255,77,77,.35) !important;
    color:#ffd2d2;
}
.danger-btn:hover{ background: rgba(255,77,77,.12); }

/* -------- Helpers -------- */
.hidden{ display:none !important; }

.error{
    margin-top:10px;
    padding:10px 12px;
    border-radius:var(--radius-sm);
    border:1px solid rgba(255,77,77,.35);
    background: rgba(255,77,77,.12);
    color:#ffd2d2;
}

.muted{ color:var(--muted); font-size:13px; }
.hint{ color:var(--muted); font-size:13px; }

/* -------- Toolbar & Tabs -------- */
.toolbar{
    display:flex;
    justify-content:space-between;
    align-items:flex-end;
    gap:12px;
    margin-bottom:14px;
    flex-wrap:wrap;
}

.tabs{ display:flex; gap:8px; }

.tab{
    background:transparent;
    border:1px solid var(--border);
    color:var(--text);
    border-radius:var(--radius-pill);
    padding:8px 12px;
    cursor:pointer;
}

.tab:hover{ background:rgba(255,255,255,.03); }

.tab:focus{
    outline:none;
    box-shadow: var(--focus);
}

.tab.active{
    border-color:var(--accent);
    box-shadow: var(--focus);
}

/* -------- Grid -------- */
.grid2{
    display:grid;
    grid-template-columns: 1fr 1fr;
    gap:14px;
}

@media (max-width: 900px){
    .grid2{ grid-template-columns:1fr; }
}

/* -------- Table -------- */
.table{
    width:100%;
    border-collapse:collapse;
    overflow:hidden;
    border-radius:12px;
    border:1px solid var(--border);
}

.table th,.table td{
    padding:10px 10px;
    border-bottom:1px solid var(--border);
    font-size:14px;
}

.table th{
    color:var(--muted);
    text-align:left;
    background:#0f182a;
}

.clickable-row{ cursor:pointer; }
.clickable-row:hover{ background:rgba(255,255,255,.03); }

/* -------- Badges -------- */
.badge{
    display:inline-block;
    padding:3px 8px;
    border-radius:var(--radius-pill);
    border:1px solid var(--border);
    color:var(--muted);
    font-size:12px;
}

.badge.good{ border-color:rgba(79,255,170,.3); color:#bfffe1; }
.badge.warn{ border-color:rgba(255,176,32,.35); color:#ffe6b9; }
.badge.bad{ border-color:rgba(255,77,77,.35); color:#ffd2d2; }

/* -------- Icon buttons -------- */
.icon-btn{
    background:transparent;
    border:1px solid var(--border);
    color:var(--text);
    border-radius:12px;
    padding:8px 10px;
    cursor:pointer;
    line-height:1;
}

.icon-btn:hover{ filter:brightness(1.05); }

.icon-btn:focus{
    outline:none;
    box-shadow: var(--focus);
}

.icon-btn.small{
    padding:6px 8px;
    border-radius:10px;
}

/* ===== Drawer ===== */
.drawer{
    position:fixed;
    top:0;
    left:0;
    height:100vh;
    width:215px;
    max-width:70vw;
    background:linear-gradient(180deg,#0e1627,#0b1220);
    border-right:1px solid var(--border);
    box-shadow: 10px 0 30px rgba(0,0,0,.35);
    z-index:90;

    transform: translateX(-110%);
    transition: transform .18s ease;
    display:flex;
    flex-direction:column;

    overflow:hidden; /* sticky within flex */
}

.drawer.open{ transform: translateX(0); }

/* drawer header now correctly laid out */
.drawer-top{
    position: sticky;
    top: 0;
    z-index: 5;
    background:linear-gradient(180deg,#0e1627,#0b1220);
    border-bottom:1px solid var(--border);

    display:flex;
    align-items:center;
    gap:10px;
    padding:12px;
}

.avatar{
    width:38px;
    height:38px;
    border-radius:12px;
    background:rgba(79,124,255,.15);
    display:flex;
    align-items:center;
    justify-content:center;
    border:1px solid rgba(79,124,255,.25);
}

.drawer-profile{ flex:1; min-width:0; }

.drawer-name{
    font-weight:800;
    font-size:14px;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
}

.drawer-role{
    margin-top:2px;
    color:var(--muted);
    font-size:12px;
}

.drawer-content{
    padding:10px;
    overflow:auto;
    flex: 1;
}

.drawer-item{
    width:100%;
    text-align:left;
    padding:10px 12px;
    border-radius:12px;
    border:1px solid transparent;
    background:transparent;
    color:var(--text);
    cursor:pointer;
    font-weight:600;
}

.drawer-item:hover{
    border-color:var(--border);
    background:rgba(255,255,255,.03);
}

.drawer-block{ margin-top:6px; }

.drawer-item-parent{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:10px;
}

.chev{
    display:inline-block;
    transform: rotate(0deg);
    transition: transform .15s ease;
    color: var(--muted);
    font-size:18px;
    margin-left:auto;
}

.drawer-item-parent.open .chev{ transform: rotate(90deg); }

.drawer-sub{
    margin-top:6px;
    padding-left:10px;
    border-left:1px solid rgba(79,124,255,.25);
}

.drawer-subitem{
    width:100%;
    text-align:left;
    padding:9px 12px;
    border-radius:12px;
    border:1px solid transparent;
    background:transparent;
    color:var(--text);
    cursor:pointer;
    font-weight:600;
    opacity:.95;
}

.drawer-subitem:hover{
    border-color:var(--border);
    background:rgba(255,255,255,.03);
}

/* ===== Modal ===== */
.modal{
    position:fixed;
    inset:0;
    display:flex;
    justify-content:center;
    align-items:flex-start;
    padding:60px 16px 16px;
    z-index:200;
    background:rgba(0,0,0,.35);
    backdrop-filter: blur(2px);
}

.modal-card{
    width:min(720px, 96vw);
    background:linear-gradient(180deg,#0e1627,#0b1220);
    border:1px solid var(--border);
    border-radius:16px;
    box-shadow: var(--shadow-lg);
    overflow:hidden;
}

#formModal .modal-card{
    width:min(400px, 92vw);
}

.modal-head{
    display:flex;
    justify-content:space-between;
    align-items:center;
    padding:14px 14px;
    border-bottom:1px solid var(--border);
}

.modal-title{ font-weight:800; }

.modal-body{ padding:14px; }

.modal-foot{
    display:flex;
    justify-content:flex-end;
    gap:10px;
    padding:14px;
    border-top:1px solid var(--border);
}

.checklist{
    margin-top:10px;
    max-height:360px;
    overflow:auto;
    border:1px solid var(--border);
    border-radius:12px;
    background:rgba(255,255,255,.02);
    padding:8px;
}

.checkitem{
    display:flex;
    align-items:center;
    gap:10px;
    padding:8px 10px;
    border-radius:10px;
}

.checkitem:hover{ background:rgba(255,255,255,.03); }
.checkitem input{ width:16px; height:16px; }

/* ===== Operator layout (kept for future) ===== */
.op-content{ flex:1; min-width:0; }

/* ===== Details (legacy block) ===== */
details{
    border:1px solid var(--border);
    border-radius:var(--radius);
    background:rgba(255,255,255,.02);
}

details > summary{
    list-style:none;
    user-select:none;
}

details > summary::-webkit-details-marker{ display:none; }

details[open] > summary{
    border-bottom:1px solid var(--border);
    border-bottom-left-radius:0;
    border-bottom-right-radius:0;
}

#loginView {
    margin: auto;
    max-width: 440px;
    width: min(520px, calc(100% - 24px));
}

/* На всякий случай: когда показываем appView — пусть занимает ширину */
#appView {
    width: 100%;
}

.drawer-subitem.active {
    background: rgba(90, 140, 255, 0.18);
    color: #e9f0ff;
    border-left: 3px solid rgba(90, 140, 255, 0.9);
    padding-left: calc(12px - 3px);
}

.drawer-item.drawer-item-parent.active {
    background: rgba(90, 140, 255, 0.12);
    color: #e9f0ff;
}

/* ===== Accessibility / motion ===== */
@media (prefers-reduced-motion: reduce){
    *{ transition:none !important; animation:none !important; }
}
