/* ============================================================================
   UI.js inputs (combo dropdown + number) — themeable (dark / light)
   Tokens are shared with layout.css; switch theme via  data-theme on <html>
   or any ancestor:   document.documentElement.setAttribute('data-theme','light')
   ============================================================================ */

/* ---------- design tokens ---------- */
:root,
[data-theme="dark"] {
    --lay-bar:        #333333;
    --lay-panel:      #2b2b2b;
    --lay-panel-2:    #2f2f2f;
    --lay-line:       #1c1c1c;
    --lay-line-soft:  #404040;
    --lay-text:       #d0d0d0;
    --lay-muted:      #8a8a8a;
    --lay-hover:      #3a3a3a;
    --lay-accent:     #4a90d9;
    --lay-canvas-bg:  #5a5a5a;
    --lay-field-bg:   #2b2b2b;
    --lay-placeholder:#7e7e7e;
    --lay-dropdown-bg:#2b2b2b;
    --lay-scroll:     #4a4a4a;
    --lay-shadow:     rgba(0,0,0,.45);
    --lay-accent-soft: rgba(74,144,217,.20);
}
[data-theme="light"] {
    --lay-bar:        #ececec;
    --lay-panel:      #f6f6f6;
    --lay-panel-2:    #efefef;
    --lay-line:       #c6c6c6;
    --lay-line-soft:  #d6d6d6;
    --lay-text:       #2a2a2a;
    --lay-muted:      #6c6c6c;
    --lay-hover:      #e3e3e3;
    --lay-accent:     #2f6fd0;
    --lay-canvas-bg:  #9a9a9a;
    --lay-field-bg:   #ffffff;
    --lay-placeholder:#9a9a9a;
    --lay-dropdown-bg:#ffffff;
    --lay-scroll:     #bdbdbd;
    --lay-shadow:     rgba(0,0,0,.18);
    --lay-accent-soft: rgba(47,111,208,.16);
}

/* ---------- shared UI sizing tokens (scale everything from here) ---------- */
:root {
    --ui-h: 28px;        /* control height */
    --ui-fs: 13px;       /* control font-size */
    --ui-fs-sm: 14px;    /* combo/dropdown font-size */
    --ui-pad: 8px;       /* control horizontal padding */
    --ui-step: 22px;     /* number stepper width */
}

.line-through { text-decoration: line-through; }

input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }

/* ---------- combo dropdown ---------- */
.combo-wrapper {
    position: relative; display: inline-flex; align-items: center;
    height: var(--ui-h); box-sizing: border-box;
    background: var(--lay-field-bg); border: 1px solid var(--lay-line);
    border-radius: 4px; width: 200px;
}
.combo-input {
    flex: 1 1 auto; min-width: 0; height: 100% !important; box-sizing: border-box;
    background: transparent; border: none; outline: none;
    color: var(--lay-text); font-size: var(--ui-fs-sm); padding: 0 var(--ui-pad); border-radius: 4px 0 0 4px;
}
.combo-input::placeholder { color: var(--lay-placeholder); }

.combo-arrow {
    flex: 0 0 auto; width: 26px; height: 100%;
    display: flex; justify-content: center; align-items: center;
    cursor: pointer; user-select: none; color: var(--lay-muted);
    background: transparent; border: none; border-left: 1px solid var(--lay-line);
}
.combo-arrow:hover { color: var(--lay-text); background: var(--lay-hover); border-radius: 0 3px 3px 0; }
.combo-arrow svg { width: 15px; height: 15px; fill: currentColor; }

.combo-dropdown {
    position: absolute; top: calc(100% + 2px); left: 0; width: 100%; box-sizing: border-box;
    border: 1px solid var(--lay-line); background: var(--lay-dropdown-bg); color: var(--lay-text);
    border-radius: 4px; z-index: 10; display: none; max-height: 80vh; overflow: auto;
    flex-direction: column; box-shadow: 0 4px 12px var(--lay-shadow);
    scrollbar-width: thin; scrollbar-color: var(--lay-scroll) transparent;
}
.combo-dropdown div {
    display: block; padding: 6px 10px; cursor: pointer; font-size: var(--ui-fs-sm);
    color: var(--lay-text); white-space: nowrap;
}
.combo-dropdown div:hover, .combo-dropdown .highlight { background: var(--lay-hover); }

