/* =====================================================================
   ระบบสารบรรณอัจฉริยะ สภ.ไชยปราการ
   Design system — light / dark, ชื่อคลาสเดิมทั้งหมด
   ===================================================================== */

:root {
    /* ---- Light (ค่าเริ่มต้น) ---- */
    --ground:        #f4f6f8;
    --surface:       #ffffff;
    --surface-2:     #eef1f5;
    --surface-3:     #e6ebf2;

    --text-primary:  #16213e;
    --text-secondary:#54617a;
    --text-faint:    #8b96a9;

    --border-color:  #e2e7ee;
    --border-strong: #cdd5e0;

    --accent-blue:      #1e4fa3;
    --accent-blue-soft: #eaf0fb;
    --accent-blue-ink:  #173d80;
    --accent-gold:      #b07d1a;
    --accent-gold-glow: #a06f12;
    --accent-gold-soft: #f6efdd;

    --success:      #0f7a52;
    --success-soft: #e4f3ec;
    --error:        #c0392b;
    --error-soft:   #fbeae8;

    /* กระดาษเอกสาร — ไม่สลับตามธีม ให้เหมือนกระดาษจริงเสมอ */
    --paper:        #ffffff;
    --paper-ink:    #14161a;
    --paper-ink-2:  #4a5160;
    --paper-edge:   #dfe4ec;
    --paper-field:  #f2f6fd;
    --paper-accent: #1e4fa3;

    --font-thai:    'Sarabun', sans-serif;
    --font-display: 'Kanit', 'Sarabun', sans-serif;
    --font-eng:     'Kanit', sans-serif;

    --shadow-sm:      0 1px 2px rgba(16, 29, 58, .05);
    --shadow-premium: 0 1px 2px rgba(16, 29, 58, .05), 0 8px 28px rgba(16, 29, 58, .08);
    --shadow-lg:      0 24px 60px rgba(16, 29, 58, .16);

    --radius:    14px;
    --radius-sm: 10px;
}

/* ---- Dark: ตามระบบปฏิบัติการ (เว้นแต่ผู้ใช้เลือก light เอง) ---- */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --ground:        #0b111e;
        --surface:       #151f33;
        --surface-2:     #1c2842;
        --surface-3:     #24314e;

        --text-primary:  #eaf0f9;
        --text-secondary:#9fadc4;
        --text-faint:    #6b7997;

        --border-color:  #25324c;
        --border-strong: #33425f;

        --accent-blue:      #6aa0ff;
        --accent-blue-soft: #182647;
        --accent-blue-ink:  #a9c6ff;
        --accent-gold:      #d9a441;
        --accent-gold-glow: #eab308;
        --accent-gold-soft: #2a2416;

        --success:      #3ecb8f;
        --success-soft: #12271f;
        --error:        #ff6b5e;
        --error-soft:   #2d1614;

        --shadow-sm:      0 1px 2px rgba(0, 0, 0, .4);
        --shadow-premium: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .45);
        --shadow-lg:      0 26px 70px rgba(0, 0, 0, .6);
    }
}

/* ---- Dark: ผู้ใช้กดเลือกเอง ---- */
:root[data-theme="dark"] {
    --ground:        #0b111e;
    --surface:       #151f33;
    --surface-2:     #1c2842;
    --surface-3:     #24314e;

    --text-primary:  #eaf0f9;
    --text-secondary:#9fadc4;
    --text-faint:    #6b7997;

    --border-color:  #25324c;
    --border-strong: #33425f;

    --accent-blue:      #6aa0ff;
    --accent-blue-soft: #182647;
    --accent-blue-ink:  #a9c6ff;
    --accent-gold:      #d9a441;
    --accent-gold-glow: #eab308;
    --accent-gold-soft: #2a2416;

    --success:      #3ecb8f;
    --success-soft: #12271f;
    --error:        #ff6b5e;
    --error-soft:   #2d1614;

    --shadow-sm:      0 1px 2px rgba(0, 0, 0, .4);
    --shadow-premium: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .45);
    --shadow-lg:      0 26px 70px rgba(0, 0, 0, .6);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: var(--ground);
    color: var(--text-primary);
    font-family: var(--font-thai);
    line-height: 1.65;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5 { font-family: var(--font-display); font-weight: 600; }

:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}

/* พื้นหลังเรืองแสงเดิม — เบาลงมากในธีมสว่าง */
.glow-bg-1,
.glow-bg-2 {
    position: fixed;
    z-index: 0;
    pointer-events: none;
    border-radius: 50%;
}

.glow-bg-1 {
    width: 620px; height: 620px;
    top: -260px; left: -220px;
    background: radial-gradient(circle, color-mix(in srgb, var(--accent-blue) 12%, transparent) 0%, transparent 70%);
}

.glow-bg-2 {
    width: 700px; height: 700px;
    bottom: -280px; right: -200px;
    background: radial-gradient(circle, color-mix(in srgb, var(--accent-gold) 10%, transparent) 0%, transparent 70%);
}

/* =====================  Layout  ===================== */

.app-container {
    max-width: 1340px;
    margin: 0 auto;
    padding: 1.75rem 1.5rem 3rem;
    position: relative;
    z-index: 1;
}

/* =====================  Header  ===================== */

.app-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.75rem;
    padding: 0.85rem 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-premium);
}

.logo-area { flex: none; }

.header-logo {
    height: 52px;
    width: 52px;
    object-fit: contain;
    transition: transform .5s ease;
}

.header-logo:hover { transform: rotate(360deg); }

.title-area { min-width: 0; }

.title-area h1 {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.22rem;
    line-height: 1.25;
    color: var(--text-primary);
    letter-spacing: .1px;
}

