/* ==========================================================================
   BHYT Device Usage Control — Windows Desktop UI Style
   ========================================================================== */
:root {
    --win-bg: #eef2f6;
    --win-surface: #ffffff;
    --win-panel-header: #f3f6fa;
    --win-border: #c5ced9;
    --win-border-strong: #9aa7b8;
    --win-titlebar: #0f3d7a;
    --win-titlebar-accent: #1857a8;
    --win-primary: #0067c0;
    --win-primary-hover: #00549e;
    --win-danger: #c42b1c;
    --win-danger-bg: #fde7e9;
    --win-danger-border: #d94c3d;
    --win-warn-bg: #fff4ce;
    --win-ok: #107c10;
    --win-ok-bg: #dff6dd;
    --win-text: #1b1f24;
    --win-muted: #5a6573;
    --win-used-bg: #dbeafe;
    --win-used-border: #2563eb;
    --win-used-text: #1e3a8a;
    --win-free-bg: #f8fafc;
    --win-free-border: #94a3b8;
    --win-free-hover: #e0f2fe;
    --win-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
    --font-win: "Segoe UI", Tahoma, Geneva, Verdana, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: var(--font-win);
    font-size: 13px;
    color: var(--win-text);
    background: var(--win-bg);
}

.hidden {
    display: none !important;
}

/* Main Window Shell */
.win-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-height: 600px;
    overflow: hidden;
}

/* Compact Windows Title Bar */
.win-titlebar {
    background: linear-gradient(90deg, var(--win-titlebar), var(--win-titlebar-accent));
    color: #fff;
    height: 30px;
    padding: 0 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    user-select: none;
    border-bottom: 1px solid #0a2a54;
    flex-shrink: 0;
}

.win-titlebar-left {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.win-app-icon {
    font-size: 14px;
    line-height: 1;
}

.win-title-main {
    font-size: 12.5px;
    font-weight: 600;
    letter-spacing: 0.1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.win-title-sep {
    color: rgba(255, 255, 255, 0.35);
    font-size: 11px;
}

.win-title-host {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.78);
    white-space: nowrap;
}

.win-titlebar-right {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.win-badge-status {
    font-size: 11px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.22);
    padding: 1px 6px;
    border-radius: 2px;
    color: #d9ffdb;
    line-height: 18px;
}

.win-tool-btn {
    background: transparent;
    color: #fff;
    border: 1px solid transparent;
    height: 22px;
    padding: 0 7px;
    font-size: 11.5px;
    font-family: inherit;
    border-radius: 2px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.win-tool-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.28);
}

/* Compact Windows Tab Bar */
.win-tabbar {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    padding: 4px 8px 0 8px;
    background: #dde4ec;
    border-bottom: 1px solid var(--win-border-strong);
    flex-shrink: 0;
}

.win-tab {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 11px;
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 500;
    color: #334155;
    background: #e9eef4;
    border: 1px solid var(--win-border);
    border-bottom: none;
    border-radius: 2px 2px 0 0;
    cursor: pointer;
    position: relative;
    top: 1px;
}

.win-tab:hover {
    background: #f5f8fb;
}

.win-tab.active {
    background: var(--win-bg);
    color: var(--win-titlebar);
    font-weight: 600;
    border-color: var(--win-border-strong);
    border-bottom: 1px solid var(--win-bg);
    box-shadow: inset 0 2px 0 var(--win-primary);
}

.tab-count {
    background: #cbd5e1;
    color: #1e293b;
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 10px;
    font-weight: 600;
}

.win-tab.active .tab-count {
    background: var(--win-primary);
    color: #fff;
}

