/* ══════════════════════════════════════════════
   Shared Shell Layout — sidebar + topbar + content
   Used by ALL pages via <link rel="stylesheet" href="/css/layout.css">
   ══════════════════════════════════════════════ */

/* ── Body shell ── */
:root {
    --sidebar-width: 240px;
}

body.hub-page {
    background: var(--hub-shell-bg);
    display: flex;
    flex-direction: row;
    min-height: 100vh;
    height: 100vh;
    overflow: hidden;
}

body.hub-page.dashboard-page {
    background: var(--hub-shell-bg-dashboard);
}

/* On non-home pages the <header> lives inside hub-content —
   strip the old gradient / shadow styles.                    */
body.hub-page header {
    background: transparent;
    color: inherit;
    padding: 0;
    margin-bottom: 16px;
    box-shadow: none;
    border: none;
}

body.hub-page header .header-content {
    padding: 0;
    gap: 8px;
}

body.hub-page footer { display: none; }

/* Override the container width inside the shell */
body.hub-page .container {
    width: 100%;
    max-width: 100%;
    padding: 0;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--hub-sidebar-bg);
    border-right: 1px solid var(--hub-border);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 12px 10px 16px;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-controls {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin: 0 0 8px;
    padding-right: 4px;
}

.sidebar-collapse-toggle {
    appearance: none;
    border: 1px solid var(--hub-border);
    border-radius: 8px;
    background: var(--hub-sidebar-bg);
    color: var(--hub-text-muted);
    font-size: 0.75rem;
    line-height: 1;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.sidebar-collapse-toggle:hover {
    background: var(--hub-hover-bg);
    color: var(--hub-text-strong);
}

.sidebar-resize-handle {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    width: 8px;
    height: 100vh;
    margin-left: -4px;
    cursor: col-resize;
    z-index: 150;
}

.sidebar-resize-handle::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 3px;
    width: 2px;
    background: transparent;
    transition: background 0.15s;
}

.sidebar-resize-handle:hover::before,
body.sidebar-resizing .sidebar-resize-handle::before {
    background: var(--hub-border);
}

body.sidebar-resizing,
body.sidebar-resizing * {
    cursor: col-resize !important;
    user-select: none;
}

.sidebar-logo {
    width: 36px;
    height: 36px;
    margin: 0 0 6px 4px;
}

.sidebar-brand {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--hub-text-strong);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 12px;
    text-align: left;
    line-height: 1.2;
    padding-left: 4px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    width: 100%;
}

.sidebar-link {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    width: 100%;
    border-radius: 8px;
    text-decoration: none;
    color: var(--hub-text-muted);
    font-size: 0.82rem;
    font-weight: 500;
    text-align: left;
    line-height: 1.2;
    transition: background 0.15s, color 0.15s;
}

.sidebar-link:hover {
    background: var(--hub-hover-bg);
    color: var(--hub-text-strong);
}

.sidebar-link.active {
    background: var(--hub-active-bg);
    color: #2CA01C;
}

.sidebar-icon {
    font-size: 1rem;
    line-height: 1;
    width: 18px;
    text-align: center;
}

.sidebar-subnav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 2px 0 6px;
    padding-left: 28px;
}

.sidebar-tab-link {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--hub-text-muted);
    font-size: 0.76rem;
    font-weight: 500;
    line-height: 1.2;
    text-align: left;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.sidebar-tab-link:hover {
    background: var(--hub-hover-bg);
    color: var(--hub-text-strong);
}

.sidebar-tab-link.active {
    background: var(--hub-active-bg);
    color: #2CA01C;
}

.sidebar-divider {
    width: 100%;
    height: 1px;
    background: var(--hub-border);
    margin: 8px 0;
}

.sidebar-section-label {
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 4px 0 2px;
    padding-left: 10px;
}

/* ── Topbar ── */
.topbar {
    min-height: 76px;
    height: auto;
    background: var(--hub-topbar-bg);
    border-bottom: 1px solid var(--hub-border);
    display: flex;
    align-items: center;
    padding: 10px 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 2200;
    overflow: visible;
    flex-shrink: 0;
}

.topbar-brand {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--hub-text-strong);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-brand.topbar-page-heading {
    align-items: flex-start;
    gap: 10px;
    white-space: normal;
}

.topbar-title-stack {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.15;
}

.topbar-page-title {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--hub-text-strong);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 420px;
}

