/* NexusOS — Segment 3: headerbars, titlebars, window controls, window chrome.
   Headerbars use the alt surface to distinguish chrome from content.
   Buttons in headerbars default to flat; close button warns red on hover. */

/* ── Window ──────────────────────────────────────────────── */

window,
window.background {
    background-color: @base_bg;
    color: @text_primary;
}

window:backdrop {
    background-color: @base_bg;
    color: @text_secondary;
}

/* CSD (client-side decorated) windows — rounded corners + subtle border */
window.csd {
    border-radius: 8px;
    box-shadow: 0 0 0 1px @border,
                0 8px 24px rgba(0, 0, 0, 0.45),
                0 2px 6px  rgba(0, 0, 0, 0.30);
}

window.csd:backdrop {
    box-shadow: 0 0 0 1px @border,
                0 4px 12px rgba(0, 0, 0, 0.30);
}

window.ssd {
    /* server-side decorated — leave decoration to WM */
    box-shadow: none;
}

/* Maximized / tiled / fullscreen — no rounded corners, no shadow */
window.maximized,
window.tiled,
window.tiled-top,
window.tiled-bottom,
window.tiled-left,
window.tiled-right,
window.fullscreen {
    border-radius: 0;
    box-shadow: none;
}

/* ── Headerbar / titlebar ────────────────────────────────── */

headerbar,
.titlebar {
    padding: 4px 6px;
    min-height: 38px;
    border: none;
    border-bottom: 1px solid @border;
    background-color: @surface_bg_alt;
    background-image: none;
    color: @text_primary;
    box-shadow: none;
    text-shadow: none;
}

headerbar:backdrop,
.titlebar:backdrop {
    background-color: @surface_bg;
    color: @text_secondary;
    border-bottom-color: @border;
}

/* Rounded top corners on CSD headerbars */
window.csd > headerbar:first-child,
window.csd > .titlebar:first-child,
window.csd > deck > headerbar:first-child,
window.csd > box > headerbar:first-child {
    border-top-left-radius: 7px;
    border-top-right-radius: 7px;
}

window.maximized > headerbar,
window.tiled    > headerbar,
window.fullscreen > headerbar {
    border-radius: 0;
}

/* Title / subtitle text */
headerbar .title,
.titlebar .title {
    font-weight: 600;
    color: @text_primary;
    padding: 0 12px;
}

headerbar .subtitle,
.titlebar .subtitle {
    font-size: smaller;
    color: @text_secondary;
    padding: 0 12px;
}

headerbar:backdrop .title,
.titlebar:backdrop .title,
headerbar:backdrop .subtitle,
.titlebar:backdrop .subtitle {
    color: @text_secondary;
}

/* Separator between title and other widgets */
headerbar separator.titlebutton,
.titlebar separator.titlebutton {
    background-color: @border;
    min-width: 1px;
    margin: 6px 4px;
}

/* ── Buttons inside headerbars ───────────────────────────── */

headerbar button,
.titlebar button {
    padding: 4px 8px;
    min-height: 24px;
    border: 1px solid transparent;
    background-color: transparent;
    background-image: none;
    color: @text_primary;
    box-shadow: none;
}

headerbar button:hover,
.titlebar button:hover {
    background-color: @hover_bg;
    border-color: transparent;
    color: @text_primary;
}

headerbar button:active,
headerbar button:checked,
.titlebar button:active,
.titlebar button:checked {
    background-color: @active_bg;
    border-color: transparent;
    color: @active_fg;
}

headerbar button:disabled,
.titlebar button:disabled {
    background-color: transparent;
    color: @text_disabled;
}

headerbar button:focus,
.titlebar button:focus {
    outline: 2px solid @focus_ring;
    outline-offset: -2px;
}

headerbar button:backdrop,
.titlebar button:backdrop {
    color: @text_secondary;
}

/* Suggested-action in a headerbar keeps its solid lime fill */
headerbar button.suggested-action,
.titlebar button.suggested-action {
    background-color: @brand_green;
    border-color: @brand_green_dark;
    color: @text_on_accent;
}

headerbar button.suggested-action:hover,
.titlebar button.suggested-action:hover {
    background-color: @brand_green_light;
    color: @text_on_accent;
}

headerbar button.destructive-action,
.titlebar button.destructive-action {
    background-color: @error_color;
    color: #ffffff;
}

/* Entries in headerbars — pick up the alt surface */
headerbar entry,
.titlebar entry {
    background-color: @base_bg;
    border-color: @border_strong;
}

headerbar entry:focus,
.titlebar entry:focus {
    border-color: @brand_green;
    box-shadow: inset 0 0 0 1px @brand_green;
}

/* ── Window control buttons (close, min, max) ────────────── */

.titlebutton,
headerbar button.titlebutton,
.titlebar button.titlebutton,
button.titlebutton {
    min-width: 22px;
    min-height: 22px;
    padding: 4px;
    margin: 0 2px;
    border-radius: 999px;          /* circular control dots */
    border: 1px solid transparent;
    background-color: alpha(@text_primary, 0.08);
    color: @text_primary;
    -gtk-icon-shadow: none;
}

.titlebutton:hover,
headerbar button.titlebutton:hover,
.titlebar button.titlebutton:hover {
    background-color: @hover_bg;
    border-color: @brand_green_dark;
    color: @text_primary;
}

.titlebutton:active,
.titlebutton:checked {
    background-color: @active_bg;
    border-color: @brand_green_dark;
    color: @active_fg;
}

.titlebutton:backdrop,
.titlebutton:disabled {
    background-color: alpha(@text_primary, 0.04);
    color: @text_disabled;
    border-color: transparent;
}

/* Close button — warn red on hover so it can't be confused with accent actions */
.titlebutton.close,
button.titlebutton.close {
    background-color: alpha(@error_color, 0.18);
    color: @text_primary;
}

.titlebutton.close:hover,
button.titlebutton.close:hover {
    background-color: @error_color;
    border-color: shade(@error_color, 0.85);
    color: #ffffff;
}

.titlebutton.close:active,
button.titlebutton.close:active {
    background-color: shade(@error_color, 0.85);
    color: #ffffff;
}

.titlebutton.close:backdrop {
    background-color: alpha(@error_color, 0.10);
    color: @text_disabled;
}

/* Minimize / maximize — explicit selectors in case theming engines key off them */
.titlebutton.minimize:hover,
.titlebutton.maximize:hover,
button.titlebutton.minimize:hover,
button.titlebutton.maximize:hover {
    background-color: @hover_bg;
    border-color: @brand_green_dark;
    color: @text_primary;
}

/* ── Stack-of-headerbars (e.g. libhandy/libadwaita-style split) ── */

headerbar.flat {
    background-color: transparent;
    border-bottom-color: transparent;
}

/* Selection-mode headerbar (e.g. when picking files) — purple to match selection accent */
headerbar.selection-mode,
.titlebar.selection-mode {
    background-color: @brand_purple_dark;
    color: @selected_fg;
    border-bottom-color: @brand_purple;
}

headerbar.selection-mode .title,
.titlebar.selection-mode .title,
headerbar.selection-mode .subtitle,
.titlebar.selection-mode .subtitle {
    color: @selected_fg;
}

headerbar.selection-mode button,
.titlebar.selection-mode button {
    color: @selected_fg;
}

headerbar.selection-mode button:hover,
.titlebar.selection-mode button:hover {
    background-color: alpha(@selected_fg, 0.15);
}
