/* ==================================================================
   ยอดทิพย์ธรรม — Timeline Builder ประกอบคดี
   styles.css : สไตล์กลางใช้ร่วมทุกหน้า
   ================================================================== */
:root{
  --ink:#1c2430;
  --paper:#f5f3ec;
  --card:#ffffff;
  --line:#e2ddd0;
  --line-strong:#c9c2b0;
  --red:#9e2b25;
  --gold:#a8843c;
  --navy:#16233d;      /* น้ำเงินเข้มจากโลโก้ */
  --muted:#5d6470;
  --focus:#1e5fae;

  --cat-fact:#1d5fbf;
  --cat-proc:#6d3fa4;
  --cat-doc:#a05e10;
  --cat-wit:#0f7a52;
  --cat-hear:#b3261e;

  --z-sticky:10; --z-backdrop:40; --z-modal:50; --z-toast:60; --z-login:100;
  --radius:10px;
  --shadow:0 1px 3px rgba(28,36,48,.08), 0 6px 20px rgba(28,36,48,.06);
}
*{box-sizing:border-box; margin:0; padding:0}
html{-webkit-text-size-adjust:100%}
body{
  font-family:'Sarabun','Leelawadee UI','Noto Sans Thai',Tahoma,sans-serif;
  background:var(--paper); color:var(--ink);
  font-size:16px; line-height:1.65;
}
button{font-family:inherit; cursor:pointer}
input,select,textarea{font-family:inherit; font-size:15px; color:var(--ink)}
h1,h2,h3{text-wrap:balance}
a{color:var(--focus)}

