/* MDC UI Library — standardized component styles */

/* ── Snap Layouts preview overlay (Phase 1 desktop redesign, §D.6) ─────────
 * Single shared, reused element repositioned per active snap zone by
 * MDCLib.makeDraggable()'s extended drag logic below. Sits above every
 * window/modal/menu z-index in this app so it's always visible mid-drag.
 */
.mdc-snap-preview {
    position: fixed;
    display: none;
    background: rgba(0, 120, 212, 0.28);
    border: 2px solid var(--win11-accent, #0078d4);
    border-radius: var(--win11-radius-md, 8px);
    box-shadow: var(--win11-shadow-flyout, 0 8px 32px rgba(0,0,0,0.5));
    pointer-events: none;
    z-index: 10050;
}

/* ── Program Window ──────────────────────────────────────────── */
/* Frame (own background + backdrop-filter) — Win11 acrylic per Phase 1's
 * desktop redesign (§D.3). Scoped to the frame only; every content-bearing
 * sub-element below (.mdc-toolbar/.mdc-sidebar/.mdc-content/.mdc-statusbar/
 * .mdc-input/.mdc-btn/.mdc-modal* /.mdc-tab-bar/.mdc-table*) stays solid/
 * opaque and only picks up geometry/font tokens, mirroring real Windows 11
 * Mica/acrylic apps (translucent frame, opaque content pane).
 */
.mdc-program {
    position: absolute;
    display: none;
    flex-direction: column;
    background: var(--win11-bg-acrylic-light, rgba(255, 255, 255, 0.72));
    backdrop-filter: var(--win11-blur, blur(24px) saturate(165%));
    -webkit-backdrop-filter: var(--win11-blur, blur(24px) saturate(165%));
    border: 1px solid var(--win11-border-subtle-light, rgba(0, 0, 0, 0.12));
    border-radius: var(--win11-radius-lg, 12px);
    box-shadow: var(--win11-shadow-window, 0 32px 80px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.08));
    /* Round-2 runtime fix (Runtime Finding #6): !important is required here
     * because frontend/css/fonts.css's pre-existing, untouched blanket rule
     * (`:root, body, body * { font-family: 'Courier New',... !important; }`)
     * always beats a non-!important declaration regardless of specificity —
     * scoped narrowly to this chrome/frame selector only, not a blanket
     * override of fonts.css for the rest of the app.
     */
    font-family: var(--win11-font, 'Segoe UI', 'Segoe UI Variable', Tahoma, Geneva, Verdana, sans-serif) !important;
    font-size: 12px;
    z-index: 1000;
    min-width: 200px;
    min-height: 100px;
    overflow: hidden;
}

.mdc-program.mdc-open {
    display: flex;
}

/* ── Title Bar (frame — acrylic) ────────────────────────────────── */
.mdc-title-bar {
    width: 100%;
    box-sizing: border-box;
    height: 30px;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.32));
    border-bottom: 1px solid var(--win11-border-subtle-light, rgba(0, 0, 0, 0.12));
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px;
    /* Round-2 runtime fix (Runtime Finding #6): see .mdc-program's comment
     * above for why !important is required and why it's scoped narrowly. */
    font-family: var(--win11-font, 'Segoe UI', 'Segoe UI Variable', Tahoma, Geneva, Verdana, sans-serif) !important;
    font-size: 12px;
    font-weight: 600;
    color: #1a1a1a;
    box-shadow: none;
    cursor: move;
    user-select: none;
    flex-shrink: 0;
}

/* Round-2 runtime fix (Runtime Finding #6): frontend/css/fonts.css's
 * `body *` blanket !important rule directly matches every descendant of the
 * title bar too (icon/text/buttons), not just .mdc-title-bar itself —
 * inheriting from .mdc-title-bar's own font-family isn't enough, since a
 * directly-matching declaration (even from a low-specificity universal
 * selector) always wins over an inherited value. Each descendant needs its
 * own directly-matching, higher-specificity !important declaration to
 * actually render the Segoe UI stack. Scoped to .mdc-title-bar's own
 * subtree only — does not touch .mdc-content/.mdc-toolbar/etc.
 */
.mdc-title-bar,
.mdc-title-bar * {
    font-family: var(--win11-font, 'Segoe UI', 'Segoe UI Variable', Tahoma, Geneva, Verdana, sans-serif) !important;
}

.mdc-title-bar-left {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    flex: 1;
    min-width: 0;
}

.mdc-title-icon {
    height: 16px;
    width: 16px;
    display: inline-block;
    flex-shrink: 0;
    font-size: 14px;
    line-height: 1;
}