/* Workspace */
.win-workspace {
    flex: 1;
    min-height: 0;
    padding: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.win-tabpanel {
    display: none;
    flex: 1;
    min-height: 0;
}

.win-tabpanel.active {
    display: flex;
    flex-direction: column;
}

/* Panels */
.win-panel {
    background: var(--win-surface);
    border: 1px solid var(--win-border);
    border-radius: 2px;
    box-shadow: var(--win-shadow);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.win-panel-header {
    background: var(--win-panel-header);
    border-bottom: 1px solid var(--win-border);
    padding: 6px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-shrink: 0;
}

.panel-title {
    font-weight: 600;
    font-size: 13px;
    color: #1e293b;
}

.panel-title-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.panel-hint, .panel-count {
    font-size: 11px;
    color: var(--win-muted);
}

.win-panel-body {
    padding: 10px;
    overflow-y: auto;
}

/* Tab 1 Layout */
.usage-layout {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 10px;
    flex: 1;
    min-height: 0;
}

.entry-panel.editing-mode {
    border-color: var(--win-primary);
    box-shadow: 0 0 0 2px rgba(0, 103, 192, 0.18);
}

.entry-panel.editing-mode .win-panel-header {
    background: #e0ecff;
}

.win-app.compact-mode .usage-layout {
    grid-template-columns: 1fr;
}

.win-app.compact-mode .entry-panel {
    display: none;
}

.stats-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    min-width: 0;
}

/* Forms & Inputs */
.form-group {
    margin-bottom: 10px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #334155;
    margin-bottom: 4px;
}

.req {
    color: var(--win-danger);
}

.form-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.win-input, .win-select {
    width: 100%;
    height: 30px;
    padding: 4px 8px;
    font-family: inherit;
    font-size: 13px;
    color: var(--win-text);
    background: #fff;
    border: 1px solid var(--win-border-strong);
    border-radius: 2px;
    outline: none;
}

.win-input:focus, .win-select:focus {
    border-color: var(--win-primary);
    box-shadow: 0 0 0 2px rgba(0, 103, 192, 0.16);
}

.win-input-sm {
    height: 27px;
    font-size: 12px;
    padding: 2px 7px;
}

/* Combobox */
.combobox {
    position: relative;
}

.combobox-control {
    display: flex;
    position: relative;
}

.combobox-control .win-input {
    padding-right: 28px;
}

.combobox-toggle {
    position: absolute;
    right: 1px;
    top: 1px;
    bottom: 1px;
    width: 26px;
    background: #f1f5f9;
    border: none;
    border-left: 1px solid var(--win-border);
    cursor: pointer;
    color: #334155;
    font-size: 12px;
}

.combobox-toggle:hover {
    background: #e2e8f0;
}

.combobox-list {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 1px);
    z-index: 40;
    margin: 0;
    padding: 2px 0;
    list-style: none;
    background: #fff;
    border: 1px solid var(--win-primary);
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.16);
    max-height: 210px;
    overflow-y: auto;
    display: none;
}

.combobox.open .combobox-list {
    display: block;
}

.combobox-option {
    padding: 6px 9px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 1px;
    border-bottom: 1px solid #f1f5f9;
}

.combobox-option:last-child {
    border-bottom: none;
}

.combobox-option:hover,
.combobox-option.highlighted {
    background: #dbeafe;
    color: #0f3d7a;
}

.combobox-option-main {
    font-weight: 600;
    font-size: 12.5px;
}

.combobox-option-sub {
    font-size: 11px;
    color: var(--win-muted);
}

.combobox-empty {
    padding: 8px 10px;
    color: var(--win-muted);
    font-style: italic;
    font-size: 12px;
}

/* End time preview */
.end-time-preview {
    background: #f0f6ff;
    border: 1px solid #bfdbfe;
    border-radius: 2px;
    padding: 6px 9px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
}

.preview-label {
    color: #334155;
}

.preview-value {
    color: var(--win-titlebar);
    font-size: 13px;
}

/* Conflict & OK Alerts */
.conflict-box {
    background: var(--win-danger-bg);
    border: 1px solid var(--win-danger-border);
    border-left: 4px solid var(--win-danger);
    border-radius: 2px;
    padding: 8px 10px;
    margin-bottom: 10px;
    color: #7f1d1d;
    animation: fadeIn 0.15s ease-out;
}

.conflict-box-title {
    font-weight: 700;
    font-size: 12px;
    color: var(--win-danger);
    margin-bottom: 4px;
}

.conflict-box-body {
    font-size: 12px;
    line-height: 1.45;
}

.conflict-item {
    padding: 4px 6px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid #f5b5b0;
    border-radius: 2px;
    margin-top: 4px;
}

.ok-box {
    background: var(--win-ok-bg);
    border: 1px solid #8fd18f;
    border-left: 4px solid var(--win-ok);
    border-radius: 2px;
    padding: 6px 9px;
    margin-bottom: 10px;
    color: #0b5d0b;
    font-size: 12px;
    font-weight: 500;
}

/* Buttons */
.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 6px;
}

.win-btn {
    height: 30px;
    padding: 0 12px;
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    border-radius: 2px;
    border: 1px solid var(--win-border-strong);
    background: #f3f6fa;
    color: var(--win-text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    white-space: nowrap;
}

.win-btn:hover:not(:disabled) {
    background: #e5ebf2;
}

.win-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.win-btn-primary {
    background: var(--win-primary);
    border-color: #00549e;
    color: #fff;
}

.win-btn-primary:hover:not(:disabled) {
    background: var(--win-primary-hover);
}

.win-btn-danger {
    background: var(--win-danger);
    border-color: #9e2115;
    color: #fff;
}

.win-btn-danger:hover:not(:disabled) {
    background: #a52216;
}

.win-btn-sm {
    height: 27px;
    padding: 0 9px;
    font-size: 12px;
}

.win-btn-xs {
    height: 23px;
    padding: 0 7px;
    font-size: 11.5px;
}

/* Filter Bar */
.filter-panel {
    flex-shrink: 0;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px;
    padding: 8px 10px;
}

.filter-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.filter-item label {
    font-size: 11px;
    font-weight: 600;
    color: var(--win-muted);
}

.filter-device-wrap {
    display: flex;
    gap: 4px;
}

#filterDeviceSearch {
    width: 145px;
}