.subtitle {
    font-family: var(--font-eng);
    font-weight: 300;
    color: var(--text-faint);
    font-size: .78rem;
    letter-spacing: .6px;
    text-transform: uppercase;
    margin-top: .1rem;
}

.header-nav-menu {
    margin-left: auto;
    display: flex;
    gap: .4rem;
    align-items: center;
}

.nav-btn {
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: .55rem 1rem;
    color: var(--text-secondary);
    font-size: .9rem;
    font-weight: 500;
    font-family: var(--font-display);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    transition: background .16s ease, color .16s ease, border-color .16s ease;
}

.nav-btn:hover {
    background: var(--surface-2);
    color: var(--text-primary);
}

.nav-btn.active {
    background: var(--accent-blue-soft);
    border-color: color-mix(in srgb, var(--accent-blue) 28%, transparent);
    color: var(--accent-blue-ink);
}

/* ปุ่มสลับธีม */
.theme-toggle {
    width: 40px;
    height: 40px;
    flex: none;
    padding: 0;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--surface);
    color: var(--text-secondary);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: color .16s ease, border-color .16s ease;
}

.theme-toggle:hover { color: var(--text-primary); border-color: var(--border-strong); }
.theme-toggle svg { width: 19px; height: 19px; }
.theme-toggle .i-sun { display: none; }

:root[data-theme="dark"] .theme-toggle .i-sun  { display: block; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .i-sun  { display: block; }
    :root:not([data-theme="light"]) .theme-toggle .i-moon { display: none; }
}

/* =====================  Workspace  ===================== */

.main-workspace {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    gap: 1.35rem;
    align-items: start;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-premium);
    position: relative;
}

.panel-left {
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    position: sticky;
    top: 1.25rem;
}

.section-title {
    font-size: 1.02rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: .5rem;
}

.icon-sparkle { color: var(--accent-gold); }

.section-desc {
    color: var(--text-secondary);
    font-size: .84rem;
    line-height: 1.6;
}

/* ---- ปุ่มเลือกประเภทหนังสือ ---- */

.template-selector-list {
    display: flex;
    flex-direction: column;
    gap: .4rem;
}

.template-btn {
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: .7rem .75rem;
    display: flex;
    align-items: center;
    gap: .8rem;
    cursor: pointer;
    text-align: left;
    color: var(--text-primary);
    font-family: var(--font-thai);
    transition: background .16s ease, border-color .16s ease;
    width: 100%;
}

.template-btn:hover { background: var(--surface-2); }

.template-btn.active {
    background: var(--accent-blue-soft);
    border-color: color-mix(in srgb, var(--accent-blue) 30%, transparent);
}

.btn-icon {
    font-size: 1.05rem;
    width: 36px;
    height: 36px;
    flex: none;
    display: grid;
    place-items: center;
    background: var(--surface-2);
    border-radius: 9px;
    transition: background .16s ease;
}

.template-btn.active .btn-icon { background: var(--surface); }

.btn-text { min-width: 0; flex: 1; }

.btn-text strong {
    display: block;
    font-family: var(--font-display);
    font-size: .92rem;
    font-weight: 500;
    line-height: 1.35;
    color: var(--text-primary);
}

.template-btn.active .btn-text strong { color: var(--accent-blue-ink); }

.btn-text small {
    display: block;
    font-size: .76rem;
    color: var(--text-faint);
    line-height: 1.4;
}

.btn-more-dots {
    font-size: 1.15rem;
    color: var(--text-faint);
    margin-left: auto;
    font-weight: 700;
    line-height: 1;
}

#btn-tmpl-others.active .btn-more-dots { color: var(--accent-blue-ink); }

/* ---- รายการหนังสืออื่น ๆ ---- */