.combo-dropdown::-webkit-scrollbar { width: 10px; }
.combo-dropdown::-webkit-scrollbar-thumb { background: var(--lay-scroll); border-radius: 5px; border: 2px solid var(--lay-dropdown-bg); }
.combo-dropdown::-webkit-scrollbar-track { background: transparent; }

/* ---------- number input (pill: value + − / + steppers) ---------- */
.number-wrapper {
    display: inline-flex; align-items: center; height: var(--ui-h); box-sizing: border-box;
    background: var(--lay-field-bg); border: 1px solid var(--lay-line);
    border-radius: 4px; overflow: hidden;
}
.number-input {
    flex: 1 1 auto; min-width: 0; width: 50px; height: 100% !important; box-sizing: border-box;
    background: transparent; border: none; outline: none;
    color: var(--lay-text); font-size: var(--ui-fs); padding: 0 var(--ui-pad); text-align: left;
}
.number-input::placeholder { color: var(--lay-placeholder); }

.number-arrow {
    flex: 0 0 auto; display: flex; flex-direction: row; height: 100%;
    align-items: stretch; border-left: 1px solid var(--lay-line);
}
.num-step {
    width: var(--ui-step); height: 100%; display: flex; align-items: center; justify-content: center;
    color: var(--lay-muted); font-size: 16px; line-height: 1; cursor: pointer; user-select: none;
}
.num-step:hover { background: var(--lay-hover); color: var(--lay-text); }
#arrow-up { border-left: 1px solid var(--lay-line); }

/* ---------- range (slider + number pill) ---------- */
.range-wrapper { display: inline-flex; align-items: center; gap: 8px; width: 100%; }
.range-input {
    -webkit-appearance: none; appearance: none;
    flex: 1 1 auto; height: 6px; border-radius: 3px; background: var(--lay-line); outline: none;
}
.range-input::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--lay-line); }
.range-input::-moz-range-track { height: 6px; border-radius: 3px; background: var(--lay-line); }
.range-input::-webkit-slider-thumb {
    -webkit-appearance: none; width: 18px; height: 18px; margin-top: -6px; border-radius: 50%;
    background: var(--lay-accent); border: 2px solid var(--lay-field-bg); cursor: pointer;
}
.range-input::-moz-range-thumb {
    width: 18px; height: 18px; border-radius: 50%;
    background: var(--lay-accent); border: 2px solid var(--lay-field-bg); cursor: pointer;
}
.range-num { flex: 0 0 auto; }
.range-num .number-input { width: 56px; text-align: right; }

/* ---------- checkbox ---------- */
.check-wrapper, .radio-wrapper {
    display: inline-flex; align-items: center; gap: 7px; cursor: pointer; color: var(--lay-text); font-size: 14px;
}
.check-input, .radio-input { position: absolute; opacity: 0; width: 0; height: 0; }
.check-box {
    width: 17px; height: 17px; flex: 0 0 auto; border: 1px solid var(--lay-line-soft);
    border-radius: 3px; background: var(--lay-field-bg);
    display: inline-flex; align-items: center; justify-content: center;
}
.check-input:checked + .check-box { background: var(--lay-accent); border-color: var(--lay-accent); }
.check-input:checked + .check-box::after {
    content: ""; width: 5px; height: 9px; border: solid #fff; border-width: 0 2px 2px 0;
    transform: rotate(45deg); margin-top: -2px;
}
.check-input:focus-visible + .check-box,
.radio-input:focus-visible + .radio-box { box-shadow: 0 0 0 2px var(--lay-accent); }

/* ---------- radio ---------- */
.radio-group { display: flex; flex-direction: column; gap: 6px; }
.radio-box {
    width: 17px; height: 17px; flex: 0 0 auto; border: 1px solid var(--lay-line-soft);
    border-radius: 50%; background: var(--lay-field-bg);
    display: inline-flex; align-items: center; justify-content: center;
}
.radio-input:checked + .radio-box { border-color: var(--lay-accent); }
.radio-input:checked + .radio-box::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--lay-accent); }
/* read-only select (UI.select) display field */
.select-wrapper .select-input { display: inline-flex; align-items: center; cursor: pointer; user-select: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
