/* ylso 租戶／平台後台共用：緊湊版面元件 */

:root {
    --input-border: #cbd5e1;
    --input-bg: #ffffff;
    --input-toolbar-bg: #f8fafc;
    --input-radius: 6px;
    --input-padding-y: 0.15rem;
    --input-padding-x: 0.5rem;
    --input-font-size: 0.9rem;
    --input-line-height: 1.35;
    --form-label-w: 5rem;
    --layout-sticky-top: 2.625rem;
    --list-scroll-offset: 6.75rem;
    --table-font-size: 0.9rem;
    --table-head-bg: #eff6ff;
    --table-head-border: #dbeafe;
    --hint-tip-bg: #ffffe1;
    --hint-tip-color: #111827;
    --hint-tip-border: #d4c878;
}

/* ── 表單輸入框（租戶／平台／登入共用） ── */

.form-input,
.search-input,
.select,
textarea.form-input,
.login-form input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]),
.login-form .form-input {
    border: 1px solid var(--input-border);
    border-radius: var(--input-radius);
    padding: var(--input-padding-y) var(--input-padding-x);
    font: inherit;
    font-size: var(--input-font-size);
    line-height: var(--input-line-height);
    width: 100%;
    background: var(--input-bg);
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-input,
.select {
    background: var(--input-toolbar-bg);
}

select.form-input,
select.select {
    padding-right: 1.75rem;
}

.form-input:focus,
.search-input:focus,
.select:focus,
textarea.form-input:focus,
.login-form input:focus:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]),
.login-form .form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--input-focus-ring);
}

.form-input:disabled,
.search-input:disabled,
.select:disabled,
.form-input[readonly] {
    background: #f1f5f9;
    color: var(--muted);
    cursor: not-allowed;
}

.textarea {
    min-height: 5rem;
    resize: vertical;
}

/* ── 表單 field-hint（租戶／平台共用；併入 label 內） ── */

.form-field label .field-hint {
    font-weight: 400;
    font-size: 0.8rem;
    color: var(--muted);
}

.form-field label .field-hint code {
    font-size: 0.85em;
}

/* ── 表單 hint tooltip（`title` → JS 自訂；淡黃底黑字，對齊 YLS／Windows 提示） ── */

.ylso-hint-tip {
    position: fixed;
    z-index: 10000;
    max-width: 22rem;
    padding: 0.35rem 0.55rem;
    font-size: 0.85rem;
    line-height: 1.4;
    color: var(--hint-tip-color);
    background: var(--hint-tip-bg);
    border: 1px solid var(--hint-tip-border);
    border-radius: 4px;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.12);
    pointer-events: none;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}

.ylso-hint-tip[hidden] {
    display: none !important;
}

/* ── 緊湊版面（租戶／平台 .app-shell 後台） ── */

.app-shell .topbar {
    padding: 0.45rem 1rem;
    gap: 0.65rem;
}

.app-shell .topbar-title h1 {
    font-size: 1.05rem;
    line-height: 1.3;
}

.app-shell .user-pill {
    padding: 0.25rem 0.6rem;
    font-size: 0.82rem;
}

.app-shell .content {
    padding: 0.6rem 1rem 0.75rem;
    gap: 0.5rem;
}

.app-shell .btn {
    padding: 0.3rem 0.65rem;
    font-size: var(--table-font-size);
    border-radius: 6px;
}

.app-shell .panel {
    padding: 0.65rem 0.85rem;
}

.app-shell .panel--list-compact {
    padding: 0.45rem 0.85rem 0.55rem;
}

.app-shell .panel--list-compact .panel-head {
    margin-bottom: 0;
    min-height: 0;
    gap: 0;
}

/* 列表 toolbar：單行（搜尋 + 篩選 + 新增） */
.app-shell .toolbar--list {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.2rem;
}

.app-shell .toolbar--list .toolbar-form {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.5rem;
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
}

.app-shell .toolbar .search-input,
.app-shell .toolbar .select {
    width: auto;
    flex: 1 1 12rem;
    min-width: 9rem;
    max-width: 22rem;
}

.app-shell .toolbar-actions {
    margin-left: auto;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

@media (max-width: 640px) {
    .app-shell .toolbar--list {
        flex-wrap: wrap;
    }

    .app-shell .toolbar--list .toolbar-form {
        flex-wrap: wrap;
        width: 100%;
    }

    .app-shell .toolbar .search-input,
    .app-shell .toolbar .select {
        flex: 1 1 100%;
        max-width: none;
    }

    .app-shell .toolbar-actions {
        margin-left: 0;
        width: 100%;
        justify-content: flex-end;
    }
}

.app-shell .panel-head {
    margin-bottom: 0.6rem;
    gap: 0.65rem;
}

.app-shell details.help-fold {
    padding: 0.35rem 0.7rem;
    font-size: 0.85rem;
}

.app-shell .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.app-shell .table-wrap--list-scroll,
.app-shell .table-wrap--medium {
    max-height: calc(100dvh - var(--layout-sticky-top) - var(--list-scroll-offset));
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.app-shell .panel--list-compact .table-wrap--list-scroll,
.app-shell .panel--list-compact .table-wrap--medium {
    margin-top: 0.2rem;
}

.app-shell .data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--table-font-size);
}

