/* =====================================================================
   TPCloud Object Storage Portal — Design System v2
   layout.css: App shell — layout grid, sidebar, topbar, page body
   ===================================================================== */

/* ── Layout ──────────────────────────────────────────────────────── */
:root { --sb-collapsed: 58px; }

.layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
  background: var(--nav-bg);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0;
  width: var(--sb);
  flex-shrink: 0;
  transition: width 0.3s ease;
}

/* Brand */
.sidebar-brand {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: center !important;
  gap: 10px !important;
  width: 100% !important;
  padding: 18px 0 20px 0 !important;
  margin: 0 auto 10px auto !important;
  text-decoration: none !important;
  box-sizing: border-box !important;
  border-bottom: 1px solid var(--nav-border);
  flex-shrink: 0;
}

.sidebar-brand-logo {
  display: block;
  width: auto;
  height: 54px;
  max-width: 345px;
  object-fit: contain;
  margin: 0 auto !important;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.24));
  overflow: hidden;
  transition: opacity 0.22s ease, height 0.3s ease;
}
.sidebar-brand-favicon {
  display: block;
  width: 34px;
  height: 0;
  opacity: 0;
  object-fit: contain;
  margin: 0 auto !important;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.3));
  overflow: hidden;
  transition: opacity 0.22s ease, height 0.3s ease;
}

.sidebar-brand-subtitle {
  display: block;
  width: 100%;
  text-align: center !important;
  font-size: 12px;
  line-height: 1;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.64);
  margin: 0 !important;
  max-height: 24px;
  overflow: hidden;
  transition: opacity 0.22s ease, max-height 0.3s ease;
}

/* Legacy brand icon/text (kept for backward compat) */
.brand-icon {
  width: 34px;
  height: 34px;
  background: var(--brand-icon-bg);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}
.brand-text { line-height: 1.2; }
.brand-name {
  font-size: 14px;
  font-weight: 700;
  color: #FFFFFF;
  letter-spacing: -0.01em;
  display: block;
}
.brand-sub {
  font-size: 10.5px;
  color: var(--nav-label);
  letter-spacing: 0.02em;
  display: block;
  margin-top: 1px;
}

/* Nav */
.sidebar-nav {
  flex: 1;
  padding: 16px 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--nav-label);
  text-transform: uppercase;
  padding: 10px 8px 5px;
  display: block;
  max-height: 36px;
  overflow: hidden;
  transition: opacity 0.22s ease, max-height 0.3s ease, padding-top 0.3s ease, padding-bottom 0.3s ease;
}
.nav-label:first-child { padding-top: 2px; }
.nav-text {
  overflow: hidden;
  white-space: nowrap;
  max-width: 160px;
  transition: opacity 0.2s ease, max-width 0.3s ease;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--nav-item);
  transition: background 0.13s, color 0.13s, padding 0.3s ease, gap 0.3s ease;
  cursor: pointer;
  text-decoration: none;
}
.nav-item:hover {
  background: var(--nav-hover-bg);
  color: var(--nav-hover);
  text-decoration: none;
}
.nav-item.active {
  background: var(--nav-active-bg);
  color: var(--nav-active);
  font-weight: 600;
}
.nav-item.active:hover {
  background: var(--brand-dark);
  text-decoration: none;
}
button.logout-nav-btn {
  width: 100%;
  background: none;
  border: none;
  font-family: inherit;
}
.nav-sep {
  border: none;
  border-top: 1px solid var(--nav-border);
  margin: 10px 0;
}

/* Nav icon */
.nav-icon {
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity 0.13s;
}
.nav-item:hover .nav-icon,
.nav-item.active .nav-icon {
  opacity: 1;
}

/* Sidebar footer / user */
.sidebar-footer {
  padding: 14px 14px 16px;
  border-top: 1px solid var(--nav-border);
  flex-shrink: 0;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-avatar {
  width: 32px;
  height: 32px;
  background: rgba(37,99,235,0.7);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.user-meta { flex: 1; min-width: 0; overflow: hidden; max-width: 160px; transition: opacity 0.22s ease, max-width 0.3s ease; }
.user-meta-name {
  font-size: 12.5px;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-meta-role {
  font-size: 11px;
  color: var(--nav-label);
  text-transform: capitalize;
}
.sidebar-logout {
  font-size: 12px;
  color: var(--nav-label);
  flex-shrink: 0;
  transition: color 0.12s;
}
.sidebar-logout:hover { color: rgba(255,255,255,0.6); text-decoration: none; }

/* ── Main area ───────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

/* ── Topbar ──────────────────────────────────────────────────────── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-left { min-width: 0; }
.page-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.2;
}
.page-desc {
  font-size: 12.5px;
  color: var(--text-sec);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ── Page body ───────────────────────────────────────────────────── */
.page-body {
  padding: 28px 32px 48px;
  flex: 1;
}

/* ── Section title ───────────────────────────────────────────────── */
.section-title {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 12px;
}

/* ── Sidebar toggle button ───────────────────────────────────────── */
.sidebar-brand { position: relative; }
.sb-toggle {
  position: absolute;
  top: 12px;
  right: 10px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 6px;
  color: rgba(255,255,255,0.45);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  z-index: 1;
}
.sb-toggle:hover { background: rgba(255,255,255,0.16); color: rgba(255,255,255,0.9); }
.sb-toggle-icon { flex-shrink: 0; transition: transform 0.22s ease; }

/* ── Collapsed sidebar ───────────────────────────────────────────── */
body.sb-collapsed .sidebar { width: var(--sb-collapsed); }
body.sb-collapsed .sidebar-brand {
  padding: 12px 0 10px !important;
  gap: 6px !important;
  margin-bottom: 4px !important;
}
body.sb-collapsed .sidebar-brand-logo { opacity: 0; height: 0; }
body.sb-collapsed .sidebar-brand-favicon { opacity: 1; height: 28px; }
body.sb-collapsed .sidebar-brand-subtitle { opacity: 0; max-height: 0; }
body.sb-collapsed .sb-toggle {
  position: static;
  top: auto;
  right: auto;
  margin: 0 auto;
}
body.sb-collapsed .sb-toggle-icon { transform: rotate(180deg); }
body.sb-collapsed .nav-label { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; }
body.sb-collapsed .nav-text { opacity: 0; max-width: 0; }
body.sb-collapsed .nav-sep { margin: 6px 8px; }
body.sb-collapsed .nav-item { justify-content: center; padding: 9px; gap: 0; }
body.sb-collapsed .sidebar-footer { padding: 10px 0; }
body.sb-collapsed .sidebar-user { justify-content: center; }
body.sb-collapsed .user-meta { opacity: 0; max-width: 0; }

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  :root { --sb: 220px; }
  .page-body { padding: 24px 24px 40px; }
  .topbar { padding: 0 24px; }
  .kpi-grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .sidebar { display: none; }
  .kpi-grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-2 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar-brand {
    padding: 16px 0 18px 0 !important;
    margin: 0 auto 8px auto !important;
    gap: 8px !important;
  }
  .sidebar-brand-logo {
    height: 45px;
    max-width: 285px;
  }
  .sidebar-brand-subtitle {
    font-size: 11px;
  }
}
@media (max-width: 640px) {
  .page-body { padding: 16px 16px 32px; }
  .topbar { padding: 0 16px; height: auto; min-height: 56px; flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
  .kpi-grid.cols-2,
  .kpi-grid.cols-3,
  .kpi-grid.cols-4 { grid-template-columns: 1fr; }
}