.others-templates-dropdown {
    display: flex;
    flex-direction: column;
    gap: .2rem;
    padding: .45rem;
    background: var(--surface-2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    animation: slideDown .25s ease-out;
}

.others-templates-dropdown.hidden { display: none; }

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.sub-template-btn {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: .55rem .7rem;
    color: var(--text-secondary);
    text-align: left;
    font-size: .87rem;
    font-weight: 500;
    font-family: var(--font-display);
    display: flex;
    align-items: center;
    gap: .6rem;
    cursor: pointer;
    transition: background .16s ease, color .16s ease;
    width: 100%;
}

.sub-template-btn:hover { background: var(--surface); color: var(--text-primary); }

.sub-template-btn.active {
    background: var(--surface);
    border-color: color-mix(in srgb, var(--accent-blue) 32%, transparent);
    color: var(--accent-blue-ink);
}

.sub-icon { font-size: .95rem; }

/* ---- สถิติ ---- */

.quick-stats-card {
    background: var(--surface-2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 1rem;
}

.quick-stats-card h3 {
    font-size: .82rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: .7rem;
}

.stats-row { display: flex; justify-content: space-around; }

.stat-item { text-align: center; }

.stat-num {
    display: block;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--accent-blue);
    font-family: var(--font-display);
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.stat-label { font-size: .74rem; color: var(--text-faint); }

.stat-topline {
    margin-top: .8rem;
    padding-top: .7rem;
    border-top: 1px solid var(--border-color);
    font-size: .78rem;
    color: var(--text-secondary);
    text-align: center;
    min-height: 1em;
}

.stat-topline:empty { display: none; }

.stat-topline b { color: var(--accent-blue-ink); font-weight: 600; }

/* ---- ประวัติดาวน์โหลด ---- */

.history-card {
    background: var(--surface-2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 1rem;
}

.history-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: .6rem;
}

.history-head h3 {
    font-size: .82rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.history-refresh {
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 7px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: .95rem;
    line-height: 1;
}

.history-refresh:hover { color: var(--accent-blue); border-color: var(--accent-blue); }

.history-list {
    display: flex;
    flex-direction: column;
    gap: .4rem;
    max-height: 340px;
    overflow-y: auto;
}

.history-empty {
    font-size: .8rem;
    color: var(--text-faint);
    font-style: italic;
    text-align: center;
    padding: 1rem .5rem;
}

.history-item {
    display: flex;
    align-items: center;
    gap: .55rem;
    padding: .5rem .6rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: border-color .16s ease;
}

.history-item:hover { border-color: var(--border-strong); }

.history-item .h-icon { font-size: 1rem; flex: none; }

.history-item .h-body { min-width: 0; flex: 1; }

.history-item .h-title {
    font-size: .82rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item .h-meta {
    font-size: .7rem;
    color: var(--text-faint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item .h-actions { display: flex; gap: .25rem; flex: none; }

.history-item .h-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 7px;
    background: transparent;
    border: 1px solid var(--border-color);
    font-size: .9rem;
    line-height: 1;
    display: grid;
    place-items: center;
}

.history-item .h-btn.dl { color: var(--accent-blue); }
.history-item .h-btn.dl:hover { background: var(--accent-blue-soft); border-color: var(--accent-blue); }
.history-item .h-btn.del { color: var(--error); }
.history-item .h-btn.del:hover { background: var(--error-soft); border-color: var(--error); }

/* =====================  Wizard  ===================== */

.wizard-steps-indicator {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding: .25rem 0;
}

.step-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .45rem;
    font-size: .78rem;
    color: var(--text-faint);
    width: 76px;
    text-align: center;
    cursor: pointer;
    font-weight: 500;
    font-family: var(--font-display);
    transition: color .2s ease;
}

.step-node::before {
    content: '';
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--surface-2);
    border: 1px solid var(--border-color);
    color: var(--text-faint);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .82rem;
    font-weight: 600;
    z-index: 2;
    transition: background .2s ease, border-color .2s ease, color .2s ease;
}

.step-node[data-step="1"]::before { content: '1'; }
.step-node[data-step="2"]::before { content: '2'; }
.step-node[data-step="3"]::before { content: '3'; }
.step-node[data-step="4"]::before { content: '4'; }

.step-node.active { color: var(--text-primary); }

.step-node.active::before {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: #fff;
}

.step-node.completed { color: var(--success); }

.step-node.completed::before {
    background: var(--success);
    border-color: var(--success);
    content: '✓';
    color: #fff;
}

.line-progress {
    flex: 1;
    height: 2px;
    background: var(--border-color);
    margin: -24px 8px 0;
    border-radius: 2px;
    z-index: 1;
    transition: background .25s ease;
}

.line-progress.active    { background: var(--accent-blue); }
.line-progress.completed { background: var(--success); }

.step-content {
    display: none;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity .3s ease, transform .3s ease;
}

.step-content.active {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.step-title {
    font-size: 1.12rem;
    font-weight: 600;
    margin-bottom: 1.2rem;
    color: var(--text-primary);
    border-left: 3px solid var(--accent-gold);
    padding-left: .7rem;
    line-height: 1.4;
}

.step-desc {
    color: var(--text-secondary);
    font-size: .87rem;
    margin-bottom: 1.1rem;
    line-height: 1.6;
}

/* =====================  Forms  ===================== */

.form-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.1rem;
}

.col-span-1 { grid-column: span 1; }
.col-span-2 { grid-column: span 2; }
.col-span-3 { grid-column: span 3; }
.col-span-4 { grid-column: span 4; }

.form-group {
    display: flex;
    flex-direction: column;
    gap: .4rem;
    margin-bottom: 1.1rem;
}

label {
    font-size: .85rem;
    font-weight: 500;
    font-family: var(--font-display);
    color: var(--text-primary);
}

input[type="text"],
input[type="date"],
select,
textarea {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    padding: .68rem .85rem;
    color: var(--text-primary);
    font-family: var(--font-thai);
    font-size: .93rem;
    transition: border-color .16s ease, box-shadow .16s ease;
    width: 100%;
}

input::placeholder, textarea::placeholder { color: var(--text-faint); }

input[type="text"]:focus,
input[type="date"]:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-blue) 15%, transparent);
}

textarea { resize: vertical; line-height: 1.65; }

.input-with-prefix {
    display: flex;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    overflow: hidden;
}

.input-with-prefix:focus-within {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-blue) 15%, transparent);
}

.input-with-prefix input {
    background: transparent;
    border: none;
    border-radius: 0;
}

.input-with-prefix input:focus { background: transparent; box-shadow: none; }

.input-prefix {
    padding: 0 .7rem;
    color: var(--text-secondary);
    font-size: .9rem;
    font-weight: 600;
    white-space: nowrap;
}

.input-divider { color: var(--text-faint); font-size: 1.1rem; }

.help-text {
    font-size: .76rem;
    color: var(--text-faint);
    line-height: 1.5;
}

.step-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.roster-fetcher-area {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}

.date-picker-sm {
    padding: .4rem .7rem !important;
    width: 145px !important;
    font-size: .84rem !important;
}

/* ---- Autocomplete ---- */

.autocomplete-wrapper { position: relative; flex: 1; }