.app-shell .data-table:not(.detail-kv) th,
.app-shell .data-table:not(.detail-kv) td {
    padding: 0.35rem 0.45rem;
    vertical-align: middle;
    line-height: 1.35;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.app-shell .table-wrap--list-scroll .data-table thead th,
.app-shell .table-wrap--medium .data-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    font-size: var(--table-font-size);
    font-weight: 600;
    color: var(--text);
    background: var(--table-head-bg);
    box-shadow: 0 1px 0 var(--table-head-border);
    white-space: nowrap;
}

.app-shell .data-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.app-shell .badge {
    padding: 0.1rem 0.4rem;
    font-size: 0.72rem;
}

.app-shell .actions-cell {
    gap: 0.35rem 0.55rem;
}

.app-shell .link,
.app-shell .btn-link {
    font-size: var(--table-font-size);
}

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

.logout-link {
    font-size: 0.85rem;
    color: var(--muted);
    text-decoration: none;
}

.logout-link:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

.panel-head--actions-only {
    justify-content: flex-end;
}

.panel-head-meta {
    font-size: 0.85rem;
    color: var(--muted);
    font-weight: 400;
}

details.help-fold {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 0.45rem 0.85rem;
    font-size: 0.88rem;
}

details.help-fold summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--muted);
    user-select: none;
}

.help-fold-body {
    margin-top: 0.5rem;
    color: var(--muted);
}

.help-fold-body p {
    margin: 0.35rem 0 0;
}

.form-panel-narrow {
    max-width: 44rem;
}

.form-panel-wide {
    max-width: 52rem;
}

/* ── 表單版面：label 左、input 右（全站一致，省空間；唯一定義於 shared） ── */

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem 1.6rem;
}

.form-field {
    display: grid;
    grid-template-columns: var(--form-label-w) minmax(0, 1fr);
    align-items: center;
    column-gap: 0.55rem;
    row-gap: 0.1rem;
}

.form-field-full {
    grid-column: 1 / -1;
}

.form-field > label {
    text-align: right;
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text);
}

/* 內容為表格／多個勾選等：label 改置於上方 */
.form-field--stack {
    display: block;
}

.form-field--stack > label {
    display: block;
    text-align: left;
    margin-bottom: 0.3rem;
}

/* 欄寬：依預期文字長度取最適寬度（省空間，貼近 YLS） */
.form-input--w-xs { max-width: 6rem; }
select.form-input--w-xs {
    width: auto;
    min-width: 0;
    max-width: 4rem;
}
.form-input--w-sm { max-width: 11rem; }
.form-input--w-md { max-width: 16rem; }

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
    padding-top: 0.4rem;
}

.form-actions .btn {
    padding-left: 1rem;
    padding-right: 1rem;
}

.checkbox-row {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
    cursor: pointer;
}

.checkbox-row input {
    width: auto;
}

.checkbox-row-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 1.25rem;
}

.checkbox-row-group .checkbox-row {
    margin: 0;
}

@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
}

.panel-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* 系統設定：手風琴分區 */
.settings-accordion-tools {
    align-items: center;
    gap: 0.5rem;
}

.panel-head.settings-accordion-tools {
    margin-bottom: 0.5rem;
}