#filterDevice {
    width: 215px;
}

#filterOperator {
    width: 195px;
}

#filterDate {
    width: 135px;
}

.filter-actions {
    flex-direction: row;
    align-items: center;
    gap: 6px;
}

/* Timeline Panel */
.timeline-panel {
    flex-shrink: 0;
    max-height: 44%;
}

.timeline-legend {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 11px;
    color: var(--win-muted);
    flex-wrap: wrap;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.swatch {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    display: inline-block;
}

.swatch-used {
    background: var(--win-used-bg);
    border: 1px solid var(--win-used-border);
}

.swatch-free {
    background: var(--win-free-bg);
    border: 1px dashed var(--win-free-border);
}

.swatch-conflict {
    background: var(--win-danger-bg);
    border: 2px solid var(--win-danger);
}

.timeline-stats-pill {
    font-size: 11px;
    font-weight: 600;
    color: var(--win-titlebar);
    background: #e0ecff;
    padding: 2px 8px;
    border-radius: 10px;
}

.timeline-body {
    padding: 8px 10px;
}

.timeline-slots-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.slot-card {
    border-radius: 2px;
    padding: 6px 9px;
    min-width: 155px;
    flex: 1 1 170px;
    max-width: 260px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.slot-card.slot-used {
    background: var(--win-used-bg);
    border: 1px solid var(--win-used-border);
    border-left: 4px solid var(--win-used-border);
    color: var(--win-used-text);
}

.slot-card.slot-used.slot-conflict {
    background: var(--win-danger-bg);
    border: 2px solid var(--win-danger);
    border-left: 5px solid var(--win-danger);
    color: #7f1d1d;
    box-shadow: 0 0 0 2px rgba(196, 43, 28, 0.2);
}

.slot-card.slot-free {
    background: var(--win-free-bg);
    border: 1px dashed var(--win-free-border);
    color: #334155;
    cursor: pointer;
}

.slot-card.slot-free:hover {
    background: var(--win-free-hover);
    border-color: var(--win-primary);
    border-style: solid;
}

.slot-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.slot-time {
    font-weight: 700;
    font-size: 12.5px;
}

.slot-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 2px;
    text-transform: uppercase;
}

.slot-badge-used {
    background: #2563eb;
    color: #fff;
}

.slot-badge-conflict {
    background: var(--win-danger);
    color: #fff;
}

.slot-badge-free {
    background: #e2e8f0;
    color: #334155;
}

.slot-meta {
    font-size: 11.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* All-Devices Mode Rows */
.all-devices-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.device-tl-row {
    display: grid;
    grid-template-columns: 230px 1fr;
    gap: 8px;
    align-items: center;
    padding: 6px 8px;
    border: 1px solid #dbe2ea;
    background: #fafcff;
    border-radius: 2px;
}

.device-tl-name {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.device-tl-link {
    background: none;
    border: none;
    padding: 0;
    text-align: left;
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--win-primary);
    cursor: pointer;
}

.device-tl-link:hover {
    text-decoration: underline;
}

.device-tl-sub {
    font-size: 11px;
    color: var(--win-muted);
}

.device-tl-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: center;
}

.mini-used-pill {
    background: var(--win-used-bg);
    border: 1px solid #93c5fd;
    color: var(--win-used-text);
    font-size: 11.5px;
    padding: 2px 7px;
    border-radius: 2px;
    font-weight: 500;
}

.mini-used-pill.is-conflict {
    background: var(--win-danger-bg);
    border-color: var(--win-danger);
    color: #991b1b;
    font-weight: 700;
}

.mini-empty-note {
    font-size: 11.5px;
    color: var(--win-ok);
    background: var(--win-ok-bg);
    padding: 2px 7px;
    border-radius: 2px;
    border: 1px dashed #8fd18f;
    cursor: pointer;
}

/* Free Summary Chips */
.free-summary {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #e2e8f0;
}

.free-summary-title {
    font-size: 11.5px;
    font-weight: 600;
    color: #334155;
    margin-bottom: 5px;
}

.free-summary-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.free-chip {
    background: #f1f5f9;
    border: 1px dashed #64748b;
    color: #0f172a;
    font-family: inherit;
    font-size: 11.5px;
    padding: 3px 8px;
    border-radius: 2px;
    cursor: pointer;
}

.free-chip:hover {
    background: #e0f2fe;
    border-color: var(--win-primary);
    border-style: solid;
    color: var(--win-titlebar);
}

/* DataGrid Table */
.table-panel {
    flex: 1;
    min-height: 150px;
}

.table-scroll {
    flex: 1;
    overflow: auto;
    min-height: 0;
}

.win-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
}