.add-officer-control {
    display: flex;
    gap: .7rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.autocomplete-items {
    position: absolute;
    border: 1px solid var(--border-color);
    background: var(--surface);
    border-radius: var(--radius-sm);
    z-index: 99;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 260px;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.autocomplete-items div {
    padding: .65rem .9rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    font-size: .89rem;
    transition: background .16s ease;
}

.autocomplete-items div:last-child { border-bottom: none; }
.autocomplete-items div:hover { background: var(--surface-2); }

.autocomplete-active {
    background: var(--accent-blue-soft) !important;
    color: var(--accent-blue-ink) !important;
}

/* ---- ตาราง ---- */

.table-container {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
    overflow-x: auto;
    background: var(--surface);
    margin-top: 1rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: .89rem;
}

th, td {
    padding: .8rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

th {
    background: var(--surface-2);
    font-weight: 600;
    font-family: var(--font-display);
    color: var(--text-secondary);
    font-size: .78rem;
    letter-spacing: .3px;
    white-space: nowrap;
}

td { color: var(--text-primary); }
tr:last-child td { border-bottom: none; }

.empty-row-placeholder {
    text-align: center;
    color: var(--text-faint);
    font-style: italic;
}

.empty-row-placeholder td { padding: 2.25rem 0; }

.table-select-sm { padding: .4rem .65rem; font-size: .84rem; }

/* =====================  Buttons  ===================== */

button {
    font-family: var(--font-display);
    font-weight: 500;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: .68rem 1.25rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    font-size: .92rem;
    transition: filter .16s ease, background .16s ease, border-color .16s ease, color .16s ease, transform .05s ease;
}

button:active { transform: translateY(1px); }

.btn-primary {
    background: var(--accent-blue);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn-primary:disabled {
    background: var(--surface-3);
    color: var(--text-faint);
    cursor: not-allowed;
    box-shadow: none;
}

.btn-secondary {
    background: var(--surface);
    color: var(--text-secondary);
    border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
    color: var(--text-primary);
    border-color: var(--text-faint);
}

.btn-secondary:disabled { opacity: .45; cursor: not-allowed; }

.btn-accent {
    background: var(--accent-gold);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.btn-accent:hover { filter: brightness(1.08); }

.btn-sm { padding: .45rem .8rem; font-size: .82rem; }

.btn-delete-row {
    background: var(--error-soft);
    color: var(--error);
    border-color: color-mix(in srgb, var(--error) 25%, transparent);
    padding: .35rem .7rem;
    font-size: .8rem;
    border-radius: 7px;
}

.btn-delete-row:hover { background: var(--error); color: #fff; }

.btn-generate-docx {
    background: var(--accent-blue);
    color: #fff;
    font-size: 1rem;
    padding: .95rem 2rem;
    border-radius: var(--radius-sm);
    width: 100%;
    box-shadow: var(--shadow-premium);
}

.btn-generate-docx:hover { filter: brightness(1.08); }

.glow-gold { animation: none; }

.action-box-premium {
    margin-top: 1.75rem;
    background: var(--accent-gold-soft);
    border: 1px solid color-mix(in srgb, var(--accent-gold) 28%, transparent);
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    align-items: stretch;
}

.action-info h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent-gold);
    margin-bottom: .3rem;
}

.action-info p {
    font-size: .86rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.wizard-footer {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-color);
}

/* ---- Segmented control ---- */

.segmented-control {
    display: inline-flex;
    background: var(--surface-2);
    border: 1px solid var(--border-color);
    border-radius: 9px;
    padding: 3px;
    gap: 2px;
}

.segment-btn {
    background: transparent;
    border: none;
    border-radius: 7px;
    padding: .38rem .8rem;
    font-size: .84rem;
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 500;
    font-family: var(--font-display);
}

.segment-btn:hover { color: var(--text-primary); background: var(--surface); }

.segment-btn.active {
    background: var(--accent-blue);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

/* =====================  Toast  ===================== */

.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--accent-blue);
    padding: .9rem 1.25rem;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    font-size: .92rem;
    max-width: min(420px, calc(100vw - 3rem));
    transition: opacity .3s ease, transform .3s ease;
}

.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--error); }

.toast.hidden {
    opacity: 0;
    transform: translateY(80px);
    pointer-events: none;
}

/* =====================  PDF upload  ===================== */

.pdf-upload-zone { margin-bottom: 1.5rem; }

.pdf-upload-zone h4 {
    font-size: .92rem;
    font-weight: 600;
    color: var(--accent-gold);
    margin-bottom: .8rem;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.upload-drop-area {
    border: 1.5px dashed var(--border-strong);
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    cursor: pointer;
    transition: border-color .16s ease, background .16s ease;
    text-align: center;
}

.upload-drop-area:hover,
.upload-drop-area.drag-over {
    border-color: var(--accent-blue);
    background: var(--accent-blue-soft);
}

.upload-icon { font-size: 1.6rem; transition: transform .2s ease; }
.upload-drop-area:hover .upload-icon { transform: scale(1.08); }

.upload-text { font-size: .88rem; color: var(--text-secondary); }
.upload-text strong { color: var(--accent-blue); font-weight: 600; }

.upload-action-bar {
    display: flex;
    gap: .6rem;
    margin-top: .8rem;
    flex-wrap: wrap;
    animation: slideDown .25s ease-out;
}

.upload-action-bar.hidden { display: none; }

/* =====================================================================
   กระดาษเอกสาร A4 — คงสีกระดาษจริงทั้งสองธีม
   ===================================================================== */

.document-preview-box {
    background: var(--paper);
    color: var(--paper-ink);
    border: 1px solid var(--paper-edge);
    border-radius: 6px;
    padding: 3rem 3.25rem;
    max-width: 860px;
    margin: 1.25rem auto;
    font-family: var(--font-thai);
    box-shadow: var(--shadow-lg);
    position: relative;
}

.dynamic-canvas { font-family: var(--font-thai); color: var(--paper-ink); }

.garuda-zone { text-align: center; margin-bottom: 1.5rem; }

.garuda-img {
    width: 105px;
    height: auto;
}

/* ช่องกรอกในกระดาษ */
.inline-input-fill {
    background: var(--paper-field);
    border: none;
    border-bottom: 1px dashed var(--paper-accent);
    color: var(--paper-accent);
    font-size: 1.02rem;
    padding: .12rem .45rem;
    font-family: inherit;
    font-weight: 600;
    border-radius: 4px 4px 0 0;
    transition: background .16s ease, border-color .16s ease;
}

.inline-input-fill:focus {
    outline: none;
    background: #e4edfb;
    border-bottom: 2px solid var(--paper-accent);
    color: #0f2f66;
}

.inline-input-fill::placeholder { color: #9bb0d4; }

.saraban-paragraph {
    text-indent: 2.5rem;
    font-size: 1.06rem;
    line-height: 1.85;
    margin-bottom: 1.1rem;
    text-align: justify;
    color: var(--paper-ink);
}

.ai-textarea-fill {
    width: 100%;
    background: var(--paper-field);
    border: 1px dashed #b9c8e2;
    border-radius: 8px;
    color: var(--paper-ink);
    font-size: 1.05rem;
    line-height: 1.8;
    font-family: inherit;
    padding: .7rem 1rem;
    resize: vertical;
}

.ai-textarea-fill:focus {
    outline: none;
    border-color: var(--paper-accent);
    border-style: solid;
    background: #fff;
}

.canvas-row {
    display: flex;
    align-items: center;
    gap: .45rem;
    margin-bottom: .65rem;
    flex-wrap: wrap;
}

.canvas-label {
    font-weight: 700;
    font-size: 1.04rem;
    color: var(--paper-ink);
    white-space: nowrap;
}

.canvas-para-indent { text-indent: 2.5rem; }

/* หัวกระดาษแต่ละแบบ */
.doc-header-external {
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 1.25rem;
    margin-bottom: 1.75rem;
    align-items: start;
}

.doc-header-external .garuda-zone { text-align: left; margin-bottom: 0; }

.doc-header-external .dept-address-zone {
    text-align: right;
    font-size: 1rem;
    color: var(--paper-ink);
    line-height: 1.6;
}

.doc-header-internal {
    border-bottom: 2px solid var(--paper-ink);
    padding-bottom: .9rem;
    margin-bottom: 1.35rem;
}

.memo-title-row {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin-bottom: .9rem;
}

.memo-title-row .garuda-img { width: 56px; }

.memo-title-text {
    font-size: 1.75rem;
    font-weight: 700;
    font-family: var(--font-display);
    color: var(--paper-ink);
    letter-spacing: .5px;
}

.memo-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .6rem 1.25rem;
    font-size: 1.02rem;
}

.memo-meta-full { grid-column: span 2; }

.doc-header-center { text-align: center; margin-bottom: 1.75rem; }
.doc-header-center .garuda-zone { text-align: center; margin-bottom: .9rem; }

.doc-title-main {
    font-size: 1.3rem;
    font-weight: 700;
    font-family: var(--font-display);
    color: var(--paper-ink);
    margin-bottom: .2rem;
}

.doc-subtitle-no {
    font-size: 1.05rem;
    font-weight: 500;
    color: var(--paper-ink-2);
    margin-bottom: .4rem;
}

.doc-subject-line {
    font-size: 1.06rem;
    font-weight: 700;
    color: var(--paper-ink);
    margin-bottom: 1.35rem;
}

.stamped-header { margin-bottom: 1.75rem; }

.regulation-rule-item {
    margin-bottom: .65rem;
    padding-left: 1.5rem;
    position: relative;
}

/* รายชื่อเจ้าหน้าที่ในกระดาษ */
.officers-preview-section {
    margin-left: 2rem;
    font-size: 1.02rem;
    margin-bottom: 1.35rem;
}

.officers-preview-list {
    display: flex;
    flex-direction: column;
    gap: .45rem;
    margin-bottom: .9rem;
}

.officer-preview-row {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .45rem .8rem;
    background: var(--paper-field);
    border: 1px solid #dbe4f3;
    border-radius: 7px;
}

.officer-preview-row:hover { border-color: var(--paper-accent); }

.officer-row-num { font-weight: 700; color: var(--paper-accent); }
.officer-row-name { flex: 1; font-weight: 500; }

.inline-officer-manager {
    background: var(--paper-field);
    border: 1px solid #dbe4f3;
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin-top: 1.25rem;
    display: flex;
    flex-wrap: wrap;
    gap: .8rem;
    align-items: center;
}

/* บล็อกลงนาม */
.signature-block-a4,
.doc-signature-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin: 2.75rem 0 1.25rem auto;
    max-width: 380px;
    padding-top: 1.25rem;
}

.doc-signature-closing {
    font-size: 1.06rem;
    margin-bottom: 1.25rem;
    text-align: center;
    margin-left: auto;
    max-width: 380px;
}

.signer-select-inline {
    font-size: 1.02rem;
    font-weight: 700;
    padding: .3rem .5rem;
    border-radius: 6px;
    text-align: center;
    text-align-last: center;
    background: var(--paper-field);
    border: 1px dashed var(--paper-accent);
    color: var(--paper-accent);
    width: auto;
}

.signer-select-inline:focus {
    outline: none;
    border-style: solid;
    box-shadow: none;
}

.red-stamp-circle {
    width: 90px;
    height: 90px;
    border: 2px dashed rgba(192, 57, 43, .55);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(192, 57, 43, .8);
    font-size: .72rem;
    font-weight: 700;
    text-align: center;
    margin: 1rem auto;
    transform: rotate(-10deg);
    pointer-events: none;
    user-select: none;
}

.doc-footer-meta {
    margin-top: 2.75rem;
    border-top: 1px solid var(--paper-edge);
    padding-top: .9rem;
    font-size: .9rem;
    color: var(--paper-ink-2);
    display: flex;
    flex-direction: column;
    gap: .2rem;
}

/* กระดาษ: input ทั่วไปที่ตกมาอยู่ในกระดาษ */
.document-preview-box label { color: var(--paper-ink); }

.document-preview-box select:not(.signer-select-inline),
.document-preview-box input[type="text"]:not(.inline-input-fill),
.document-preview-box input[type="date"] {
    background: #fff;
    color: var(--paper-ink);
    border-color: #c6d2e6;
}

/* =====================================================================
   หน้าแรก (Welcome) — คงลักษณะเดิม
   ===================================================================== */

.welcome-container {
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    animation: fadeIn .5s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.welcome-content { max-width: 700px; margin: 0 auto; }

.welcome-image-wrapper {
    position: relative;
    width: 220px;
    height: 220px;
    margin: 0 auto 1.75rem;
    border-radius: 50%;
    padding: 5px;
    background: linear-gradient(135deg, var(--accent-gold) 0%, var(--accent-blue) 100%);
    box-shadow: var(--shadow-lg);
}

.welcome-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    border: 4px solid var(--surface);
    display: block;
}

.image-glow {
    position: absolute;
    inset: -10px;
    border-radius: 50%;
    background: radial-gradient(circle, color-mix(in srgb, var(--accent-blue) 22%, transparent) 0%, transparent 70%);
    z-index: -1;
    animation: pulseGlow 4s infinite alternate;
}

@keyframes pulseGlow {
    0%   { transform: scale(.95); opacity: .45; }
    100% { transform: scale(1.08); opacity: .85; }
}

.welcome-title {
    font-size: 1.75rem;
    font-weight: 600;
    font-family: var(--font-display);
    margin-bottom: .35rem;
    color: var(--text-primary);
    text-wrap: balance;
}

.welcome-subtitle {
    font-size: 1.02rem;
    color: var(--accent-blue);
    font-weight: 500;
    margin-bottom: 1.25rem;
}

.welcome-divider {
    width: 72px;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-gold) 0%, var(--accent-blue) 100%);
    margin: 0 auto 1.25rem;
    border-radius: 2px;
}