.topbar-page-subtitle {
    font-size: 0.74rem;
    font-weight: 500;
    color: var(--hub-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 520px;
}

.topbar-brand img {
    width: 22px;
    height: 22px;
}

.topbar-search {
    flex: 1;
    max-width: 520px;
    margin: 0 auto;
    position: relative;
}

.topbar-search input {
    width: 100%;
    padding: 8px 14px 8px 36px;
    border: 1px solid var(--hub-border);
    border-radius: 8px;
    font-size: 0.88rem;
    color: var(--text-primary);
    background: var(--bg-tertiary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") 10px center no-repeat;
    outline: none;
    transition: border-color 0.15s;
}

.topbar-search input:focus {
    border-color: #0077C5;
    background-color: var(--bg-primary);
}

.topbar-search-feedback {
    margin-top: 6px;
    font-size: 0.75rem;
    line-height: 1.25;
    color: var(--text-secondary);
}

.topbar-search-feedback[data-state="success"] {
    color: var(--success);
}

.topbar-search-feedback[data-state="error"] {
    color: var(--error);
}

.hub-search-highlight {
    outline: 2px solid var(--uno-blue);
    outline-offset: 3px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

.topbar-search input::placeholder {
    color: var(--text-muted);
}

.topbar-breadcrumb {
    font-size: 0.82rem;
    color: var(--hub-text-muted);
    display: flex;
    align-items: center;
    gap: 0;
}

.topbar-breadcrumb a {
    color: var(--hub-text-muted);
    text-decoration: none;
    transition: color 0.15s;
}

.topbar-breadcrumb a:hover {
    color: var(--hub-text-strong);
    text-decoration: underline;
}

.topbar-breadcrumb .sep {
    margin: 0 0.35rem;
    color: var(--text-muted);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

.topbar-dashboard-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.topbar-dashboard-controls .timeframe-selector {
    margin: 0;
}

.topbar-dashboard-controls .timeframe-selector select {
    min-width: 118px;
    height: 32px;
}

.topbar-dashboard-controls .timeframe-selector label {
    font-size: 0.78rem;
    color: var(--hub-text-muted);
}

.topbar-dashboard-controls .btn-toggle-queries,
.topbar-dashboard-controls #refresh-data {
    padding: 6px 10px;
    font-size: 0.78rem;
    line-height: 1.2;
    min-height: 32px;
    white-space: nowrap;
}

.topbar-icon-btn {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--hub-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.topbar-icon-btn:hover {
    background: var(--hub-hover-bg);
}

.topbar-icon-btn.active {
    background: var(--hub-hover-bg);
    color: var(--hub-text-strong);
}

.theme-settings-menu {
    position: fixed;
    width: 220px;
    background: var(--bg-primary);
    border: 1px solid var(--hub-border);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    padding: 8px;
    z-index: 2600;
}

.theme-settings-group {
    position: relative;
}

.theme-settings-parent {
    cursor: pointer;
    pointer-events: auto;
    width: 100%;
    appearance: none;
    border: none;
    background: transparent;
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.85rem;
    text-align: left;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background 0.15s, color 0.15s;
}

.theme-settings-parent:hover {
    background: var(--hub-hover-bg);
}

.theme-settings-parent::after {
    content: '\25B8';
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: 8px;
}

.theme-settings-parent.expanded::after {
    content: '\25BE';
}

.theme-settings-children {
    position: fixed;
    width: 160px;
    background: var(--bg-primary);
    border: 1px solid var(--hub-border);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    padding: 6px;
    z-index: 2610;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.theme-settings-children[hidden] {
    display: none;
}

.theme-settings-title {
    margin: 2px 6px 8px;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

.dashboard-settings-title {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--hub-border);
}

.theme-settings-option {
    width: 100%;
    appearance: none;
    border: none;
    background: transparent;
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.85rem;
    text-align: left;
    padding: 8px 10px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.theme-settings-option:hover {
    background: var(--hub-hover-bg);
}

.theme-settings-option.active {
    background: var(--hub-active-bg);
    color: #2CA01C;
    font-weight: 600;
}

.topbar-avatar {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    background: #2CA01C;
    color: #ffffff;
    font-size: 0.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

body.hub-page #user-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

body.hub-page #user-info .loading-text {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ── Main shell ── */
.hub-shell {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    height: 100vh;
    overflow: hidden;
}

.hub-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 28px 32px 40px;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

body.dashboard-page .hub-content {
    max-width: none;
    padding: 20px 24px 28px;
}

body.dashboard-page .tabs[role="tablist"],
body.dashboard-page .tab-navigation {
    display: none !important;
}

body.hub-page .legacy-header-title-is-topbar {
    display: none !important;
}

body.hub-page header.legacy-header-empty {
    display: none;
    margin: 0;
}

body.hub-page.sidebar-collapsed {
    --sidebar-width: 72px;
}

body.hub-page.sidebar-collapsed .sidebar {
    align-items: center;
    padding-left: 8px;
    padding-right: 8px;
}

body.hub-page.sidebar-collapsed .sidebar-controls {
    width: 100%;
    justify-content: center;
    padding-right: 0;
}

body.hub-page.sidebar-collapsed .sidebar-logo,
body.hub-page.sidebar-collapsed .sidebar-brand,
body.hub-page.sidebar-collapsed .sidebar-section-label,
body.hub-page.sidebar-collapsed .sidebar-subnav,
body.hub-page.sidebar-collapsed .sidebar-divider {
    display: none;
}

body.hub-page.sidebar-collapsed .sidebar-nav {
    align-items: center;
}

body.hub-page.sidebar-collapsed .sidebar-link {
    justify-content: center;
    font-size: 0;
    gap: 0;
    padding-left: 0;
    padding-right: 0;
    width: 48px;
    height: 40px;
}

body.hub-page.sidebar-collapsed .sidebar-icon {
    width: auto;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .sidebar-resize-handle { display: none; }
    .hub-shell { margin-left: 0; }
    .hub-content { padding: 20px 16px 32px; }
    .topbar-search { display: none; }
    .topbar-breadcrumb { font-size: 0.75rem; }
}
