/* Application shell: sidebar, admin top bar, main column, page head. */
.app {
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh;
}

/* ---------- sidebar ---------- */
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column;
  background: var(--sidebar); border-right: 1px solid var(--line);
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 22px 24px 26px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 34px; height: 30px; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; }
.brand-sub { color: var(--text-2); font-size: 12px; line-height: 1.3; white-space: nowrap; }
.nav-toggle {
  display: none; place-items: center; width: 40px; height: 40px; flex-shrink: 0;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: transparent; color: var(--text);
}
.nav-toggle .icon { width: 22px; height: 22px; }
.sidebar-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 0 14px 18px; }

.nav { display: flex; flex-direction: column; gap: 6px; }
.nav a {
  display: flex; align-items: center; gap: 14px; padding: 10px 14px; border-radius: 10px;
  color: var(--text-2); font-size: 15px; text-decoration: none;
}
.nav a .icon { width: 20px; height: 20px; }
.nav a:hover { background: var(--nav-hover); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--nav-active); color: var(--blue-text); }
.nav a.active .icon { color: var(--blue); }

.sidebar-bottom { margin-top: auto; padding-top: 24px; display: flex; flex-direction: column; gap: 18px; }
.user { display: flex; align-items: center; gap: 12px; padding: 4px 8px; min-width: 0; }
.user > div { min-width: 0; }
.avatar {
  display: grid; place-items: center; width: 44px; height: 44px; flex-shrink: 0; border-radius: 50%;
  background: linear-gradient(135deg, #2b3a55, #1a2436); border: 1px solid var(--line-2);
  color: var(--text); font-weight: 600;
}
.avatar.sm { width: 36px; height: 36px; font-size: 13px; }
.user .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user .role { color: var(--text-2); font-size: 13px; }
.logout-form { margin: 0; }
.logout {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 6px 10px;
  border: 0; border-radius: var(--radius-sm); background: none; color: var(--text-2); font-size: 15px; text-align: left;
}
.logout .icon { width: 20px; height: 20px; }
.logout:hover { color: var(--text); background: var(--nav-hover); }
.version-card {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  color: var(--text-2); font-size: 13px; line-height: 1.45;
}
.version-card .faint { font-family: var(--font-mono); font-size: 12px; }

/* admin: the brand block lines up with the top bar */
.app-admin .sidebar-top {
  height: var(--topbar-h); padding: 0 18px 0 22px; margin-bottom: 18px; border-bottom: 1px solid var(--line);
}
.app-admin .brand-mark { width: 36px; height: 31px; }

/* ---------- main column ---------- */
.main-col { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: flex-end; gap: 22px;
  height: var(--topbar-h); padding: 0 22px; border-bottom: 1px solid var(--line);
}
.topbar .status-indicator { color: var(--text-2); font-size: 14px; }
.user-menu-btn {
  display: flex; align-items: center; gap: 10px; padding: 4px 6px 4px 4px;
  border: 0; border-radius: var(--radius-pill); background: none; color: var(--text); font-weight: 500;
}
.user-menu-btn:hover { background: var(--nav-hover); }
.user-menu-btn > .icon { width: 18px; height: 18px; color: var(--text-2); }
.main { flex: 1; display: flex; flex-direction: column; gap: 14px; min-width: 0; padding: 18px 22px 24px; }
.app-admin .main { padding-top: 22px; gap: 16px; }

/* ---------- page head ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.page-title { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.page-title h1 { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; }
.subtitle { margin-top: 2px; color: var(--text-2); font-size: 14px; }
.page-head-aside { display: flex; align-items: center; gap: 12px; }

.clock-card {
  display: flex; align-items: center; gap: 36px; padding: 10px 18px; white-space: nowrap;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
}
.clock-card .label { color: var(--text-2); font-size: 14px; }
.clock-card .time { font-family: var(--font-mono); font-size: 19px; font-weight: 500; letter-spacing: .01em; min-width: 23ch; }
.clock-card .connected { font-size: 15px; color: var(--text-2); }

/* ---------- responsive: < 1024px the sidebar becomes a top bar with a menu ---------- */
@media (max-width: 1023.98px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .sidebar {
    z-index: 40; height: auto; max-height: 100vh; overflow: visible;
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  .sidebar-top, .app-admin .sidebar-top { height: 60px; padding: 0 16px; margin: 0; border-bottom: 0; }
  .brand-mark, .app-admin .brand-mark { width: 30px; height: 26px; }
  .brand-name { font-size: 18px; }
  .nav-toggle { display: grid; }
  .sidebar-panel { display: none; padding: 4px 16px 16px; overflow-y: auto; max-height: calc(100vh - 60px); }
  .sidebar.open .sidebar-panel { display: flex; }
  .sidebar-bottom { padding-top: 16px; margin-top: 12px; border-top: 1px solid var(--line); }
  .topbar { height: 52px; padding: 0 16px; }
  .clock-card { gap: 20px; }
}

@media (max-width: 639.98px) {
  .main, .app-admin .main { padding: 16px; gap: 12px; }
  .page-head { flex-direction: column; gap: 12px; }
  .page-head-aside { width: 100%; }
  .page-title h1 { font-size: 22px; }
  .clock-card { width: 100%; justify-content: space-between; gap: 12px; padding: 10px 14px; }
  .clock-card .time { font-size: 16px; min-width: 0; }
  .topbar { gap: 12px; }
  .topbar .user-name, .brand-sub { display: none; }
}