.settings-accordion-item {
    border: 1px solid var(--table-head-border, #dbeafe);
    border-radius: var(--radius, 6px);
    background: var(--surface, #fff);
    overflow: hidden;
}

.settings-accordion-summary {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 0.75rem;
    font-weight: 600;
    font-size: 0.92rem;
    cursor: pointer;
    list-style: none;
    user-select: none;
    background: var(--table-head-bg, #eff6ff);
    border-bottom: 1px solid transparent;
}

.settings-accordion-item[open] > .settings-accordion-summary {
    border-bottom-color: var(--table-head-border, #dbeafe);
}

.settings-accordion-summary::-webkit-details-marker {
    display: none;
}

.settings-accordion-summary::before {
    content: '▼';
    flex-shrink: 0;
    width: 1rem;
    font-size: 0.68rem;
    line-height: 1;
    text-align: center;
    color: var(--muted, #64748b);
}

.settings-accordion-item[open] > .settings-accordion-summary::before {
    content: '▲';
}

.btn-linkish {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    font-size: 0.85rem;
    color: var(--accent, #2563eb);
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.btn-linkish:hover {
    opacity: 0.85;
}

.settings-accordion {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.settings-accordion-body {
    padding: 0 0.75rem 0.75rem;
    border-top: none;
    --form-label-w: 7rem;
}

.settings-accordion-body .form-field > label {
    white-space: nowrap;
}

.settings-accordion-body .form-grid {
    padding-top: 0.65rem;
}

.settings-accordion-form .form-actions {
    margin-top: 0.75rem;
}

.detail-kv th {
    width: 7rem;
    white-space: nowrap;
    color: var(--muted);
    font-weight: 600;
    font-size: 0.85rem;
}

.panel-grid--split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.inline-store-form {
    margin-top: 0.75rem;
}

@media (max-width: 900px) {
    .panel-grid--split { grid-template-columns: 1fr; }
}

/* ── 側欄寬度拖曳（租戶／平台後台共用） ── */

.sidebar-resizer {
    flex-shrink: 0;
    width: 5px;
    margin: 0 -2px 0 0;
    cursor: col-resize;
    touch-action: none;
    position: relative;
    z-index: 2;
    background: transparent;
    transition: background 0.15s;
}

.sidebar-resizer::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 2px;
    width: 1px;
    background: rgba(255, 255, 255, 0.08);
    transition: background 0.15s, width 0.15s, left 0.15s;
}

.sidebar-resizer:hover::after,
.sidebar-resizer.is-dragging::after,
.app-shell.is-sidebar-resizing .sidebar-resizer::after {
    left: 1px;
    width: 2px;
    background: rgba(45, 212, 191, 0.55);
}

.app-shell.is-sidebar-resizing {
    user-select: none;
    cursor: col-resize;
}

.app-shell.is-sidebar-resizing .main {
    pointer-events: none;
}

@media (max-width: 768px) {
    .sidebar-resizer { display: none; }
}

/* ── 側欄頂部與導覽（租戶／平台共用緊湊） ── */

:root {
    --sidebar-nav-fg: #ffffff;
    --sidebar-nav-hover: #5eead4;
    --sidebar-nav-active: #2dd4bf;
    --sidebar-nav-hover-bg: rgba(45, 212, 191, 0.12);
    --sidebar-nav-active-bg: rgba(45, 212, 191, 0.18);
}

.sidebar {
    padding: 0.65rem 0.6rem;
    gap: 0.45rem;
}

.brand {
    align-items: center;
    gap: 0.45rem;
    padding: 0.1rem 0.2rem;
    flex-shrink: 0;
}

.brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.brand-title {
    color: #fff;
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: 0.01em;
}

.tenant-chip,
.env-chip {
    padding: 0.4rem 0.55rem;
    border-radius: 8px;
    gap: 0.08rem;
    flex-shrink: 0;
}

.tenant-chip strong {
    font-size: 0.88rem;
    color: #fff;
    line-height: 1.25;
}

.tenant-chip code,
.env-chip code {
    font-size: 0.78rem;
    line-height: 1.2;
}

.sidebar .nav {
    display: flex;
    flex-direction: column;
    gap: 0.05rem;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-right: 0.1rem;
    line-height: 1.3;
}

.sidebar .nav-link,
.sidebar .nav-group-toggle {
    display: flex;
    align-items: center;
    padding: 0.4rem 0.55rem;
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.35;
    border-radius: 8px;
    gap: 0.45rem;
    color: var(--sidebar-nav-fg);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

.sidebar .nav-link:hover,
.sidebar .nav-group-toggle:hover {
    background: var(--sidebar-nav-hover-bg);
    color: var(--sidebar-nav-hover);
    text-decoration: none;
}

.sidebar .nav-link.is-active {
    background: var(--sidebar-nav-active-bg);
    color: #ffffff;
}

.sidebar .nav-group-toggle {
    justify-content: space-between;
    border: none;
    background: transparent;
    cursor: pointer;
    text-align: left;
    width: 100%;
}

.sidebar .nav-group-label {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex: 1;
    min-width: 0;
    color: inherit;
    font-size: inherit;
    font-weight: inherit;
    line-height: inherit;
}

.sidebar .nav-sublink {
    padding: 0.32rem 0.45rem 0.32rem 1.45rem;
    font-size: 0.86rem;
    border-radius: 6px;
    line-height: 1.3;
    color: var(--sidebar-nav-fg);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

.sidebar .nav-sublink:hover {
    background: var(--sidebar-nav-hover-bg);
    color: var(--sidebar-nav-hover);
    text-decoration: none;
}

.sidebar .nav-sublink.is-active {
    background: var(--sidebar-nav-active-bg);
    color: var(--sidebar-nav-active);
}

.sidebar .nav-sublink.is-soon {
    opacity: 1;
}

.sidebar .nav-group-items {
    gap: 0.02rem;
    padding: 0.05rem 0 0.12rem 0.2rem;
}

.sidebar .nav-icon,
.sidebar .nav-chevron {
    color: inherit;
    opacity: 1;
}

.sidebar .nav-icon {
    width: 1rem;
    font-size: 0.92rem;
}

.sidebar .nav-chevron {
    font-size: 0.68rem;
}

.sidebar .nav-tag {
    color: #cbd5e1;
}

/* 售價矩陣（商品表單） */
.price-matrix th[scope="row"] {
    white-space: nowrap;
    font-weight: 500;
}

.price-matrix td.num {
    padding: 0.25rem 0.4rem;
}

.form-input--price {
    max-width: 8rem;
    text-align: right;
}