.win-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #e9eff6;
    color: #1e293b;
    font-weight: 600;
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid var(--win-border-strong);
    border-right: 1px solid #d4dde7;
    white-space: nowrap;
}

.win-table tbody td {
    padding: 5px 8px;
    border-bottom: 1px solid #e5ebf2;
    border-right: 1px solid #edf2f7;
    vertical-align: middle;
}

.win-table tbody tr:nth-child(even) {
    background: #fafcfe;
}

.win-table tbody tr:hover {
    background: #eef6ff;
}

.win-table tbody tr.row-conflict {
    background: var(--win-danger-bg) !important;
}

.text-center { text-align: center; }
.muted { color: var(--win-muted); }

.badge-status {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 2px;
    font-size: 11px;
    font-weight: 600;
}

.badge-active { background: var(--win-ok-bg); color: var(--win-ok); }
.badge-maintenance { background: var(--win-warn-bg); color: #8a5a00; }
.badge-inactive { background: #e2e8f0; color: #475569; }

/* CRUD Tabs Layout */
.crud-layout {
    display: grid;
    grid-template-columns: 330px 1fr;
    gap: 10px;
    flex: 1;
    min-height: 0;
}

/* Settings Tab */
.settings-layout {
    display: flex;
    justify-content: flex-start;
    flex: 1;
    min-height: 0;
}

.settings-panel {
    width: 100%;
    max-width: 600px;
    align-self: flex-start;
}

.session-group {
    background: #f8fafc;
    border: 1px solid var(--win-border);
    border-radius: 2px;
    padding: 10px 12px 4px;
    margin-bottom: 12px;
}

.session-group-title {
    font-weight: 700;
    font-size: 13px;
    color: var(--win-titlebar);
    margin-bottom: 8px;
}

.preset-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}

.time24-input {
    font-family: Consolas, "Cascadia Mono", "Segoe UI", monospace;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.slot-session-tag {
    font-size: 10px;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 2px;
    background: rgba(15, 61, 122, 0.08);
    color: var(--win-titlebar);
}

/* Status Bar */
.win-statusbar {
    height: 26px;
    background: #dde4ec;
    border-top: 1px solid var(--win-border-strong);
    display: flex;
    align-items: center;
    font-size: 11.5px;
    color: #1e293b;
    flex-shrink: 0;
    user-select: none;
}

.status-cell {
    padding: 0 10px;
    border-right: 1px solid #bec8d4;
    height: 100%;
    display: flex;
    align-items: center;
    white-space: nowrap;
}

.status-msg {
    flex: 1;
    border-right: none;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #334155;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    right: 14px;
    bottom: 36px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 380px;
}

.toast {
    background: #1e293b;
    color: #fff;
    padding: 9px 12px;
    border-radius: 2px;
    border-left: 4px solid var(--win-primary);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
    font-size: 12.5px;
    animation: fadeIn 0.15s ease-out;
}

.toast.toast-success { border-left-color: #22c55e; }
.toast.toast-error   { border-left-color: #ef4444; background: #7f1d1d; }
.toast.toast-warn    { border-left-color: #f59e0b; }

/* Windows Modal */
.win-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.win-modal {
    width: 100%;
    max-width: 440px;
    background: #fff;
    border: 1px solid var(--win-titlebar);
    border-radius: 2px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
    overflow: hidden;
}

.win-modal-titlebar {
    background: var(--win-titlebar);
    color: #fff;
    padding: 8px 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.win-modal-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
}

.win-modal-body {
    padding: 14px 14px;
    font-size: 13px;
    line-height: 1.5;
}

.win-modal-footer {
    padding: 10px 14px;
    background: #f1f5f9;
    border-top: 1px solid var(--win-border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.empty-state {
    padding: 14px;
    text-align: center;
    color: var(--win-muted);
    font-size: 12.5px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(3px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Responsive fallback for smaller viewports */
@media (max-width: 980px) {
    .win-app {
        height: auto;
        min-height: 100vh;
        overflow: auto;
    }
    .win-workspace {
        overflow: visible;
    }
    .usage-layout, .crud-layout {
        grid-template-columns: 1fr;
    }
    .timeline-panel {
        max-height: none;
    }
    .device-tl-row {
        grid-template-columns: 1fr;
    }
}