.welcome-desc {
    color: var(--text-secondary);
    font-size: .98rem;
    line-height: 1.8;
    margin-bottom: 2rem;
    max-width: 62ch;
    margin-left: auto;
    margin-right: auto;
}

.feature-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .9rem;
    text-align: left;
    margin-bottom: 2rem;
}

.feature-item {
    background: var(--surface-2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.1rem;
    display: flex;
    gap: .9rem;
    align-items: flex-start;
    transition: border-color .2s ease, transform .2s ease;
}

.feature-item:hover {
    border-color: color-mix(in srgb, var(--accent-blue) 35%, transparent);
    transform: translateY(-2px);
}

.feature-icon {
    font-size: 1.35rem;
    width: 42px;
    height: 42px;
    flex: none;
    background: var(--surface);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.feature-text { display: flex; flex-direction: column; gap: .3rem; }

.feature-text strong {
    font-size: .92rem;
    font-family: var(--font-display);
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.4;
}

.feature-text span {
    font-size: .81rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.welcome-action-box {
    background: var(--accent-gold-soft);
    border: 1px dashed var(--accent-gold);
    padding: .9rem 1.4rem;
    border-radius: var(--radius-sm);
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: .4rem;
}

.welcome-action-box p { font-size: .94rem; color: var(--text-primary); }
.welcome-action-box strong { color: var(--accent-gold); font-weight: 600; }

.pulsing-arrow { font-size: 1.35rem; animation: bounce 1.6s infinite; }

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-6px); }
}