.mdc-title-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mdc-title-buttons {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
    margin-left: 8px;
}

.mdc-title-btn {
    width: 16px;
    height: 16px;
    background: rgba(0, 0, 0, 0.06);
    border: 1px solid var(--win11-border-subtle-light, rgba(0, 0, 0, 0.12));
    color: #333;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: var(--win11-radius-sm, 6px);
    line-height: 1;
    transition: background 0.12s ease;
}

.mdc-title-btn:hover {
    background: rgba(0, 0, 0, 0.12);
}

.mdc-title-btn:active {
    background: rgba(0, 0, 0, 0.18);
    box-shadow: none;
}

/* Accessibility fix (design spec §7): every title-bar button needs a
 * visible keyboard-focus ring — not present here before this run. Covers
 * the new .mdc-maximize-btn too (no separate rule needed, matches
 * .mdc-title-btn's own box model exactly, per Implementation Plan Phase 5c
 * — "no new geometry needed beyond the extra button slot"). */
.mdc-title-btn:focus-visible {
    outline: 2px solid #000;
    outline-offset: 2px;
}

.mdc-title-btn.mdc-close-btn:hover {
    background: #e81123;
    color: #fff;
    border-color: #e81123;
}

/* ── Toolbar ─────────────────────────────────────────────────── */
.mdc-toolbar {
    width: 100%;
    box-sizing: border-box;
    height: 28px;
    background: linear-gradient(to bottom, #f5f5f5, #e8e8e8);
    border-bottom: 1px solid #aaa;
    display: flex;
    align-items: center;
    padding: 0 6px;
    gap: 4px;
    flex-shrink: 0;
}

.mdc-toolbar-separator {
    width: 1px;
    height: 18px;
    background: #aaa;
    margin: 0 4px;
}

/* ── Body / Content area ─────────────────────────────────────── */
.mdc-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.mdc-sidebar {
    width: 140px;
    flex-shrink: 0;
    background: #e8e8e8;
    border-right: 1px solid #aaa;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.mdc-sidebar-section {
    padding: 4px 0;
    border-bottom: 1px solid #ccc;
}

.mdc-sidebar-header {
    padding: 4px 8px;
    font-size: 10px;
    font-weight: bold;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mdc-sidebar-item {
    padding: 5px 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: #222;
    user-select: none;
}

.mdc-sidebar-item:hover {
    background: #d0d8e8;
}

.mdc-sidebar-item.mdc-active {
    background: #b8c8e0;
    font-weight: bold;
}

.mdc-sidebar-item-icon {
    font-size: 13px;
    flex-shrink: 0;
}

/* ── Content ─────────────────────────────────────────────────── */
.mdc-content {
    flex: 1;
    overflow: auto;
    padding: 8px;
    background: #fff;
}

/* ── Status Bar ──────────────────────────────────────────────── */
.mdc-statusbar {
    width: 100%;
    box-sizing: border-box;
    height: 22px;
    background: linear-gradient(to bottom, #e0e0e0, #d0d0d0);
    border-top: 1px solid #aaa;
    display: flex;
    align-items: center;
    padding: 0 8px;
    gap: 12px;
    font-size: 10px;
    color: #444;
    flex-shrink: 0;
}

.mdc-statusbar-item {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.mdc-statusbar-separator {
    width: 1px;
    height: 12px;
    background: #aaa;
}

.mdc-statusbar-item.mdc-status-ready { color: #228822; }
.mdc-statusbar-item.mdc-status-warn  { color: #886600; }
.mdc-statusbar-item.mdc-status-error { color: #882222; }

/* ── Buttons ─────────────────────────────────────────────────── */
.mdc-btn {
    padding: 3px 10px;
    background: linear-gradient(to bottom, #f0f0f0, #d8d8d8);
    border: 1px solid #888;
    color: #111;
    font-family: var(--win11-font, 'Segoe UI', 'Segoe UI Variable', Tahoma, Geneva, Verdana, sans-serif);
    font-size: 11px;
    cursor: pointer;
    border-radius: var(--win11-radius-sm, 6px);
    white-space: nowrap;
    user-select: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.mdc-btn:hover {
    background: linear-gradient(to bottom, #e0e8f0, #c8d8e8);
    border-color: #5580aa;
}

.mdc-btn:active {
    background: #b0c0d0;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.2);
}

.mdc-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.mdc-btn-primary {
    background: linear-gradient(to bottom, #5580cc, #3360aa);
    border-color: #2244aa;
    color: #fff;
}

.mdc-btn-primary:hover {
    background: linear-gradient(to bottom, #6690dd, #4470bb);
}

.mdc-btn-success {
    background: linear-gradient(to bottom, #44aa44, #228822);
    border-color: #116611;
    color: #fff;
}

.mdc-btn-success:hover {
    background: linear-gradient(to bottom, #55bb55, #339933);
}

.mdc-btn-danger {
    background: linear-gradient(to bottom, #cc4444, #aa2222);
    border-color: #881111;
    color: #fff;
}

.mdc-btn-danger:hover {
    background: linear-gradient(to bottom, #dd5555, #bb3333);
}

/* ── Modal / Dialog ──────────────────────────────────────────── */
.mdc-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9900;
}

.mdc-modal {
    background: #f0f0f0;
    border: 1px solid #888;
    border-radius: var(--win11-radius-md, 8px);
    box-shadow: var(--win11-shadow-window, 4px 4px 0 rgba(0,0,0,0.4));
    min-width: 280px;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    font-family: var(--win11-font, 'Segoe UI', 'Segoe UI Variable', Tahoma, Geneva, Verdana, sans-serif);
    font-size: 12px;
    overflow: hidden;
}

.mdc-modal-title-bar {
    height: 28px;
    background: linear-gradient(to bottom, #e6e6e6, #cccccc);
    border-bottom: 2px solid #666;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px;
    font-size: 11px;
    font-weight: bold;
    user-select: none;
}

.mdc-modal-body {
    padding: 16px;
    color: #111;
    line-height: 1.5;
}

.mdc-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    padding: 8px 12px;
    background: #e4e4e4;
    border-top: 1px solid #bbb;
}

/* ── Input / Form elements ───────────────────────────────────── */
.mdc-input {
    font-family: var(--win11-font, 'Segoe UI', 'Segoe UI Variable', Tahoma, Geneva, Verdana, sans-serif);
    font-size: 11px;
    border: 1px solid #888;
    background: #fff;
    padding: 3px 6px;
    color: #111;
    border-radius: var(--win11-radius-sm, 6px);
    box-sizing: border-box;
}

.mdc-input:focus {
    outline: none;
    border-color: #3360aa;
    box-shadow: 0 0 0 1px #3360aa;
}

.mdc-label {
    font-size: 11px;
    color: #333;
    font-weight: bold;
    display: block;
    margin-bottom: 2px;
}

.mdc-field {
    margin-bottom: 8px;
    display: flex;
    flex-direction: column;
}

/* ── Panel (labeled box) ─────────────────────────────────────── */
.mdc-panel {
    border: 1px solid #aaa;
    background: #fafafa;
    margin-bottom: 8px;
}

.mdc-panel-header {
    background: linear-gradient(to bottom, #e0e0e0, #d0d0d0);
    border-bottom: 1px solid #aaa;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: bold;
    color: #333;
    user-select: none;
}

.mdc-panel-body {
    padding: 8px;
}

/* ── Tabs ────────────────────────────────────────────────────── */
.mdc-tabs {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.mdc-tab-bar {
    display: flex;
    background: linear-gradient(to bottom, #e0e0e0, #d0d0d0);
    border-bottom: 2px solid #888;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.mdc-tab {
    padding: 5px 14px;
    font-family: var(--win11-font, 'Segoe UI', 'Segoe UI Variable', Tahoma, Geneva, Verdana, sans-serif);
    font-size: 11px;
    font-weight: bold;
    color: #555;
    background: linear-gradient(to bottom, #d8d8d8, #c8c8c8);
    border: 1px solid #999;
    border-bottom: none;
    border-top-left-radius: var(--win11-radius-sm, 6px);
    border-top-right-radius: var(--win11-radius-sm, 6px);
    cursor: pointer;
    user-select: none;
    margin-right: 2px;
    margin-top: 3px;
    display: flex;
    align-items: center;
    gap: 5px;
    position: relative;
    bottom: -2px;
}

.mdc-tab:hover {
    background: linear-gradient(to bottom, #e8e8e8, #d8d8d8);
    color: #222;
}

.mdc-tab.mdc-active {
    background: #f5f5f5;
    color: #111;
    border-bottom: 2px solid #f5f5f5;
    z-index: 1;
}

.mdc-tab-icon {
    font-size: 13px;
}

.mdc-tab-panels {
    flex: 1;
    min-height: 0;
    position: relative;
}

.mdc-tab-panel {
    display: none;
    height: 100%;
    overflow: auto;
    padding: 8px;
}

.mdc-tab-panel.mdc-active {
    display: block;
}

/* ── Data Table ──────────────────────────────────────────────── */
.mdc-table-wrap {
    position: relative;
    font-family: var(--win11-font, 'Segoe UI', 'Segoe UI Variable', Tahoma, Geneva, Verdana, sans-serif);
    font-size: 11px;
    border: 1px solid #aaa;
    border-radius: var(--win11-radius-sm, 6px);
    background: #fff;
}

.mdc-table {
    width: 100%;
    border-collapse: collapse;
}

.mdc-table th {
    background: linear-gradient(to bottom, #d8d8d8, #c8c8c8);
    border: 1px solid #aaa;
    padding: 4px 8px;
    text-align: left;
    font-weight: bold;
    color: #222;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.mdc-table th:hover {
    background: linear-gradient(to bottom, #e0e0e0, #d0d0d0);
}

.mdc-table th .mdc-sort-icon {
    margin-left: 4px;
    opacity: 0.5;
    font-style: normal;
}

.mdc-table th.mdc-sort-asc .mdc-sort-icon,
.mdc-table th.mdc-sort-desc .mdc-sort-icon {
    opacity: 1;
}

.mdc-table td {
    border: 1px solid #e0e0e0;
    padding: 3px 8px;
    color: #111;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
}

.mdc-table tr:nth-child(even) td {
    background: #f7f7f7;
}

.mdc-table tr:hover td {
    background: #e8f0f8;
    cursor: pointer;
}

.mdc-table tr.mdc-selected td {
    background: #ccddf0;
}

.mdc-table-empty {
    text-align: center;
    padding: 20px;
    color: #888;
    font-size: 11px;
    font-style: italic;
}

.mdc-table-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(240,240,240,0.75);
    font-size: 12px;
    color: #555;
    gap: 8px;
}

/* ── Loading overlay ─────────────────────────────────────────── */
.mdc-loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(240,240,240,0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    font-family: var(--win11-font, 'Segoe UI', 'Segoe UI Variable', Tahoma, Geneva, Verdana, sans-serif);
    font-size: 11px;
    color: #555;
    gap: 8px;
}

.mdc-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #ccc;
    border-top-color: #555;
    border-radius: 50%;
    animation: mdc-spin 0.7s linear infinite;
}

@keyframes mdc-spin {
    to { transform: rotate(360deg); }
}

/* ── Badge ───────────────────────────────────────────────────── */
.mdc-badge {
    display: inline-block;
    padding: 1px 6px;
    font-family: var(--win11-font, 'Segoe UI', 'Segoe UI Variable', Tahoma, Geneva, Verdana, sans-serif);
    font-size: 10px;
    font-weight: bold;
    letter-spacing: 0.3px;
    border: 1px solid transparent;
    border-radius: var(--win11-radius-sm, 6px);
    line-height: 16px;
    vertical-align: middle;
    white-space: nowrap;
}

.mdc-badge-default  { background: #e0e0e0; color: #333; border-color: #aaa; }
.mdc-badge-info     { background: #c8ddf0; color: #1a4a7a; border-color: #7aaddd; }
.mdc-badge-success  { background: #c0e8c0; color: #1a5a1a; border-color: #6ab86a; }
.mdc-badge-warn     { background: #f0e8b0; color: #6a5000; border-color: #c0a830; }
.mdc-badge-danger   { background: #f0c0c0; color: #7a0000; border-color: #cc6666; }
.mdc-badge-dark     { background: #333; color: #eee; border-color: #111; }

/* ── Dark-mode overrides ─────────────────────────────────────── */
/* Frame (.mdc-program/.mdc-title-bar/.mdc-title-btn) — full Win11 acrylic-
 * dark treatment (translucent + blur), matching the taskbar/Start Menu's
 * already-good acrylic look, per Phase 1's desktop redesign (§D.3). Same
 * frame-only scope boundary as the light-default retrofit above — every
 * content-bearing sub-element below this stays solid/opaque.
 */
body.dark-mode .mdc-program,
body.night-mode .mdc-program {
    background: var(--win11-bg-acrylic-dark, rgba(32, 32, 32, 0.85));
    backdrop-filter: var(--win11-blur, blur(24px) saturate(165%));
    -webkit-backdrop-filter: var(--win11-blur, blur(24px) saturate(165%));
    border-color: var(--win11-border-subtle, rgba(255, 255, 255, 0.12));
}

body.dark-mode .mdc-title-bar,
body.night-mode .mdc-title-bar {
    background: linear-gradient(to bottom, rgba(58, 58, 58, 0.55), rgba(42, 42, 42, 0.4));
    border-bottom-color: var(--win11-border-subtle, rgba(255, 255, 255, 0.12));
    color: #eee;
}

body.dark-mode .mdc-title-btn,
body.night-mode .mdc-title-btn {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--win11-border-subtle, rgba(255, 255, 255, 0.12));
    color: #ccc;
}

body.dark-mode .mdc-title-btn:hover,
body.night-mode .mdc-title-btn:hover {
    background: rgba(255, 255, 255, 0.16);
}

body.dark-mode .mdc-title-btn:focus-visible,
body.night-mode .mdc-title-btn:focus-visible {
    outline-color: #fff;
}

body.dark-mode .mdc-title-btn.mdc-close-btn:hover,
body.night-mode .mdc-title-btn.mdc-close-btn:hover {
    background: #e81123;
    color: #fff;
    border-color: #e81123;
}

body.dark-mode .mdc-toolbar,
body.night-mode .mdc-toolbar {
    background: linear-gradient(to bottom, #2c2c2c, #222);
    border-bottom-color: #444;
}

body.dark-mode .mdc-sidebar,
body.night-mode .mdc-sidebar {
    background: #252525;
    border-right-color: #444;
}

body.dark-mode .mdc-sidebar-item,
body.night-mode .mdc-sidebar-item {
    color: #ccc;
}

body.dark-mode .mdc-sidebar-item:hover,
body.night-mode .mdc-sidebar-item:hover {
    background: #2e3a4e;
}

body.dark-mode .mdc-content,
body.night-mode .mdc-content {
    background: #1a1a1a;
    color: #ddd;
}

body.dark-mode .mdc-statusbar,
body.night-mode .mdc-statusbar {
    background: linear-gradient(to bottom, #2a2a2a, #222);
    border-top-color: #444;
    color: #aaa;
}

body.dark-mode .mdc-input,
body.night-mode .mdc-input {
    background: #2a2a2a;
    border-color: #555;
    color: #eee;
}

body.dark-mode .mdc-btn,
body.night-mode .mdc-btn {
    background: linear-gradient(to bottom, #3a3a3a, #2a2a2a);
    border-color: #555;
    color: #eee;
}

body.dark-mode .mdc-modal,
body.night-mode .mdc-modal {
    background: #2a2a2a;
    border-color: #555;
}

body.dark-mode .mdc-modal-title-bar,
body.night-mode .mdc-modal-title-bar {
    background: linear-gradient(to bottom, #3a3a3a, #2a2a2a);
    border-bottom-color: #111;
    color: #eee;
}

body.dark-mode .mdc-modal-body,
body.night-mode .mdc-modal-body {
    color: #ddd;
}

body.dark-mode .mdc-modal-footer,
body.night-mode .mdc-modal-footer {
    background: #222;
    border-top-color: #444;
}

body.dark-mode .mdc-tab-bar,
body.night-mode .mdc-tab-bar {
    background: linear-gradient(to bottom, #2a2a2a, #222);
    border-bottom-color: #555;
}

body.dark-mode .mdc-tab,
body.night-mode .mdc-tab {
    background: linear-gradient(to bottom, #2a2a2a, #222);
    border-color: #555;
    color: #aaa;
}

body.dark-mode .mdc-tab.mdc-active,
body.night-mode .mdc-tab.mdc-active {
    background: #1e1e1e;
    color: #eee;
    border-bottom-color: #1e1e1e;
}

body.dark-mode .mdc-table th,
body.night-mode .mdc-table th {
    background: linear-gradient(to bottom, #333, #2a2a2a);
    border-color: #555;
    color: #ddd;
}

body.dark-mode .mdc-table td,
body.night-mode .mdc-table td {
    border-color: #333;
    color: #ccc;
}

body.dark-mode .mdc-table tr:nth-child(even) td,
body.night-mode .mdc-table tr:nth-child(even) td {
    background: #232323;
}

body.dark-mode .mdc-table tr:hover td,
body.night-mode .mdc-table tr:hover td {
    background: #2a3040;
}

body.dark-mode .mdc-table tr.mdc-selected td,
body.night-mode .mdc-table tr.mdc-selected td {
    background: #1e3050;
}

body.dark-mode .mdc-table-wrap,
body.night-mode .mdc-table-wrap {
    background: #1a1a1a;
    border-color: #444;
}

body.dark-mode .mdc-loading-overlay,
body.night-mode .mdc-loading-overlay {
    background: rgba(20,20,20,0.75);
    color: #aaa;
}

body.dark-mode .mdc-spinner,
body.night-mode .mdc-spinner {
    border-color: #444;
    border-top-color: #aaa;
}
