/* ===========================================================================
   進銷存系統 IPMOS － 樣式表
   設計方向：工業簡約（warm paper + ink + 深青色強調），桌機與手機共用。
   行動優先：基本樣式為手機版，860px 以上切換為桌機側邊欄版型。
   =========================================================================== */

:root {
    --paper:   #f2efe7;
    --surface: #ffffff;
    --ink:     #1f2420;
    --ink2:    #5d6158;
    --ink3:    #8b8e84;
    --line:    #e4dfd3;
    --line2:   #d0cabb;

    --teal:    #0f6e56;
    --teal-d:  #0a4f3f;
    --teal-l:  #e4f0ec;

    --amber:   #a76910;
    --amber-l: #f7edda;

    --red:     #a72f23;
    --red-l:   #f6e4e1;

    --radius:  8px;
    --font:    "PingFang TC","Microsoft JhengHei","Noto Sans TC",-apple-system,"Segoe UI",sans-serif;
    --mono:    "SF Mono","JetBrains Mono",Menlo,Consolas,"Courier New",monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
    font-family: var(--font);
    color: var(--ink);
    background: var(--paper);
    font-size: 15px;
    line-height: 1.6;
    -webkit-text-size-adjust: 100%;
}

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); background: var(--teal-l); padding: .05em .4em; border-radius: 4px; font-size: .9em; }

/* ====================== 登入頁 ========================================== */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: var(--paper);
}
.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 2rem 1.6rem;
}
.login-head { text-align: center; margin-bottom: 1.4rem; }
.login-head h1 { font-size: 1.2rem; margin: .6rem 0 .2rem; }
.login-head p { color: var(--ink2); font-size: .9rem; }
.login-form { display: flex; flex-direction: column; gap: 1rem; }
.login-foot { text-align: center; color: var(--ink3); font-size: .78rem; margin-top: 1.4rem; }

.brand-mark {
    display: inline-block;
    font-family: var(--mono);
    font-weight: 700;
    letter-spacing: .14em;
    color: var(--surface);
    background: var(--teal);
    padding: .25em .6em;
    border-radius: 5px;
    font-size: .82rem;
}

/* ====================== 頂部列 ========================================== */

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: .8rem;
    height: 54px;
    padding: 0 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.brand-name { font-weight: 500; font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: .7rem; }
.who { font-size: .86rem; color: var(--ink2); display: flex; align-items: center; gap: .35rem; }
.tag-admin {
    font-style: normal; font-size: .68rem; color: var(--amber);
    background: var(--amber-l); padding: .1em .45em; border-radius: 4px;
}
.btn-logout {
    font-size: .82rem; color: var(--ink2);
    border: 1px solid var(--line2); border-radius: 6px;
    padding: .35rem .7rem;
}
.btn-logout:hover { color: var(--red); border-color: var(--red); text-decoration: none; }

/* 漢堡鈕：僅手機顯示 */
.burger {
    display: flex; flex-direction: column; justify-content: center; gap: 4px;
    width: 38px; height: 38px; cursor: pointer; flex: none;
    border: 1px solid var(--line2); border-radius: 6px; padding: 0 8px;
}
.burger span { display: block; height: 2px; background: var(--ink); border-radius: 2px; }

/* ====================== 版型骨架 ======================================== */

.shell { display: flex; min-height: calc(100vh - 54px); }

.sidebar {
    position: fixed;
    top: 54px; left: 0; bottom: 0;
    width: 240px;
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: 1rem .7rem;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform .22s ease;
    z-index: 40;
}
.nav-toggle:checked ~ .shell .sidebar { transform: translateX(0); }

.nav-scrim {
    position: fixed; inset: 54px 0 0 0;
    background: rgba(20,22,18,.42);
    display: none; z-index: 35;
}
.nav-toggle:checked ~ .nav-scrim { display: block; }

.nav-group {
    /* 取代原本的小字標籤,改為可收合的群組容器 */
    margin: .15rem 0 .25rem;
    border: 0;
}
.nav-group > .nav-group-title {
    /* 主功能項:比子項大 50%(子項 0.92rem → 主項 1.38rem),粗體、黑色 */
    display: flex; align-items: center; gap: .4rem;
    list-style: none;
    cursor: pointer;
    padding: .55rem .55rem;
    border-radius: 6px;
    color: #000;
    font-size: 1.38rem;
    font-weight: 700;
    line-height: 1.25;
    user-select: none;
}
/* 隱藏瀏覽器預設的 disclosure 三角(WebKit / Firefox) */
.nav-group > .nav-group-title::-webkit-details-marker { display: none; }
.nav-group > .nav-group-title::marker                  { content: ''; }