/* =====================  PDF Preview Modal  ===================== */

.pdf-modal {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.pdf-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(9, 13, 22, .62);
    backdrop-filter: blur(3px);
}

.pdf-modal-box {
    position: relative;
    z-index: 1;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: min(920px, 100%);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalIn .2s ease-out;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(12px) scale(.99); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.pdf-modal-head {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.pdf-modal-head h3 { font-size: 1.05rem; color: var(--text-primary); }

.pdf-modal-hint {
    font-size: .8rem;
    color: var(--text-faint);
}

.pdf-modal-close {
    margin-left: auto;
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text-secondary);
    font-size: 1rem;
}

.pdf-modal-close:hover { background: var(--surface-3); color: var(--text-primary); }

.pdf-modal-body {
    flex: 1;
    overflow: auto;
    background: #e9edf3;
    padding: 1rem;
}

#pdf-preview-frame {
    width: 100%;
    height: 68vh;
    border: none;
    background: #e9edf3;
    display: block;
}

.pdf-modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: .75rem;
    padding: .9rem 1.25rem;
    border-top: 1px solid var(--border-color);
}

@media (max-width: 720px) {
    .pdf-modal { padding: 0; }
    .pdf-modal-box { max-height: 100vh; height: 100vh; width: 100%; border-radius: 0; }
    #pdf-preview-frame { height: 60vh; }
    .pdf-modal-foot { flex-direction: column-reverse; }
    .pdf-modal-foot button { width: 100%; }
}

/* =====================  จัดกำลัง ถปภ.  ===================== */

.tapaphor-view {
    display: flex;
    flex-direction: column;
    gap: 1.35rem;
    animation: fadeIn .35s ease-out;
}

.tp-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.tp-title { font-size: 1.3rem; color: var(--text-primary); }

.tp-sub {
    color: var(--text-secondary);
    font-size: .86rem;
    margin-top: .2rem;
    max-width: 60ch;
}

.tp-stats { display: flex; gap: .6rem; flex-wrap: wrap; }