/* ---------- ปุ่มพื้นฐาน ---------- */
.btn{
  border:1px solid transparent; border-radius:8px;
  padding:8px 14px; font-size:14px; font-weight:600;
  transition:background .15s ease, border-color .15s ease, transform .1s ease;
  display:inline-flex; align-items:center; gap:6px; text-decoration:none;
}
.btn:active{transform:translateY(1px)}
.btn:focus-visible{outline:2px solid var(--focus); outline-offset:2px}
.btn-ghost{background:transparent; color:#e8e3d5; border-color:#4a5260}
.btn-ghost:hover{background:#2a3341; border-color:#6a7280}
.btn-primary{background:var(--red); color:#fff}
.btn-primary:hover{background:#b53a33}
.btn-gold{background:var(--gold); color:#fff}
.btn-gold:hover{background:#bd9850}
.btn-danger-ghost{background:transparent; color:#d8a5a2; border-color:#5a4442}
.btn-danger-ghost:hover{background:#3a2b2a}

/* ==================================================================
   APP HEADER (ใช้ใน app.html และ users.html)
   ================================================================== */
.app-header{
  position:sticky; top:0; z-index:var(--z-sticky);
  background:var(--ink); color:#f2efe6; border-bottom:3px solid var(--gold);
}
.app-header-inner{
  max-width:1040px; margin:0 auto; padding:10px 20px;
  display:flex; align-items:center; gap:14px; flex-wrap:wrap;
}
.brand{display:flex; align-items:center; gap:12px; margin-right:auto}
.brand img{height:42px; width:auto; display:block}
.brand-text .brand-mark{font-weight:700; font-size:17px; letter-spacing:.01em; line-height:1.15}
.brand-text .brand-sub{font-size:12px; color:#b9b2a0; font-weight:400}
.save-indicator{font-size:12.5px; color:#9db89d; white-space:nowrap}
.header-actions{display:flex; gap:8px; flex-wrap:wrap; align-items:center}
.user-tag{font-size:12.5px; color:#c8d0dc; padding:4px 10px; border:1px solid #3a4350; border-radius:999px; white-space:nowrap}
.user-tag b{color:var(--gold); font-weight:600}

.container{max-width:1040px; margin:0 auto; padding:24px 20px 90px}

/* ---------- ฟิลด์ทั่วไป ---------- */
.field label{display:block; font-size:13px; font-weight:600; color:var(--muted); margin-bottom:4px}
.field input, .field select, .field textarea{
  width:100%; padding:9px 12px; border:1px solid var(--line-strong);
  border-radius:7px; background:#fffdf8; transition:border-color .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus{
  outline:none; border-color:var(--focus); box-shadow:0 0 0 3px rgba(30,95,174,.12);
}

/* ==================================================================
   CASE CARD + TIMELINE (app.html)
   ================================================================== */
.case-card{
  background:var(--card); border:1px solid var(--line); border-top:4px solid var(--ink);
  border-radius:var(--radius); box-shadow:var(--shadow); margin-bottom:22px; overflow:hidden;
}
.case-card-head{
  display:flex; align-items:center; justify-content:space-between;
  padding:14px 20px; cursor:pointer; user-select:none;
  background:linear-gradient(to bottom, #fdfcf8, #f8f6ef); border-bottom:1px solid var(--line);
}
.case-card-head h2{font-size:16px; font-weight:700; display:flex; align-items:center; gap:8px}
.case-card-head h2::before{content:""; width:8px; height:8px; border-radius:50%; background:var(--gold)}
.case-summary{font-size:13px; color:var(--muted); font-weight:400; margin-left:8px}
.chevron{transition:transform .2s ease; font-size:12px; color:var(--muted)}
.case-card.collapsed .chevron{transform:rotate(-90deg)}
.case-card.collapsed .case-body{display:none}
.case-body{padding:18px 20px 22px}
.case-grid{display:grid; grid-template-columns:repeat(auto-fit,minmax(230px,1fr)); gap:14px 18px}
.field-black input{border-left:4px solid var(--ink)}
.field-red input{border-left:4px solid var(--red)}
.vs-row{display:grid; grid-template-columns:1fr auto 1fr; gap:10px; align-items:end}
.vs-row .vs{padding-bottom:10px; font-weight:700; color:var(--gold); font-size:14px}

.toolbar{display:flex; flex-wrap:wrap; gap:10px; align-items:center; margin-bottom:6px}
.toolbar .btn-add{background:var(--ink); color:#fff; padding:10px 18px; font-size:15px; border:none; border-radius:8px; font-weight:600}
.toolbar .btn-add:hover{background:#2c3a4e}
.search-wrap{position:relative; flex:1; min-width:200px}
.search-wrap input{width:100%; padding:10px 12px 10px 36px; border:1px solid var(--line-strong); border-radius:8px; background:#fffdf8}
.search-wrap input:focus{outline:none; border-color:var(--focus); box-shadow:0 0 0 3px rgba(30,95,174,.12)}
.search-wrap .icon{position:absolute; left:11px; top:50%; transform:translateY(-50%); color:var(--muted); font-size:15px}
.btn-sort{background:#fffdf8; border:1px solid var(--line-strong); color:var(--ink); padding:10px 14px; border-radius:8px; font-size:14px; font-weight:600}
.btn-sort:hover{border-color:var(--gold)}

.chips{display:flex; flex-wrap:wrap; gap:8px; margin:12px 0 4px}
.chip{
  border:1.5px solid var(--line-strong); background:#fffdf8; color:var(--muted);
  border-radius:999px; padding:5px 13px; font-size:13.5px; font-weight:600;
  display:inline-flex; align-items:center; gap:7px; transition:all .15s ease;
}
.chip .dot{width:9px; height:9px; border-radius:50%; background:currentColor; flex:none}
.chip .count{font-size:12px; font-weight:400; opacity:.75}
.chip:hover{border-color:var(--gold)}
.chip.active{color:#fff !important; border-color:transparent}
.chip:focus-visible{outline:2px solid var(--focus); outline-offset:2px}

.stats-line{font-size:13.5px; color:var(--muted); margin:6px 0 20px; display:flex; flex-wrap:wrap; gap:6px 18px}
.stats-line .next-hearing{color:var(--cat-hear); font-weight:600}

.timeline{position:relative; padding-left:34px}
.timeline::before{content:""; position:absolute; left:11px; top:6px; bottom:6px; width:2px;
  background:linear-gradient(var(--line-strong) 60%, transparent 0) center/2px 10px repeat-y;}
.year-seal{position:relative; margin:26px 0 18px -34px; display:flex; align-items:center; gap:12px}
.year-seal .seal{
  width:58px; height:58px; border-radius:50%; border:2px solid var(--red); color:var(--red);
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  background:#fffdf8; font-weight:700; line-height:1.1;
  box-shadow:inset 0 0 0 2px #fffdf8, inset 0 0 0 3.5px var(--red); transform:rotate(-4deg); flex:none;
}
.year-seal .seal small{font-size:9.5px; font-weight:600; letter-spacing:.05em}
.year-seal .seal span{font-size:17px}
.year-seal .seal-line{height:1px; background:var(--line-strong); flex:1}
.timeline .year-seal:first-child{margin-top:4px}

.tl-item{position:relative; margin-bottom:16px}
.tl-item .node{position:absolute; left:-29px; top:20px; width:14px; height:14px; border-radius:50%;
  border:3px solid var(--card); box-shadow:0 0 0 2px var(--line-strong);}
.tl-card{background:var(--card); border:1px solid var(--line); border-left:4px solid var(--line-strong);
  border-radius:var(--radius); box-shadow:var(--shadow); padding:14px 18px 15px; transition:box-shadow .15s ease;}
.tl-card:hover{box-shadow:0 2px 6px rgba(28,36,48,.12), 0 10px 28px rgba(28,36,48,.09)}
.tl-top{display:flex; align-items:flex-start; gap:10px; flex-wrap:wrap}
.tl-date{font-weight:700; font-size:15px}
.badge{font-size:12px; font-weight:600; color:#fff; border-radius:5px; padding:2px 9px; line-height:1.5; white-space:nowrap}
.badge-days{font-size:12px; font-weight:700; border-radius:5px; padding:2px 9px; background:#fbeae9; color:var(--cat-hear); border:1px solid #eecfcd; white-space:nowrap}
.tl-actions{margin-left:auto; display:flex; gap:6px}
.icon-btn{border:1px solid var(--line); background:#fdfcf8; border-radius:6px; font-size:12.5px; font-weight:600; color:var(--muted); padding:3px 10px}
.icon-btn:hover{border-color:var(--gold); color:var(--ink)}
.icon-btn.danger:hover{border-color:var(--red); color:var(--red)}
.icon-btn:focus-visible{outline:2px solid var(--focus); outline-offset:1px}
.tl-title{font-size:16.5px; font-weight:600; margin-top:5px}
.tl-detail{font-size:14.5px; color:#39414e; margin-top:4px; white-space:pre-line; max-width:72ch}
.tl-ref{margin-top:8px; font-size:13px; color:var(--muted); display:inline-flex; align-items:center; gap:6px;
  background:#f7f4ea; border:1px dashed var(--line-strong); border-radius:6px; padding:3px 10px;}

.empty{text-align:center; padding:56px 20px; color:var(--muted); border:2px dashed var(--line-strong);
  border-radius:var(--radius); background:#fbf9f3; margin-left:-34px;}
.empty .glyph{font-size:40px; margin-bottom:10px}
.empty p{max-width:46ch; margin:0 auto 18px}
.no-result{margin-left:-34px; text-align:center; color:var(--muted); padding:30px; font-size:14.5px}
.date-preview{font-size:12.5px; color:var(--gold); font-weight:600; margin-top:5px; min-height:18px}

/* ==================================================================
   MODAL + TOAST (ใช้ร่วม)
   ================================================================== */
.overlay{position:fixed; inset:0; background:rgba(28,36,48,.55); z-index:var(--z-backdrop);
  display:none; align-items:flex-start; justify-content:center; padding:6vh 16px 16px; overflow-y:auto;}
.overlay.open{display:flex}
.modal{background:var(--card); border-radius:12px; box-shadow:0 20px 60px rgba(0,0,0,.3);
  width:100%; max-width:560px; z-index:var(--z-modal); border-top:5px solid var(--ink);
  animation:pop .18s cubic-bezier(.22,1,.36,1);}
@keyframes pop{from{transform:translateY(10px); opacity:0} to{transform:none; opacity:1}}
.modal-head{padding:16px 22px 0; display:flex; justify-content:space-between; align-items:center}
.modal-head h3{font-size:18px; font-weight:700}
.modal-x{background:none; border:none; font-size:20px; color:var(--muted); line-height:1; padding:4px 8px; border-radius:6px}
.modal-x:hover{background:#f1ede2; color:var(--ink)}
.modal-body{padding:16px 22px 22px; display:grid; gap:14px}
.form-row-2{display:grid; grid-template-columns:1fr 1fr; gap:14px}
@media (max-width:520px){.form-row-2{grid-template-columns:1fr}}
.form-error{color:var(--red); font-size:13.5px; font-weight:600; display:none}
.form-error.show{display:block}
.modal-foot{display:flex; justify-content:flex-end; gap:10px; padding:0 22px 22px}
.btn-cancel{background:#f1ede2; color:var(--ink)}
.btn-cancel:hover{background:#e6e0d0}
.btn-save{background:var(--ink); color:#fff; padding:9px 22px}
.btn-save:hover{background:#2c3a4e}
.modal-small{max-width:430px}
.modal-small .modal-body{font-size:15px; color:#39414e}
.choice-btns{display:grid; gap:10px; padding:0 22px 22px}
.choice-btns .btn{justify-content:center; padding:11px}

.toast-wrap{position:fixed; bottom:22px; left:50%; transform:translateX(-50%); z-index:var(--z-toast); display:grid; gap:8px; width:min(92vw,420px)}
.toast{background:var(--ink); color:#f2efe6; border-left:4px solid var(--gold); border-radius:8px;
  padding:11px 16px; font-size:14px; box-shadow:0 8px 30px rgba(0,0,0,.25); animation:pop .2s cubic-bezier(.22,1,.36,1);}
.toast.warn{border-left-color:var(--red)}
.toast.ok{border-left-color:#4f9a6e}

.storage-note{display:none; font-size:13px; background:#fdf3e0; color:#7a5a17; border:1px solid #ecd9ad;
  border-radius:8px; padding:9px 14px; margin-bottom:16px;}
.storage-note.show{display:block}

/* ==================================================================
   LOGIN (index.html)
   ================================================================== */
.login-body{min-height:100vh; display:flex; align-items:center; justify-content:center;
  background:
    radial-gradient(1200px 500px at 70% -10%, rgba(168,132,60,.18), transparent 60%),
    radial-gradient(900px 600px at 10% 110%, rgba(158,43,37,.14), transparent 55%),
    linear-gradient(155deg, #161d27 0%, #1c2430 45%, #232c3a 100%);
  padding:24px;}
.login-shell{display:grid; grid-template-columns:1.05fr .95fr; width:100%; max-width:940px;
  background:var(--card); border-radius:16px; overflow:hidden;
  box-shadow:0 30px 80px rgba(0,0,0,.45), 0 0 0 1px rgba(168,132,60,.25);
  animation:loginIn .5s cubic-bezier(.22,1,.36,1);}
@keyframes loginIn{from{opacity:0; transform:translateY(18px) scale(.98)} to{opacity:1; transform:none}}
.login-brand{position:relative; color:#f2efe6; padding:44px 40px;
  background:linear-gradient(160deg,#1a222e 0%,#232d3c 100%);
  display:flex; flex-direction:column; justify-content:center; align-items:center; text-align:center;
  border-right:3px solid var(--gold); overflow:hidden;}
.login-brand::before{content:""; position:absolute; inset:0;
  background:repeating-linear-gradient(45deg, rgba(168,132,60,.05) 0 2px, transparent 2px 22px); pointer-events:none;}
.login-logo{position:relative; z-index:1; width:210px; max-width:70%; height:auto; margin-bottom:8px;
  filter:drop-shadow(0 6px 18px rgba(0,0,0,.4));}
.brand-desc{position:relative; z-index:1; font-size:14.5px; color:#c8d0dc; line-height:1.7; max-width:32ch; margin-top:10px}
.brand-rule{width:52px; height:3px; background:var(--gold); border-radius:2px; margin:18px auto 0}
.login-form-panel{padding:46px 42px; display:flex; flex-direction:column; justify-content:center; background:#fbf9f3}
.login-head h2{font-size:23px; font-weight:700; color:var(--ink)}
.login-head p{font-size:14px; color:var(--muted); margin-top:5px; margin-bottom:26px}
.login-field{margin-bottom:16px}
.login-field label{display:block; font-size:13.5px; font-weight:600; color:var(--muted); margin-bottom:6px}
.login-input-wrap{position:relative}
.login-field input{width:100%; padding:12px 14px; font-size:15.5px; border:1px solid var(--line-strong);
  border-radius:9px; background:#fffdf8; transition:border-color .15s ease, box-shadow .15s ease;}
.login-field input:focus{outline:none; border-color:var(--focus); box-shadow:0 0 0 3px rgba(30,95,174,.14)}
.pw-toggle{position:absolute; right:6px; top:50%; transform:translateY(-50%); background:none; border:none;
  color:var(--muted); font-size:12.5px; font-weight:600; padding:6px 10px; border-radius:6px; cursor:pointer;}
.pw-toggle:hover{background:#efe9dc; color:var(--ink)}
.login-remember{display:flex; align-items:center; gap:8px; font-size:13.5px; color:var(--muted); margin:4px 0 20px; cursor:pointer; user-select:none}
.login-remember input{width:16px; height:16px; accent-color:var(--red)}
.btn-login{width:100%; padding:13px; font-size:16px; font-weight:700; color:#fff; background:var(--ink);
  border:none; border-radius:10px; cursor:pointer; transition:background .15s ease, transform .1s ease;}
.btn-login:hover:not(:disabled){background:#2c3a4e}
.btn-login:active:not(:disabled){transform:translateY(1px)}
.btn-login:disabled{background:#9aa2af; cursor:not-allowed}
.btn-login:focus-visible{outline:2px solid var(--gold); outline-offset:2px}
.login-error{display:none; font-size:13.5px; font-weight:600; color:var(--red); background:#fbeae9;
  border:1px solid #eecfcd; border-radius:8px; padding:9px 12px; margin-bottom:16px;}
.login-error.show{display:block; animation:pop .2s ease}
.login-note{font-size:12px; color:#8a8474; margin-top:22px; line-height:1.6; border-top:1px solid var(--line); padding-top:16px}
@media (max-width:720px){
  .login-shell{grid-template-columns:1fr; max-width:440px}
  .login-brand{padding:32px 28px; border-right:none; border-bottom:3px solid var(--gold)}
  .login-logo{width:160px}
  .login-form-panel{padding:32px 28px}
}

/* ==================================================================
   USER MANAGEMENT (users.html)
   ================================================================== */
.page-title{font-size:22px; font-weight:700; margin-bottom:4px}
.page-sub{color:var(--muted); font-size:14px; margin-bottom:22px}
.panel{background:var(--card); border:1px solid var(--line); border-radius:var(--radius); box-shadow:var(--shadow); margin-bottom:22px; overflow:hidden}
.panel-head{padding:14px 20px; border-bottom:1px solid var(--line); background:linear-gradient(to bottom,#fdfcf8,#f8f6ef); font-weight:700; font-size:15px; display:flex; align-items:center; gap:8px}
.panel-head::before{content:""; width:8px; height:8px; border-radius:50%; background:var(--gold)}
.panel-body{padding:18px 20px 22px}
.user-table{width:100%; border-collapse:collapse}
.user-table th{text-align:left; font-size:12.5px; color:var(--muted); font-weight:600; padding:8px 10px; border-bottom:2px solid var(--line-strong)}
.user-table td{padding:11px 10px; border-bottom:1px solid var(--line); font-size:14.5px; vertical-align:middle}
.user-table tr:last-child td{border-bottom:none}
.role-pill{font-size:12px; font-weight:600; border-radius:999px; padding:2px 11px}
.role-admin{background:#f3e8d3; color:#7a5a17; border:1px solid #e2caa0}
.role-user{background:#e7eef7; color:#2a5487; border:1px solid #c6d7ec}
.you-tag{font-size:11.5px; color:var(--gold); font-weight:600; margin-left:6px}
.tbl-actions{display:flex; gap:6px; justify-content:flex-end}
.add-grid{display:grid; grid-template-columns:1fr 1fr; gap:14px}
@media (max-width:560px){.add-grid{grid-template-columns:1fr}}
.hint{font-size:12.5px; color:var(--muted); margin-top:4px}
.back-link{display:inline-flex; align-items:center; gap:6px; font-size:14px; font-weight:600; text-decoration:none; color:var(--focus); margin-bottom:16px}
.back-link:hover{text-decoration:underline}

/* ==================================================================
   PRINT (A4) — app.html
   ================================================================== */
#printDoc{display:none}
@media print{
  @page{
    size:A4; margin:16mm 15mm 20mm;
    @bottom-right{content:"หน้า " counter(page); font-family:'Sarabun',sans-serif; font-size:9pt; color:#555}
    @bottom-left{content:"จัดทำด้วยระบบ Timeline Builder — ยอดทิพย์ธรรม"; font-family:'Sarabun',sans-serif; font-size:8pt; color:#999}
  }
  body{background:#fff; -webkit-print-color-adjust:exact; print-color-adjust:exact}
  .app-header, .container, .overlay, .toast-wrap{display:none !important}
  #printDoc{display:table; width:100%; border-collapse:collapse}
  #printDoc thead{display:table-header-group}
  .p-running{font-size:9.5pt; color:#444; border-bottom:1.5pt solid #1c2430; padding-bottom:5pt; margin-bottom:0; display:flex; justify-content:space-between; gap:10pt}
  .p-body{padding-top:10pt}
  .p-title{text-align:center; font-size:17pt; font-weight:700; color:#1c2430; margin-bottom:2pt; letter-spacing:.01em}
  .p-subtitle{text-align:center; font-size:10.5pt; color:#666; margin-bottom:14pt}
  .p-caseinfo{border:1.2pt solid #1c2430; border-radius:4pt; padding:10pt 14pt; margin-bottom:14pt; font-size:11pt; line-height:1.7}
  .p-caseinfo .row{display:flex; gap:8pt}
  .p-caseinfo .lbl{font-weight:700; min-width:118pt; flex:none}
  .p-caseinfo .num-black{font-weight:700}
  .p-caseinfo .num-red{font-weight:700; color:#9e2b25}
  .p-filter-note{font-size:9.5pt; color:#8a6d1f; background:#fdf6e0; border:.7pt solid #e5d193; border-radius:3pt; padding:4pt 8pt; margin-bottom:10pt}
  .p-total{font-size:10.5pt; font-weight:700; color:#333; margin-bottom:8pt; border-bottom:.7pt solid #ccc; padding-bottom:3pt}
  .p-event{border-left:3pt solid #999; padding:7pt 0 7pt 12pt; margin-bottom:9pt; page-break-inside:avoid; break-inside:avoid}
  .p-ev-head{font-size:11pt; margin-bottom:1pt}
  .p-ev-no{display:inline-block; font-weight:700; color:#555; min-width:34pt}
  .p-ev-date{font-weight:700}
  .p-ev-cat{display:inline-block; font-size:8.5pt; font-weight:700; color:#fff; border-radius:3pt; padding:.5pt 6pt; margin-left:7pt; vertical-align:1pt}
  .p-ev-title{font-size:11.5pt; font-weight:600; margin:1pt 0}
  .p-ev-detail{font-size:10.5pt; color:#333; white-space:pre-line}
  .p-ev-ref{font-size:9.5pt; color:#555; margin-top:2pt}
  .p-ev-ref::before{content:"อ้างอิง: "; font-weight:700}
  .p-sign{margin-top:22pt; page-break-inside:avoid; display:flex; justify-content:flex-end}
  .p-sign-box{text-align:center; font-size:11pt; min-width:200pt}
  .p-sign-line{border-bottom:.8pt dotted #555; height:26pt; margin-bottom:4pt}
  .p-gen-date{font-size:9.5pt; color:#666; margin-top:6pt}
}
@media (prefers-reduced-motion:reduce){ *{animation:none !important; transition:none !important} }