.nav-group-arrow {
    display: inline-block; width: 1em;
    color: var(--ink2);
    font-size: .75em;
    transition: transform .18s ease;
}
.nav-group[open] > .nav-group-title .nav-group-arrow { transform: rotate(90deg); }

.nav-group > .nav-group-title:hover { background: var(--paper); }

.nav-group-body {
    padding: .15rem 0 .4rem .9rem;
    border-left: 2px solid var(--line);
    margin-left: .85rem;
}

.nav-link {
    display: flex; align-items: center; justify-content: space-between;
    padding: .5rem .7rem; border-radius: 6px;
    color: #0a3a7a;                  /* 子功能項:深藍色 */
    font-size: .92rem;
    margin-bottom: 1px;
    transition: background .12s ease, color .12s ease;
}
.nav-link:hover { background: var(--paper); color: #0a3a7a; text-decoration: none; }
.nav-link.is-active {
    /* 反白:深底白字,顯示「目前所在頁」 */
    background: #0a3a7a;
    color: #ffffff;
    font-weight: 600;
}
.nav-link.is-active:hover { background: #0a3a7a; color: #ffffff; }
.nav-link.is-disabled { color: var(--ink3); cursor: not-allowed; }
.nav-link.is-disabled:hover { background: transparent; color: var(--ink3); }

/* 不在群組裡的頂層項(如:儀表板),沿用粗體大字風格,直接放第一階 */
.nav-link.nav-link-top {
    color: #000;
    font-size: 1.38rem;
    font-weight: 700;
    padding: .55rem .55rem;
    margin-bottom: .15rem;
}
.nav-link.nav-link-top.is-active {
    background: #0a3a7a;
    color: #ffffff;
}
.phase-tag {
    font-style: normal; font-size: .66rem; color: var(--ink3);
    border: 1px solid var(--line2); border-radius: 4px; padding: .05em .35em;
}
.nav-foot { font-size: .72rem; color: var(--ink3); padding: 1.2rem .6rem .4rem; }

.content {
    flex: 1;
    min-width: 0;
    padding: 1.2rem 1rem 3rem;
}
.page-title { font-size: 1.25rem; font-weight: 500; margin-bottom: 1rem; }
.lead { color: var(--ink2); margin-bottom: 1.2rem; }

/* ====================== 提示訊息 ======================================== */

.alert {
    border-radius: var(--radius);
    padding: .7rem 1rem;
    margin-bottom: 1rem;
    font-size: .9rem;
    border: 1px solid transparent;
}
.alert-success { background: var(--teal-l);  border-color: #bcdcd1; color: var(--teal-d); }
.alert-error   { background: var(--red-l);   border-color: #e6c3bd; color: var(--red); }
.alert-info    { background: var(--amber-l); border-color: #e6d4ad; color: var(--amber); }

/* ====================== 按鈕 ============================================ */

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    font-family: var(--font); font-size: .9rem; font-weight: 500;
    padding: .55rem 1.1rem; min-height: 40px;
    border-radius: var(--radius); border: 1px solid transparent;
    cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--teal); color: var(--surface); }
.btn-primary:hover { background: var(--teal-d); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line2); }
.btn-ghost:hover { background: var(--paper); }
.btn-block { width: 100%; }
.btn-mini { min-height: 32px; padding: .3rem .7rem; font-size: .82rem; }
.btn-danger { background: var(--surface); color: var(--red); border-color: #e0bdb8; }
.btn-danger:hover { background: var(--red-l); }

/* ====================== 儀表板 ========================================== */

.stat-grid {
    display: grid; gap: .9rem;
    grid-template-columns: 1fr;
    margin-bottom: 1.6rem;
}
.stat-card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 1rem 1.1rem;
    display: flex; flex-direction: column; gap: .25rem;
}
.stat-label { font-size: .82rem; color: var(--ink2); }
.stat-value { font-family: var(--mono); font-size: 1.7rem; font-weight: 700; color: var(--teal-d); }
.stat-note { font-size: .76rem; color: var(--ink3); }
.stat-link { font-size: .82rem; }

.panel {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 1.2rem 1.2rem;
}
.panel-title { font-size: 1rem; font-weight: 500; margin-bottom: .8rem; }
.phase-list { list-style: none; display: flex; flex-direction: column; gap: .5rem; }
.phase-list li {
    font-size: .88rem; color: var(--ink2);
    padding-left: 1rem; border-left: 2px solid var(--line2);
}
.phase-list li strong { color: var(--ink); font-weight: 500; }
.phase-list li.phase-done { border-left-color: var(--teal); color: var(--ink); }
.phase-list li.phase-done em {
    font-style: normal; color: var(--teal); font-size: .76rem;
    background: var(--teal-l); padding: .05em .45em; border-radius: 4px; margin-left: .3rem;
}

/* ====================== 工具列與搜尋 ==================================== */

.toolbar {
    display: flex; flex-wrap: wrap; gap: .7rem;
    align-items: center; margin-bottom: 1rem;
}
.search-form { display: flex; gap: .5rem; flex: 1; min-width: 200px; }
.search-form input[type=text] {
    flex: 1; min-width: 0;
    padding: .5rem .7rem; font-size: .9rem;
    border: 1px solid var(--line2); border-radius: var(--radius);
}
.toolbar .btn-primary { margin-left: auto; }

.empty-box {
    background: var(--surface); border: 1px dashed var(--line2);
    border-radius: var(--radius); padding: 2.5rem 1rem;
    text-align: center; color: var(--ink2);
}

/* ====================== 資料表 ========================================== */

.table-wrap {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); overflow: hidden;
}
.data-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.data-table th {
    text-align: left; font-weight: 500; color: var(--ink2);
    background: var(--paper); padding: .65rem .8rem;
    border-bottom: 1px solid var(--line);
}
.data-table td { padding: .6rem .8rem; border-bottom: 1px solid var(--line); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #faf8f2; }
.data-table .num { text-align: right; font-family: var(--mono); }
.code { font-family: var(--mono); font-weight: 500; }
.list-foot { font-size: .8rem; color: var(--ink3); margin-top: .7rem; }

.pill {
    display: inline-block; font-size: .74rem; padding: .12em .55em;
    border-radius: 999px; background: var(--paper);
    border: 1px solid var(--line2); color: var(--ink2);
}
.pill-on, .pill-ok { background: var(--teal-l); border-color: #bcdcd1; color: var(--teal-d); }
.pill-off { background: var(--red-l); border-color: #e6c3bd; color: var(--red); }

.row-actions { display: flex; gap: .4rem; align-items: center; }
.inline-form { display: inline; }

/* ====================== 表單 ============================================ */

.form-panel { padding: 1.4rem 1.2rem; }
.form-grid {
    display: grid; gap: 1rem;
    grid-template-columns: 1fr;
}
.field { display: flex; flex-direction: column; gap: .3rem; }
.field-label { font-size: .85rem; font-weight: 500; color: var(--ink2); }
.req { color: var(--red); font-style: normal; }
.field input[type=text],
.field input[type=password],
.field input[type=number],
.field input[type=email],
.field input[type=tel],
.field input[type=date],
.field select,
.field textarea {
    font-family: var(--font); font-size: .92rem;
    padding: .55rem .7rem;
    border: 1px solid var(--line2); border-radius: var(--radius);
    background: var(--surface); color: var(--ink);
    width: 100%; box-sizing: border-box;
}
.field textarea { min-height: 78px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--teal);
    box-shadow: 0 0 0 3px var(--teal-l);
}
.field input[readonly] { background: var(--paper); color: var(--ink2); }
.field-hint { font-size: .76rem; color: var(--ink3); }
.field-error { font-size: .78rem; color: var(--red); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--red); }

/* 寬欄：在 form-grid 內跨整列（給 textarea 等用） */
.field-wide { grid-column: 1 / -1; }

.form-checks {
    display: flex; flex-wrap: wrap; align-items: center; gap: 1.2rem;
    margin: 1.2rem 0;
    padding-top: 1rem; border-top: 1px solid var(--line);
}
.check { display: flex; align-items: center; gap: .5rem; font-size: .9rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--teal); }
.field-inline { flex-direction: row; align-items: center; gap: .6rem; }
.field-inline select { width: auto; }

.form-actions {
    display: flex; gap: .7rem;
    padding-top: 1rem; border-top: 1px solid var(--line);
}

/* ====================== 桌機版（≥ 860px） ============================== */

@media (min-width: 860px) {
    .burger { display: none; }
    .nav-scrim { display: none !important; }

    .sidebar {
        position: sticky;
        top: 54px;
        height: calc(100vh - 54px);
        transform: none;
        flex: none;
    }
    .content { padding: 1.8rem 2rem 3rem; }
    .page-title { font-size: 1.4rem; }

    .stat-grid { grid-template-columns: repeat(4, 1fr); }
    .form-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ====================== 手機版資料表轉卡片（≤ 720px） ================== */

@media (max-width: 720px) {
    .table-wrap { background: transparent; border: none; }
    .data-table thead { display: none; }
    .data-table, .data-table tbody { display: block; }
    .data-table tr {
        display: block;
        background: var(--surface);
        border: 1px solid var(--line);
        border-radius: var(--radius);
        margin-bottom: .7rem;
        padding: .3rem .2rem;
    }
    .data-table td {
        display: flex; justify-content: space-between; gap: 1rem;
        border-bottom: 1px dashed var(--line);
        padding: .5rem .8rem;
    }
    .data-table tr td:last-child { border-bottom: none; }
    .data-table td::before {
        content: attr(data-label);
        font-weight: 500; color: var(--ink3); font-size: .82rem;
        flex: none;
    }
    .data-table .num { text-align: right; }
    .row-actions { justify-content: flex-end; }
}

/* ====================== 產品示意圖（Phase 2 擴充） ===================== */

.image-section {
    margin: 1.2rem 0;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
}
.section-label {
    font-size: .9rem; font-weight: 500; color: var(--ink2);
    margin-bottom: .7rem;
}
.image-slots {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: .8rem;
}
.image-slot {
    display: flex; flex-direction: column; gap: .5rem;
    border: 1px solid var(--line2); border-radius: var(--radius);
    padding: .7rem;
    background: var(--paper);
}
.image-slot.has-error { border-color: var(--red); }
.slot-no { font-size: .8rem; font-weight: 500; color: var(--ink2); }
.slot-thumb {
    width: 100%; height: 140px; object-fit: contain;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 6px;
}
.slot-empty {
    width: 100%; height: 140px;
    display: flex; align-items: center; justify-content: center;
    background: var(--surface); border: 1px dashed var(--line2);
    border-radius: 6px; color: var(--ink3); font-size: .82rem;
}
.image-slot input[type=file] {
    font-size: .8rem; width: 100%;
}
.check-sm { font-size: .8rem; gap: .35rem; }
.check-sm input { width: 15px; height: 15px; }

/* 清單縮圖 */
.list-thumb {
    width: 42px; height: 42px; object-fit: cover;
    border: 1px solid var(--line); border-radius: 6px;
    display: block;
}
.no-thumb {
    display: inline-block; font-size: .72rem; color: var(--ink3);
    width: 42px; height: 42px; line-height: 42px; text-align: center;
    background: var(--paper); border: 1px dashed var(--line2); border-radius: 6px;
}

/* ====================== 單位換算頁（Phase 2 批次2） =================== */

.context-bar {
    display: flex; flex-wrap: wrap; gap: 1.4rem;
    background: var(--surface); border: 1px solid var(--line);
    border-left: 3px solid var(--teal);
    border-radius: var(--radius);
    padding: .7rem 1rem; margin-bottom: 1rem;
    font-size: .9rem;
}
.context-item { display: flex; align-items: center; gap: .4rem; }
.context-k {
    font-size: .76rem; color: var(--ink3);
    background: var(--paper); padding: .1em .45em; border-radius: 4px;
}
.data-table tr.base-row { background: var(--teal-l); }
.data-table tr.base-row:hover { background: var(--teal-l); }

/* 效期預警標籤（批號管理用） */
.pill-warn { background: var(--amber-l); border-color: #e6d4ad; color: var(--amber); }

/* ====================== 採購單 主檔+明細（Phase 3a） ================= */

.detail-section { margin: 1.2rem 0; padding-top: 1rem; border-top: 1px solid var(--line); }

/* 明細表格內的輸入元件：緊湊、填滿欄位 */
.detail-table th, .detail-table td { vertical-align: middle; }
.detail-table select, .detail-table input {
    width: 100%; min-width: 84px; padding: .35rem .5rem;
    font-size: .88rem; box-sizing: border-box;
}
.detail-table .ln-seq { color: var(--ink3); text-align: center; }
.detail-table .ln-amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.detail-table tfoot .total-label { text-align: right; font-weight: 500; color: var(--ink2); }
.detail-table tfoot .total-value {
    font-weight: 700; font-size: 1.05rem; color: var(--teal);
    font-variant-numeric: tabular-nums;
}
#addPoLine { margin-top: .7rem; }

/* 表單錯誤清單 */
.err-list { margin: .4rem 0 0 1.1rem; padding: 0; }
.err-list li { margin: .15rem 0; }

/* ====================== 稽核資訊面板（單據編輯時上方顯示） ============= */
.audit-bar {
    margin: -.4rem 0 1rem 0; padding: .6rem .9rem;
    background: var(--paper); border-left: 3px solid var(--teal);
    border-radius: 4px; font-size: .85rem; color: var(--ink2);
    display: flex; flex-wrap: wrap; gap: .6rem 1.2rem;
}
.audit-bar strong { color: var(--ink); font-weight: 600; }
.audit-bar .audit-sep { color: var(--ink3); }