.tp-stat {
    background: var(--surface-2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: .6rem 1rem;
    min-width: 108px;
    text-align: center;
}

.tp-stat-num {
    display: block;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.4rem;
    color: var(--accent-blue);
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.tp-stat-label { font-size: .72rem; color: var(--text-faint); }

.tp-grid {
    display: grid;
    grid-template-columns: 380px minmax(0, 1fr);
    gap: 1.35rem;
    align-items: start;
}

.tp-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: .75rem;
    flex-wrap: wrap;
}

.tp-card-head h3 { font-size: 1rem; color: var(--text-primary); }

.tp-count-label {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .84rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.tp-need {
    width: 64px !important;
    padding: .35rem .5rem !important;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.tp-hint { font-size: .78rem; color: var(--text-faint); margin-bottom: .7rem; }

.tp-next-list {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    max-height: 420px;
    overflow-y: auto;
    margin-bottom: 1rem;
}

.tp-next-item {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .55rem .7rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--surface);
    cursor: pointer;
    font-weight: 400;
    transition: border-color .16s ease, background .16s ease;
}

.tp-next-item:hover { border-color: var(--border-strong); }

.tp-next-item.is-on {
    background: var(--accent-blue-soft);
    border-color: color-mix(in srgb, var(--accent-blue) 35%, transparent);
}

.tp-next-item.is-spare { opacity: .62; border-style: dashed; }

.tp-next-item input[type="checkbox"] {
    width: 17px;
    height: 17px;
    accent-color: var(--accent-blue);
    flex: none;
}

.tp-q {
    display: inline-grid;
    place-items: center;
    min-width: 26px;
    height: 26px;
    padding: 0 .3rem;
    border-radius: 7px;
    background: var(--surface-2);
    color: var(--text-secondary);
    font-family: var(--font-display);
    font-weight: 600;
    font-size: .78rem;
    font-variant-numeric: tabular-nums;
}

.tp-next-item.is-on .tp-q { background: var(--accent-blue); color: #fff; }

.tp-who { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.tp-who strong {
    font-size: .88rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tp-who small {
    font-size: .72rem;
    color: var(--text-faint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tp-pts {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: .95rem;
    color: var(--accent-gold);
    font-variant-numeric: tabular-nums;
}

.tp-round-form {
    display: grid;
    grid-template-columns: 150px 1fr;
    gap: .6rem;
    margin-bottom: .9rem;
}

.tp-round-form label {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    font-size: .78rem;
    color: var(--text-secondary);
}

.tp-round-form input { padding: .5rem .65rem; font-size: .88rem; }

.tp-save { width: 100%; padding: .8rem 1rem; }

.tp-search { max-width: 260px; padding: .45rem .7rem !important; font-size: .85rem !important; }

.tp-table-wrap { margin-top: 0; max-height: 620px; overflow-y: auto; }

.tp-table th, .tp-table td { padding: .6rem .75rem; }

.tp-table thead th { position: sticky; top: 0; z-index: 1; }

.tp-table .num { text-align: center; font-variant-numeric: tabular-nums; }

.tp-table .tp-pos { color: var(--text-secondary); font-size: .84rem; }

.tp-table tr.tp-row-on td { background: var(--accent-blue-soft); }

.tp-adj {
    display: block;
    font-size: .68rem;
    color: var(--text-faint);
}

.tp-adj-btns { white-space: nowrap; }

.tapaphor-view .h-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 7px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: .95rem;
    line-height: 1;
    display: inline-grid;
    place-items: center;
}

.tapaphor-view .h-btn:hover { color: var(--accent-blue); border-color: var(--accent-blue); }
.tapaphor-view .h-btn.del { color: var(--error); }
.tapaphor-view .h-btn.del:hover { background: var(--error-soft); border-color: var(--error); }
.tapaphor-view .h-btn:disabled { opacity: .5; cursor: wait; }

.tp-rounds-list { display: flex; flex-direction: column; gap: .5rem; }

.tp-round {
    display: flex;
    align-items: flex-start;
    gap: .9rem;
    padding: .7rem .85rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.tp-round-date {
    flex: none;
    min-width: 88px;
    font-family: var(--font-display);
    font-weight: 500;
    font-size: .88rem;
    color: var(--accent-blue-ink);
}

.tp-round-body { flex: 1; min-width: 0; }

.tp-round-note { font-size: .85rem; color: var(--text-primary); margin-bottom: .35rem; }

.tp-round-names { display: flex; flex-wrap: wrap; gap: .3rem; }

.tp-chip {
    font-size: .74rem;
    padding: .15rem .55rem;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

@media (max-width: 1024px) {
    .tp-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
    .tp-round-form { grid-template-columns: 1fr; }
    .tp-search { max-width: none; width: 100%; }
    .tp-stat { flex: 1; min-width: 0; }
    .tp-round { flex-wrap: wrap; }
}

/* ---- ถปภ.: นำเข้าจากไฟล์คำสั่ง ---- */

.tp-hint-inline { margin: 0; }

.tp-drop { padding: 1.25rem 1rem; }

.tp-drop.is-busy {
    cursor: progress;
    border-style: solid;
    border-color: var(--accent-blue);
    background: var(--accent-blue-soft);
}

.tp-drop.is-busy .upload-icon { animation: bounce 1.2s infinite; }

.tp-import-result {
    margin-top: 1.1rem;
    padding-top: 1.1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: .9rem;
}

.tp-imp-meta {
    display: flex;
    align-items: center;
    gap: .6rem;
    min-width: 0;
}

.tp-badge {
    flex: none;
    font-family: var(--font-display);
    font-weight: 500;
    font-size: .74rem;
    padding: .2rem .65rem;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.tp-badge.is-ai {
    background: var(--accent-blue-soft);
    border-color: color-mix(in srgb, var(--accent-blue) 30%, transparent);
    color: var(--accent-blue-ink);
}

.tp-imp-file {
    font-size: .8rem;
    color: var(--text-faint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tp-warn {
    font-size: .85rem;
    padding: .65rem .85rem;
    border-radius: var(--radius-sm);
    background: var(--accent-gold-soft);
    border: 1px solid color-mix(in srgb, var(--accent-gold) 35%, transparent);
    color: var(--text-primary);
}

.tp-imp-fields {
    display: grid;
    grid-template-columns: 150px 160px 190px minmax(0, 1fr);
    gap: .7rem;
}

.tp-imp-fields label {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    font-size: .78rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.tp-imp-fields label small { font-weight: 400; color: var(--text-faint); }

.tp-imp-fields input { padding: .5rem .65rem; font-size: .88rem; }

.tp-date-th {
    font-size: .76rem;
    font-weight: 600;
    color: var(--accent-blue-ink);
}

.tp-imp-key input {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-blue) 12%, transparent);
    font-weight: 600;
}

.tp-imp-table { margin-top: 0; max-height: 420px; overflow-y: auto; }

.tp-imp-table th, .tp-imp-table td { padding: .55rem .75rem; vertical-align: middle; }

.tp-imp-table thead th { position: sticky; top: 0; z-index: 1; }

.tp-imp-table .num { text-align: center; width: 54px; }

.tp-imp-table input[type="checkbox"] {
    width: 17px;
    height: 17px;
    accent-color: var(--accent-blue);
}

.tp-imp-map { padding: .35rem .55rem; font-size: .83rem; max-width: 260px; }

.tp-role {
    font-size: .74rem;
    padding: .12rem .55rem;
    border-radius: 999px;
    background: var(--accent-gold-soft);
    color: var(--accent-gold);
    font-weight: 600;
    white-space: nowrap;
}

.tp-ok { color: var(--success); font-weight: 600; font-size: .84rem; }

.tp-muted { color: var(--text-faint); font-size: .76rem; }

.tp-imp-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.tp-imp-sum { font-size: .88rem; color: var(--text-secondary); }

.tp-imp-sum b { color: var(--accent-blue-ink); }

.tp-imp-btns { display: flex; gap: .6rem; }

/* ประวัติรอบ: เลขคำสั่ง + หน้าที่ + ไฟล์ */
.tp-round-date small {
    display: block;
    font-family: var(--font-thai);
    font-weight: 400;
    font-size: .72rem;
    color: var(--text-faint);
}

.tp-chip.has-role { border-color: color-mix(in srgb, var(--accent-gold) 40%, transparent); }

.tp-chip em {
    font-style: normal;
    font-weight: 600;
    color: var(--accent-gold);
    margin-left: .2rem;
}

.tp-round-actions { display: flex; gap: .3rem; flex: none; }

.tapaphor-view a.h-btn { text-decoration: none; }

@media (max-width: 1024px) {
    .tp-imp-fields { grid-template-columns: 1fr 1fr; }
    .tp-imp-wide { grid-column: span 2; }
}

@media (max-width: 720px) {
    .tp-imp-fields { grid-template-columns: 1fr; }
    .tp-imp-wide { grid-column: span 1; }
    .tp-imp-btns { width: 100%; }
    .tp-imp-btns button { flex: 1; }
}

/* =====================  Utilities  ===================== */

.hidden { display: none !important; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* utility ที่ index.html เรียกใช้แบบ tailwind-ish */
.text-sm      { font-size: .88rem; }
.font-semibold{ font-weight: 600; }
.text-accent  { color: var(--accent-gold); }
.mb-3         { margin-bottom: .75rem; }
.flex         { display: flex; }
.items-center { align-items: center; }
.gap-2        { gap: .5rem; }
.flex-1       { flex: 1; }

/* =====================  Responsive  ===================== */

@media (max-width: 1024px) {
    .main-workspace { grid-template-columns: 1fr; }
    .panel-left { position: static; }
    .document-preview-box { padding: 2rem 1.75rem; }
}

@media (max-width: 720px) {
    .app-container { padding: 1rem .9rem 2.5rem; }

    .app-header {
        flex-wrap: wrap;
        gap: .75rem;
        padding: .85rem 1rem;
    }

    .header-nav-menu {
        margin-left: 0;
        width: 100%;
        order: 3;
        flex-wrap: wrap;
    }

    .nav-btn { flex: 1; justify-content: center; }
    .theme-toggle { order: 2; margin-left: auto; }

    .title-area h1 { font-size: 1.05rem; }
    .card { padding: 1.1rem; }
    .form-grid { grid-template-columns: 1fr; }
    .col-span-1, .col-span-2, .col-span-3, .col-span-4 { grid-column: span 1; }
    .feature-grid { grid-template-columns: 1fr; }
    .memo-meta-grid { grid-template-columns: 1fr; }
    .memo-meta-full { grid-column: span 1; }
    .doc-header-external { grid-template-columns: 1fr; }
    .doc-header-external .garuda-zone { text-align: center; }
    .doc-header-external .dept-address-zone { text-align: center; }

    .document-preview-box { padding: 1.5rem 1.15rem; }
    .saraban-paragraph { font-size: .98rem; text-indent: 1.75rem; }
    .welcome-image-wrapper { width: 170px; height: 170px; }
    .toast { left: 1rem; right: 1rem; bottom: 1rem; max-width: none; }
    .wizard-footer { flex-direction: column-reverse; }
    .wizard-footer button { width: 100%; }
    .step-node { width: 60px; font-size: .7rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
