/* Shared visual language. Page-specific document and print styles remain in pages/. */
:root {
    --bg-body: #f4f8fc;
    --bg-surface: #fff;
    --bg-sidebar: #ffffff;
    --text-primary: #182239;
    --text-secondary: #66728a;
    --border-light: #e4e8f2;
    --primary: #0875c9;
    --primary-hover: #0661a8;
    --success: #16825d;
    --danger: #c53d4d;
    --input-bg: #fff;
    --header-height: 72px;
    --sidebar-width: 232px;
    --shadow-sm: 0 2px 8px rgb(15 23 42 / 4%);
    --shadow-md: 0 8px 28px rgb(15 23 42 / 7%);
    --shadow-lg: 0 24px 80px rgb(15 23 42 / 18%);
}
* { box-sizing: border-box; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
body { font-family: 'Sarabun', 'Inter', sans-serif; -webkit-font-smoothing: antialiased; letter-spacing: 0; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; }
button:disabled { cursor: wait; opacity: .65; }
:focus-visible { outline: 3px solid #78bff2; outline-offset: 3px; }
input[type="file"] { font-size: 14px; color: var(--text-secondary); }
input[type="file"]::file-selector-button { border: 0; border-radius: 7px; background: #edf7ff; color: #0661a8; padding: 9px 14px; margin-right: 12px; font: inherit; cursor: pointer; }
.modal-box { box-shadow: var(--shadow-lg); }
.table-container { border-radius: 12px; }
input, textarea, select { transition: border-color .15s, box-shadow .15s; }
input:focus, textarea:focus, select:focus { border-color: #78bff2; }
.page-state { margin: auto; max-width: 520px; padding: 48px 28px; text-align: center; }
.page-state > i { font-size: 40px; color: var(--primary); }
.page-state h1 { font-size: 24px; margin: 20px 0 12px; }
.page-state p { color: var(--text-secondary); line-height: 1.8; }
.state-link { display: inline-flex; padding: 12px 20px; margin-top: 12px; border-radius: 10px; background: var(--primary); color: white; text-decoration: none; }
.connection-notice { padding: 12px 16px; background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; border-radius: 10px; margin-bottom: 16px; font-size: 14px; }
.record-actions { position: fixed; z-index: 50; bottom: max(12px, env(safe-area-inset-bottom)); left: var(--dock-left, 16px); width: var(--dock-width, calc(100% - 32px)); padding: 12px; margin: 0 !important; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: #fff; border: 1px solid var(--border-light); border-radius: 14px; box-shadow: 0 6px 30px rgb(15 23 42 / 15%); }
.record-actions button { flex: 1 1 auto !important; width: auto !important; min-height: 42px; padding: 9px 12px !important; margin: 0 !important; justify-content: center; font-size: 13px; white-space: nowrap; }
.record-selection-count { flex-basis: 100%; font-size: 13px; color: var(--text-secondary); }
.record-select-all { display: flex; align-items: center; gap: 10px; margin: 0 0 16px; font-size: 14px; cursor: pointer; }
.record-select-all input, .record-check { width: 18px; height: 18px; accent-color: var(--primary); flex-shrink: 0; }
.record-history-heading { display: flex; gap: 16px; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.record-history-heading h4 { margin: 0; font-size: 17px; }
.record-history-heading p { color: var(--text-secondary); font-size: 13px; margin: 6px 0 0; }
.time-history-card { background: #fff; padding: 18px; border: 1px solid var(--border-light); border-radius: 12px; margin-bottom: 12px; }
.time-history-top { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.time-history-title { display: flex; align-items: center; gap: 10px; }
.time-history-details { margin-top: 12px; font-size: 14px; line-height: 1.8; color: var(--text-secondary); overflow-wrap: anywhere; }
.record-danger { color: var(--danger); border-color: #fecaca; }
.archive-content { max-width: 1100px; margin-inline: auto; padding: 28px; }
.archive-content { height: 100%; overflow-y: auto; padding-bottom: 150px; }
.archive-action-dock { position: fixed; bottom: max(12px, env(safe-area-inset-bottom)); left: calc(var(--sidebar-width) + 24px); right: 24px; padding: 14px; display: flex; gap: 10px; flex-wrap: wrap; border: 1px solid var(--border-light); border-radius: 14px; background: #fff; box-shadow: var(--shadow-lg); z-index: 50; }
.archive-content .btn-outline, .archive-action-dock button { width: auto; height: auto; min-height: 42px; padding: 9px 12px; border-radius: 9px; white-space: nowrap; justify-content: center; }
.archive-content .btn-outline:hover { background: #edf7ff; color: var(--primary); border-color: #badef7; }
.archive-action-dock button { flex: 1 0 auto; min-width: 75px; white-space: normal; }
.archive-action-dock .record-danger:hover { background: #fef2f2; color: var(--danger); border-color: #fca5a5; }
@media (max-width: 768px) { .archive-content { padding: 20px 16px 190px; } .archive-action-dock { left: 16px; right: 16px; } }
@media print { .archive-action-dock { display: none !important; } }
.archive-tabs { display: flex; gap: 8px; margin: 20px 0; flex-wrap: wrap; }
.archive-tabs button { border: 1px solid var(--border-light); border-radius: 9px; background: #fff; padding: 10px 16px; cursor: pointer; }
.archive-tabs button.active { color: #fff; background: var(--primary); border-color: var(--primary); }
@media print { .record-actions, .record-select-all { display: none !important; } }
button, input, select, textarea { font-family: inherit; }
.ph, .ph-fill, .ph-bold { display: inline-flex; width: 1em; height: 1em; flex-shrink: 0; align-items: center; vertical-align: -.12em; }
.ph svg, .ph-fill svg, .ph-bold svg { width: 100%; height: 100%; }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
button { transition: background .18s, box-shadow .18s; }
button:disabled { opacity: .55; cursor: wait; transform: none !important; pointer-events: none; }
:focus-visible { outline: 3px solid #818cf8; outline-offset: 3px; }
input[type="checkbox"] { accent-color: var(--primary); }
textarea { line-height: 1.6; }
[hidden] { display: none !important; }
.top-header { background: #fff; box-shadow: none; padding: 0 28px; }
.header-brand { font-size: 19px; font-weight: 700; color: var(--text-primary); gap: 10px; }
.header-brand img { width: 36px; height: 40px; margin-left: 0; }
.header-actions { gap: 12px; }
.profile-btn { border: 1px solid var(--border-light); border-radius: 12px; background: #f8fafc; }
.profile-btn img { width: 34px; height: 34px; }
.left-sidebar { background: var(--bg-sidebar); width: var(--sidebar-width); border-right: 0; padding: 26px 12px; }
.left-sidebar .menu-title { margin: 0 14px 12px; color: #94a3b8; letter-spacing: .1em; font-size: 11px; }
.left-sidebar .menu-list { margin-bottom: 28px; }
.left-sidebar .menu-item { color: #cbd5e1; margin: 4px 0; padding: 13px 14px; border-radius: 10px; gap: 12px; font-weight: 500; font-size: 14px; }
.left-sidebar .menu-item i { color: #94a3b8; font-size: 21px; }
.left-sidebar .menu-item:hover { background: #1e293b; color: #fff; transform: none; }
.left-sidebar .menu-item.active { background: #0875c9; color: #fff; box-shadow: none; }
.left-sidebar .menu-item.active i { color: #dcefff; }
.main-content, .controls-panel, .preview-panel { min-width: 0; }
.main-content-split { padding: 24px; gap: 24px; }
.controls-panel { width: 430px; background: transparent; border: 0; box-shadow: none; }
.controls-panel .panel-header { padding: 0; border: 0; background: transparent; display: block; }
.controls-panel .panel-body { display: block; padding: 0 4px 24px; background: transparent; }
.panel-header { margin-bottom: 20px; }
.tabs { background: #e2e8f0; border: 0; border-radius: 12px; padding: 5px; gap: 4px; }
.tab-btn { border: 0; border-radius: 9px; min-height: 42px; font-weight: 600; padding: 11px 8px; }
.tab-btn.active { background: #fff; color: var(--primary); box-shadow: var(--shadow-sm); }
.box-card, .form-panel, .widget-card, .merger-card, .chat-container, .history-day, .stat-card, .table-container { border-radius: 16px; border: 1px solid var(--border-light); box-shadow: var(--shadow-sm); }
.box-card:hover, .stat-card:hover { transform: none; box-shadow: var(--shadow-sm); }
.box-card, .form-panel, .task-box { padding: 22px; }
.app-input { border-radius: 9px; background-color: #fff; padding: 12px 14px; font-size: 14px; min-height: 44px; }
.app-input:focus { border: 1px solid var(--primary); padding: 12px 14px; box-shadow: 0 0 0 3px rgb(37 99 235 / 12%); outline: none; }
.btn-outline { border-radius: 9px; min-height: 38px; }
.btn-save, .btn-add, .btn-primary, .export-pdf, .btn-export, .btn-merge, .btn-google { border-radius: 10px; box-shadow: none; min-height: 46px; font-weight: 600; }
.btn-save:hover, .btn-add:hover, .export-pdf:hover, .btn-google:hover { transform: none; box-shadow: 0 4px 12px rgb(37 99 235 / 14%); }
.btn-add-day, .btn-add-task { border-radius: 10px; }
.preview-panel { background: #e2e8f0; padding: 28px 0; border: 1px solid #cbd5e1; box-shadow: none; }
.modal-overlay { padding: 20px; background: rgb(15 23 42 / 55%); backdrop-filter: blur(4px); }
.modal-box { border-radius: 18px; max-height: 90dvh; box-shadow: var(--shadow-lg); }
.modal-header { background: #fff; padding: 18px 24px; }
.modal-header h2, .modal-header h3 { font-size: 18px; font-weight: 700; }
.modal-body { overscroll-behavior: contain; }
.sig-canvas-container { height: 180px; border-color: #badef7; background: #fff; }
/* Identical signature controls on both document pages. */
#view-template .box-card { background: #fff; margin-bottom: 16px; flex-shrink: 0; }
#view-template label, #edit-template-modal label { display: block; margin: 16px 0 8px; color: var(--text-primary); font-size: 13px; font-weight: 500; }
#view-template .btn-save, #edit-template-modal .btn-save { background: var(--primary); color: #fff; width: 100%; padding: 12px 24px; border: 0; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 14px; letter-spacing: .25px; }
#view-template .btn-save:hover, #edit-template-modal .btn-save:hover { background: var(--primary-hover); }
#view-template .btn-outline, #edit-template-modal .btn-outline { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: transparent; border: 1px solid var(--border-light); color: var(--text-secondary); padding: 8px 12px; font-size: 13px; font-weight: 500; cursor: pointer; }
#view-template .btn-outline:hover, #edit-template-modal .btn-outline:hover { background: #edf7ff; color: var(--primary); border-color: #badef7; }
.signature-template-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 16px; }
.signature-template-info { flex: 1 1 170px; min-width: 0; overflow-wrap: anywhere; }
.signature-template-info strong { display: block; font-size: 14px; color: var(--primary); }
.signature-template-info div { margin-top: 4px; font-size: 12px; line-height: 1.6; color: var(--text-secondary); }
.signature-template-actions { display: flex; align-items: center; gap: 8px; }
.signature-template-actions .btn-delete-item { background: transparent; color: var(--text-secondary); padding: 8px; border: 0; border-radius: 50%; width: 38px; height: 38px; font-size: 16px; font-weight: 500; display: inline-flex; justify-content: center; align-items: center; cursor: pointer; }
.signature-template-actions .btn-delete-item:hover { color: var(--danger); background: #fff1f2; }
.signature-template-empty { text-align: center; color: var(--text-secondary); padding: 20px; border: 1px dashed var(--border-light); border-radius: 8px; font-size: 14px; }
#edit-template-modal .modal-box { max-width: 600px; border: 0; }
#edit-template-modal .modal-body { display: block; }
#edit-template-modal .btn-close { background: transparent; border: 0; border-radius: 50%; width: 38px; height: 38px; padding: 8px; font-size: 20px; color: var(--text-secondary); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
#edit-template-modal .btn-close:hover { color: var(--primary); background: #edf7ff; }
#edit-template-modal img { max-width: 100%; object-fit: contain; }
.sig-canvas-container canvas { cursor: crosshair; }
.sidebar-backdrop { display: none; position: fixed; inset: var(--header-height) 0 0; z-index: 899; background: rgb(15 23 42 / 48%); border: 0; padding: 0; }
.skip-link { position: fixed; z-index: 10001; left: 16px; top: -60px; padding: 12px 18px; background: #fff; border: 2px solid var(--primary); border-radius: 8px; color: var(--primary); }
.skip-link:focus { top: 10px; }
.guest-notice { color: #866315; background: #fff5d9; border: 1px solid #f0dfa7; border-radius: 10px; font-size: 13px; padding: 10px 14px; margin-bottom: 16px; }
.controls-panel > .guest-notice { flex-shrink: 0; }
#preview-wrapper { background-color: #e2e8f0; }
.button-spinner { width: 16px; height: 16px; display: inline-block; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .75s linear infinite; }
.swal2-popup { font-family: 'Sarabun', sans-serif; border-radius: 18px; }
.swal2-confirm { background: var(--primary) !important; }
.content-padding { max-width: 1440px; margin-inline: auto; padding: 28px; width: 100%; }
.hero-banner { background: linear-gradient(115deg, #0661a8, #6366f1); border-radius: 20px; padding: 32px; box-shadow: none; }
.hero-info h2 { font-size: clamp(24px, 2.5vw, 32px); font-weight: 700; color: #fff; }
.hero-banner p { color: #dcefff; }
.hero-kpi { background: rgb(255 255 255 / 8%); border: 1px solid rgb(255 255 255 / 14%); border-radius: 12px; color: #fff; }
.hero-kpi .kpi-head, .hero-kpi .kpi-foot { color: #edf7ff; }
.section-title { margin-top: 28px; font-size: 17px; font-weight: 700; }
.module-grid { gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.module-card { border-radius: 14px; box-shadow: none; border: 1px solid var(--border-light); padding: 24px; }
.module-card:hover { border-color: #78bff2; box-shadow: var(--shadow-md); transform: translateY(-2px); }
.module-text h3 { font-size: 17px; }
.module-text p { font-size: 13px; line-height: 1.7; }
.module-icon { border-radius: 12px; }
.right-sidebar { border-left: 1px solid var(--border-light); background: #fff; }
.news-card { border-radius: 12px; overflow: hidden; box-shadow: none; }
.news-card:hover { transform: none; box-shadow: var(--shadow-sm); }
.news-title, .file-name { overflow-wrap: anywhere; }
.chat-input-area { gap: 10px; padding: 18px; }
.msg-bubble { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-me .msg-bubble { background: var(--primary); }
.sidebar { background: var(--bg-sidebar); box-shadow: none; }
.nav-item.active { box-shadow: none; }
.stats-grid { gap: 16px; }
.stat-card { padding: 24px; }
.topbar { background: #fff; backdrop-filter: none; }
.dashboard-scroll { padding: 28px; }
.file-item { min-width: 0; border-radius: 12px; }
.file-info, .file-info > div { min-width: 0; }
.file-name { white-space: normal; }
.file-order-button { width: 34px; height: 34px; border: 1px solid var(--border-light); background: #fff; border-radius: 7px; cursor: pointer; color: var(--text-secondary); }
.merged-result { padding: 18px; border: 1px solid #a8d5c6; border-radius: 12px; background: #eff9f5; margin-top: 20px; }
.merged-result a { color: var(--primary); font-weight: 600; display: inline-flex; padding: 10px 16px; border: 1px solid #a8d5c6; background: #fff; border-radius: 8px; margin: 8px 8px 0 0; text-decoration: none; }
/* Authentication */
.top-nav { background: transparent; padding: 24px 5vw; }
.split-layout { min-height: 100dvh; height: auto; }
.form-side { background: #f8fafc; padding: 100px 5vw 48px; }
.massive-title { font-size: clamp(38px, 5vw, 66px); line-height: 1.15; letter-spacing: -1px; font-weight: 700; }
.tagline { color: var(--primary); font-size: 11px; letter-spacing: .16em; }
.form-side > p.hero-desc { font-size: 16px; max-width: 460px; margin-bottom: 28px; font-weight: 400; }
.policy-container { border: 1px solid var(--border-light); border-radius: 12px; box-shadow: none; padding: 16px; }
.btn-google { background: var(--primary); padding: 16px; }
.btn-guest { border-radius: 10px; padding: 14px; }
.visual-side { background: #1e40af; }
.form-group input, .form-group select { border-radius: 9px; }
.profile-btn, .news-card[onclick], .dropzone-area, #drop-zone { cursor: pointer; }
.chip-remove { border: 0; padding: 2px; background: transparent; color: inherit; cursor: pointer; display: inline-flex; }
.empty-state { margin: auto; padding: 24px; text-align: center; color: var(--text-secondary); font-size: 14px; }
.mobile-news { margin-top: 24px; padding: 22px; }
.mobile-news h3 { font-size: 17px; margin: 0 0 16px; }
@media (max-width: 1280px) { .controls-panel { width: 380px; } .right-sidebar { width: 290px; } }
@media (max-width: 1100px) {
    .main-content-split { flex-direction: column; overflow-y: auto; align-items: stretch; }
    .controls-panel { width: 100%; flex-shrink: 0; overflow: visible; }
    .panel-body { overflow: visible; }
    .preview-panel { flex: none; width: 100%; min-height: 500px; max-height: 800px; }
    .main-content-split > .guest-notice { position: static; margin-bottom: 0; }
    .right-sidebar { display: none; }
}
@media (max-width: 768px) {
    body { height: 100dvh; }
    .layout-wrapper { height: calc(100dvh - var(--header-height)); }
    .top-header { padding: 0 14px; }
    .header-actions { gap: 6px; }
    .header-brand { width: auto; gap: 6px; font-size: 16px; }
    .header-brand img { width: 28px; height: 32px; }
    .profile-btn { padding: 4px; border-radius: 50%; }
    .btn-outline { padding: 8px; }
    .mobile-toggle { min-width: 38px; min-height: 38px; display: inline-flex; align-items: center; justify-content: center; }
    .left-sidebar { position: fixed; top: var(--header-height); bottom: 0; left: 0; transform: translateX(-100%); transition: transform .2s; width: 260px; z-index: 900; overflow-y: auto; }
    .left-sidebar.show { left: 0; transform: translateX(0); }
    .sidebar { position: fixed; inset: 0 auto 0 0; transform: translateX(-100%); z-index: 901; }
    .sidebar.show { left: 0; transform: translateX(0); }
    .sidebar-backdrop.visible { display: block; }
    .content-padding { padding: 18px 16px; }
    .main-content-split { padding: 16px; gap: 16px; }
    .hero-banner { padding: 24px; gap: 20px; }
    .module-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
    .module-card { padding: 18px; }
    .module-text h3 { font-size: 15px; }
    .box-card, .form-panel, .task-box { padding: 18px; }
    .modal-overlay { padding: 12px; }
    .modal-box { max-height: 94dvh; }
    .modal-body { padding: 18px; }
    .modal-header { padding: 16px 18px; }
    .modal-box table { min-width: 550px; }
    .modal-body, .table-container { overflow-x: auto; }
    .history-task > div { flex-wrap: wrap; }
    #template-list-container > div { flex-wrap: wrap; gap: 14px; }
    .dashboard-scroll { padding: 16px; }
    .topbar { padding: 0 16px; }
    .topbar-left h2 { font-size: 16px; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stat-card { padding: 16px; gap: 12px; }
    .stat-icon { width: 40px; height: 40px; font-size: 22px; flex-shrink: 0; }
    .stat-info h3 { font-size: 25px; }
    .stat-info p { font-size: 12px; }
    .split-layout { display: block; height: auto; }
    .form-side { min-height: 100dvh; padding: 108px 24px 40px; width: 100%; }
    .visual-side { display: none; }
    .auth-container { max-width: 100%; }
    .form-side > p.hero-desc { max-width: 100%; }
}
@media (max-width: 400px) { .module-grid { grid-template-columns: 1fr; } .header-brand > span { font-size: 14px; } .tabs { gap: 0; } .tab-btn { font-size: 12px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; } }
.controls-panel .panel-body { padding-bottom: 180px; }
.archive-content { width: 100%; min-height: 0; flex: 1; }
#archive-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
#archive-list .time-history-card { margin-bottom: 0; }
#archive-list .empty-state { grid-column: 1 / -1; }
@media (max-width: 768px) { #archive-list { grid-template-columns: 1fr; } }
@media print {
    .skip-link, .sidebar-backdrop, .guest-notice, .merged-result { display: none !important; }
    body { background: #fff; height: auto; }
    .pdf-page { color: #000; box-shadow: none; border-radius: 0; }
}
