/* ============================================================
   โครงการพระราชดำริ (v2) — Theme "Sage & Sand"
   เขียวเสจหม่น + ครีมทราย + น้ำตาลเปลือกไม้ — ธรรมชาติแบบมินิมอล สว่าง โปร่ง
   ============================================================ */
:root{
  --sage-900:#2c3a31;
  --sage-800:#34463a;
  --sage-700:#4f6b58;
  --sage-600:#5f7f69;
  --sage-500:#7a9a82;
  --sage-300:#b7c9b8;
  --sage-100:#e6eee5;
  --sage-50:#f2f6f0;
  --sand-50:#fbf9f4;
  --sand-100:#f6f2ea;
  --sand-200:#ece5d6;
  --sand-300:#ded3bd;
  --bark:#7a5c43;
  --clay:#c08a5b;
  --clay-100:#f6e8da;
  --danger:#b5523f;
  --danger-100:#f7e3dd;
  --warn:#a0702f;
  --warn-100:#f6ecd8;
  --bg:var(--sand-100);
  --card:#fffdf8;
  --border:#e7e0d1;
  --text:#2e3a33;
  --text-muted:#7b857c;
  --shadow:0 1px 2px rgba(60,55,40,.05),0 4px 16px rgba(60,55,40,.05);
  --radius:14px;
  --sidebar-w:264px;
  --font-body:'IBM Plex Sans Thai','Segoe UI',Tahoma,sans-serif;
  --font-head:'Prompt','IBM Plex Sans Thai',sans-serif;
}

*{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%}
body{font-family:var(--font-body);background:var(--bg);color:var(--text);font-size:14px;line-height:1.55}
a{text-decoration:none;color:inherit}
button{font-family:inherit;cursor:pointer}
h1,h2,h3{font-family:var(--font-head);font-weight:600}

/* ---------------- Layout ---------------- */
.app{display:flex;min-height:100vh}
.main{flex:1;margin-left:var(--sidebar-w);min-width:0}

/* ---------------- Sidebar (สว่าง) ---------------- */
.sidebar{position:fixed;left:0;top:0;bottom:0;width:var(--sidebar-w);background:var(--sand-50);border-right:1px solid var(--border);
  display:flex;flex-direction:column;padding:22px 16px;z-index:50}
.brand{display:flex;align-items:center;gap:12px;padding:4px 6px 22px;border-bottom:1px dashed var(--sand-300);margin-bottom:16px}
.brand-mark{width:46px;height:46px;flex:0 0 46px}
.brand-text b{display:block;font-family:var(--font-head);font-size:14.5px;font-weight:600;color:var(--sage-800);line-height:1.3}
.brand-text small{display:block;font-size:11px;color:var(--text-muted);margin-top:2px;line-height:1.35}
.nav-label{font-size:11px;letter-spacing:.08em;color:var(--text-muted);padding:0 10px 8px;text-transform:uppercase}
.nav{display:flex;flex-direction:column;gap:2px}
.nav a{display:flex;align-items:center;gap:12px;padding:10px 12px;border-radius:10px;color:#56625a;font-size:14px;position:relative;transition:background .15s,color .15s}
.nav a svg{width:19px;height:19px;flex:0 0 19px;color:var(--sage-500)}
.nav a:hover{background:var(--sand-200);color:var(--sage-900)}
.nav a.active{background:var(--sage-100);color:var(--sage-800);font-weight:600}
.nav a.active svg{color:var(--sage-700)}
.nav a.active:before{content:'';position:absolute;left:-16px;top:8px;bottom:8px;width:4px;border-radius:0 4px 4px 0;background:var(--sage-700)}


/* ---------------- Topbar (หัวหน้าเรียบ + ลายใบไม้จาง ๆ) ---------------- */
.topbar{position:relative;padding:26px 32px 22px;border-bottom:1px solid var(--border);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='360' height='120' viewBox='0 0 360 120'%3E%3Cg fill='none' stroke='%237a9a82' stroke-width='1.2' opacity='.35'%3E%3Cpath d='M250 110c0-40 30-70 80-80-2 50-32 78-80 80z'/%3E%3Cpath d='M250 110c20-25 45-50 80-80'/%3E%3Cpath d='M200 115c-4-30 14-56 46-66 6 34-12 58-46 66z'/%3E%3Cpath d='M200 115c10-22 26-44 46-66'/%3E%3Ccircle cx='160' cy='40' r='3'/%3E%3Ccircle cx='180' cy='22' r='2'/%3E%3C/g%3E%3C/svg%3E") right bottom/360px 120px no-repeat,
    linear-gradient(180deg,var(--sand-50),var(--sand-100))}
.topbar .tb-inner{display:flex;justify-content:space-between;align-items:center;gap:16px}
.tb-eyebrow{display:inline-flex;align-items:center;gap:6px;font-size:12.5px;color:var(--sage-600);font-weight:500}
.tb-eyebrow svg{width:15px;height:15px}
.topbar h2{font-size:25px;color:var(--sage-900);margin-top:2px;line-height:1.3}
.tb-actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap;justify-content:flex-end}
.icon-btn{width:40px;height:40px;border-radius:10px;background:#fff;border:1px solid var(--border);display:flex;align-items:center;justify-content:center;color:var(--sage-700);transition:.15s}
.icon-btn:hover{background:var(--sage-100);border-color:var(--sage-300)}

/* ---------------- Content ---------------- */
.content{padding:24px 32px 40px}

/* KPI tiles */
.kpi-row{display:grid;grid-template-columns:repeat(4,1fr);gap:16px;margin-bottom:20px}
@media(max-width:1200px){.kpi-row{grid-template-columns:repeat(2,1fr)}}
.kpi{background:var(--card);border:1px solid var(--border);border-radius:var(--radius);padding:18px;box-shadow:var(--shadow);display:flex;gap:14px;align-items:flex-start}
.kpi .k-icon{width:44px;height:44px;border-radius:12px;display:flex;align-items:center;justify-content:center;flex:0 0 44px;background:var(--sage-100);color:var(--sage-700)}
.kpi:nth-child(2) .k-icon{background:var(--clay-100);color:var(--bark)}
.kpi:nth-child(3) .k-icon{background:#e5edf0;color:#4f7686}
.kpi:nth-child(4) .k-icon{background:#efe9f2;color:#76608a}
.kpi .k-label{font-size:13px;color:var(--text-muted)}
.kpi .k-big{font-family:var(--font-head);font-size:30px;font-weight:600;color:var(--sage-900);line-height:1.15}
.kpi .k-sub{font-size:12px;color:var(--text-muted)}

/* cards / charts */
.grid-2{display:grid;grid-template-columns:1fr 1fr;gap:16px;margin-bottom:20px}
@media(max-width:1100px){.grid-2{grid-template-columns:1fr}}
.card{background:var(--card);border:1px solid var(--border);border-radius:var(--radius);padding:20px;box-shadow:var(--shadow)}
.card h3{font-size:16px;margin-bottom:16px;color:var(--sage-800);display:flex;align-items:center;gap:8px}
.card h3 svg{width:18px;height:18px;color:var(--sage-600)}
.chart-wrap{position:relative;height:240px}
.donut-wrap{display:flex;align-items:center;justify-content:center;min-height:250px}
.donut-box{position:relative;width:250px;height:250px}
.donut-center{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;pointer-events:none}
.donut-center b{font-family:var(--font-head);font-size:34px;color:var(--sage-900);line-height:1}
.donut-center span{font-size:12px;color:var(--text-muted)}

.cat-list{display:flex;flex-direction:column;gap:12px}
.cat-row{display:flex;align-items:center;gap:12px}
.cat-code{min-width:52px;height:26px;padding:0 8px;border-radius:7px;color:#fff;font-size:12px;font-weight:600;display:flex;align-items:center;justify-content:center;white-space:nowrap}
.cat-body{flex:1;min-width:0}
.cat-top{display:flex;justify-content:space-between;gap:8px;font-size:13px;margin-bottom:5px}
.cat-top span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.cat-top b{color:var(--sage-900)}
.cat-pct{width:46px;text-align:right;font-size:12px;color:var(--text-muted)}
.bar{height:7px;border-radius:7px;background:var(--sand-200);overflow:hidden}
.bar>i{display:block;height:100%;border-radius:7px}

/* Table */
.table-card{background:var(--card);border:1px solid var(--border);border-radius:var(--radius);box-shadow:var(--shadow);overflow:hidden}
.table-head{display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap;padding:16px 20px}
.table-head h3{font-size:16px;color:var(--sage-800)}
.table-scroll{overflow-x:auto}
.btn-ghost{border:1px solid var(--border);background:#fff;border-radius:10px;padding:8px 14px;font-size:13px;display:inline-flex;align-items:center;gap:6px;color:var(--text);transition:.15s}
.btn-ghost svg{width:17px;height:17px;color:var(--sage-600)}
.btn-ghost:hover{border-color:var(--sage-300);background:var(--sage-50)}
.btn-accent{background:var(--sage-700);border-color:var(--sage-700);color:#fff}
.btn-accent svg{color:#fff}
.btn-accent:hover{background:var(--sage-800);border-color:var(--sage-800)}
table{width:100%;border-collapse:collapse;font-size:13.5px}
thead th{background:var(--sand-100);color:#5d665f;text-align:left;padding:11px 16px;font-weight:600;font-size:12.5px;white-space:nowrap;border-top:1px solid var(--border);border-bottom:1px solid var(--border)}
tbody td{padding:13px 16px;border-bottom:1px solid #f0eadf;vertical-align:middle}
tbody tr:last-child td{border-bottom:none}
tbody tr:hover{background:var(--sage-50)}
.link{color:var(--sage-900)}
.link:hover{color:var(--sage-700);text-decoration:underline;text-underline-offset:3px}
.rc-pill{padding:3px 10px;border-radius:20px;font-size:12px;font-weight:600;white-space:nowrap}
.act{display:inline-flex;color:var(--sage-600)}
.act svg{width:19px;height:19px}
.row-actions{display:flex;gap:6px;justify-content:flex-end}
.badge-status{padding:4px 12px;border-radius:20px;font-size:12px;font-weight:600;white-space:nowrap}
.st-done{background:var(--sage-100);color:var(--sage-700)}
.st-doing{background:var(--warn-100);color:var(--warn)}
.st-wait{background:var(--danger-100);color:var(--danger)}
.empty{padding:36px;text-align:center;color:var(--text-muted)}

.alert{background:var(--danger-100);color:var(--danger);border-radius:10px;padding:10px 14px;font-size:13px;margin-bottom:14px;text-align:center}
.alert-ok{background:var(--sage-100);color:var(--sage-700)}

/* ---------------- Forms ---------------- */
.form-card{background:var(--card);border:1px solid var(--border);border-radius:var(--radius);padding:24px;box-shadow:var(--shadow)}
.form-grid{display:grid;grid-template-columns:1fr 1fr;gap:16px 22px}
.form-group{display:flex;flex-direction:column;gap:6px}
.form-group.full{grid-column:1 / -1}
.form-group label{font-size:13px;font-weight:600;color:var(--sage-800)}
.form-group input,.form-group select,.form-group textarea{padding:10px 12px;border:1px solid var(--border);border-radius:10px;font-size:14px;font-family:inherit;background:var(--sand-50);color:var(--text)}
.form-group input:focus,.form-group select:focus{outline:none;border-color:var(--sage-500);background:#fff;box-shadow:0 0 0 3px var(--sage-100)}
.form-actions{display:flex;justify-content:flex-end;gap:10px;margin-top:22px}
.btn-save{background:var(--sage-700);color:#fff;border:none;border-radius:10px;padding:10px 20px;font-weight:600;font-size:14px}
.btn-save:hover{background:var(--sage-800)}
.btn-icon{display:inline-flex;align-items:center;gap:6px}
.btn-icon svg{width:17px;height:17px}

.cols-3{display:grid;grid-template-columns:repeat(3,1fr);gap:16px}
@media(max-width:1200px){.cols-3{grid-template-columns:1fr}}
.col-card{background:var(--card);border:1px solid var(--border);border-radius:var(--radius);box-shadow:var(--shadow);padding:16px}
.col-head{display:flex;align-items:center;gap:8px;font-family:var(--font-head);font-size:14.5px;font-weight:600;color:var(--sage-800);margin-bottom:12px;flex-wrap:wrap}
.col-num{width:26px;height:26px;border-radius:8px;background:var(--clay-100);color:var(--bark);display:flex;align-items:center;justify-content:center;font-size:13px;flex:0 0 26px}
.btn-add-mini{margin-left:auto;border:1px solid var(--sage-300);background:var(--sage-50);color:var(--sage-700);border-radius:8px;padding:4px 10px;font-size:12px;font-weight:600;font-family:var(--font-body)}
.btn-add-mini:hover{background:var(--sage-700);border-color:var(--sage-700);color:#fff}
.btn-add-block{width:100%;border:1.5px dashed var(--sand-300);background:var(--sand-50);color:var(--sage-700);border-radius:10px;padding:11px;font-weight:600;font-size:13px;margin-top:10px}
.btn-add-block:hover{border-color:var(--sage-500);background:var(--sage-50)}

.rep-list{display:flex;flex-direction:column;gap:12px}
.rep-item{border:1px solid var(--border);border-radius:12px;padding:12px;background:var(--sand-50)}
.rep-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:8px}
.rep-title{font-size:13px;font-weight:600;color:var(--text)}
.rep-del{border:none;background:var(--danger-100);color:var(--danger);width:24px;height:24px;border-radius:7px;font-size:12px;line-height:1}
.rep-del:hover{background:var(--danger);color:#fff}
.rep-label{display:block;font-size:12px;font-weight:600;color:var(--sage-800);margin:8px 0 4px}
.rep-item input,.rep-item select{width:100%;padding:8px 10px;border:1px solid var(--border);border-radius:8px;font-size:13px;font-family:inherit;background:#fff;color:var(--text)}
.rep-item input:focus,.rep-item select:focus{outline:none;border-color:var(--sage-500)}
.two{display:grid;grid-template-columns:1fr 1fr;gap:10px}
.fg label{display:block;font-size:12px;font-weight:600;color:var(--sage-800);margin:6px 0 4px}
.area-map{height:170px;border-radius:9px;border:1px solid var(--border);overflow:hidden;margin-top:4px}

/* rich text */
.rt{border:1px solid var(--border);border-radius:9px;overflow:hidden;background:#fff}
.rt-toolbar{display:flex;align-items:center;gap:2px;padding:5px 6px;background:var(--sand-100);border-bottom:1px solid var(--border)}
.rt-toolbar button{width:28px;height:26px;border:none;background:none;border-radius:5px;font-size:13px;color:var(--text)}
.rt-toolbar button:hover{background:var(--sand-200)}
.rt-sep{width:1px;height:16px;background:var(--border);margin:0 3px}
.rt-editor{min-height:90px;padding:10px 12px;font-size:13px;line-height:1.65;outline:none}
.rt-editor:empty:before{content:attr(data-ph);color:#aab0a6}
.rt-editor ul,.rt-editor ol{margin-left:20px}

/* ---------------- Detail ---------------- */
.detail-head{display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:14px}
.roy{display:flex;align-items:center;gap:12px}
.roy .rc{min-width:26px;height:26px;border-radius:8px;display:flex;align-items:center;justify-content:center;color:#fff;font-size:11px;font-weight:600;padding:0 6px}
.roy .rc-lg{min-width:48px;height:48px;border-radius:12px;font-size:13px}
.roy small{display:block;color:var(--text-muted);font-size:12px;margin-top:2px}
.dh-name{font-family:var(--font-head);font-size:17px;font-weight:600;color:var(--sage-900);line-height:1.4}
.d-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:14px 22px}
@media(max-width:900px){.d-grid{grid-template-columns:1fr 1fr}}
.d-item{display:flex;flex-direction:column;gap:2px;padding-left:10px;border-left:2px solid var(--sand-200)}
.d-label{font-size:11.5px;color:var(--text-muted)}
.d-val{font-size:14px;font-weight:600;color:var(--text)}
.col-card .d-grid{grid-template-columns:1fr 1fr}
.d-block{border:1px solid var(--border);border-radius:10px;padding:12px;margin-bottom:10px;background:var(--sand-50)}
.d-block-h{font-size:13px;font-weight:600;color:var(--sage-700);margin-bottom:8px}
.rt-view{font-size:13.5px;line-height:1.75}
.rt-view ul,.rt-view ol{margin-left:20px}
.map-mini{height:220px;border-radius:10px;margin-bottom:12px;border:1px solid var(--border)}

/* gallery / upload */
.img-up{margin-top:4px}
.btn-browse{border:1px dashed var(--sage-300);background:#fff;color:var(--sage-700);border-radius:9px;padding:10px 14px;font-size:13px;font-weight:600;width:100%}
.btn-browse:hover{background:var(--sage-50);border-color:var(--sage-500)}
.img-preview{display:flex;flex-wrap:wrap;gap:8px;margin-top:8px}
.img-thumb{position:relative;width:72px;height:72px;border-radius:8px;overflow:hidden;border:1px solid var(--border)}
.img-thumb img{width:100%;height:100%;object-fit:cover;display:block}
.img-x{position:absolute;top:2px;right:2px;width:20px;height:20px;border:none;border-radius:50%;background:rgba(181,82,63,.92);color:#fff;font-size:13px;line-height:1;display:flex;align-items:center;justify-content:center}
.gallery{display:grid;grid-template-columns:repeat(auto-fill,minmax(240px,1fr));gap:12px;margin-top:6px}
.gallery img{width:100%;height:190px;object-fit:cover;border-radius:10px;border:1px solid var(--border);cursor:zoom-in;transition:transform .15s}
.gallery img:hover{transform:scale(1.02)}
.lightbox{display:none;position:fixed;inset:0;background:rgba(30,36,32,.9);z-index:9999;align-items:center;justify-content:center;padding:24px;cursor:zoom-out}
.lightbox img{max-width:95%;max-height:95%;border-radius:8px}

/* ---------------- PIN / edit ---------------- */
.pin-card{max-width:380px;margin:40px auto;background:var(--card);border:1px solid var(--border);border-radius:16px;box-shadow:var(--shadow);padding:32px;text-align:center}
.pin-ic{width:56px;height:56px;border-radius:50%;background:var(--sage-100);color:var(--sage-700);display:flex;align-items:center;justify-content:center;margin:0 auto 14px}
.pin-card h3{color:var(--sage-900);margin-bottom:6px}
.pin-card p{color:var(--text-muted);font-size:13px;margin-bottom:16px}
.pin-card input{width:100%;padding:12px 14px;border:1px solid var(--border);border-radius:10px;font-size:20px;text-align:center;letter-spacing:8px;font-family:inherit;background:var(--sand-50)}
.pin-card input:focus{outline:none;border-color:var(--sage-500);box-shadow:0 0 0 3px var(--sage-100)}
.pin-back{display:block;margin-top:14px;color:var(--text-muted);font-size:13px}
.btn-mini{display:inline-flex;align-items:center;gap:4px;border:none;border-radius:8px;padding:6px 11px;font-size:12px;font-weight:600;font-family:inherit}
.btn-mini svg{width:15px;height:15px}
.btn-mini-edit{background:var(--sage-100);color:var(--sage-700)}
.btn-mini-edit:hover{background:var(--sage-700);color:#fff}
.btn-mini-del{background:var(--danger-100);color:var(--danger)}
.btn-mini-del:hover{background:var(--danger);color:#fff}
.unlock-chip{display:inline-flex;align-items:center;gap:6px;background:var(--sage-100);color:var(--sage-700);border-radius:10px;padding:8px 12px;font-size:12.5px;font-weight:600}
.unlock-chip svg{width:15px;height:15px}

/* ---------------- Filters ---------------- */
.proj-filter{display:flex;align-items:center;gap:10px;flex-wrap:wrap;padding:12px 20px;border-top:1px solid var(--border);background:var(--sand-50)}
.map-filter{border:1px solid var(--border);border-radius:10px;margin-bottom:10px}
.flabel{font-size:13px;color:var(--text-muted);font-weight:600}
.fchips{display:flex;gap:6px;flex-wrap:wrap}
.fchip{border:1px solid var(--border);background:#fff;border-radius:20px;padding:4px 12px;font-size:12px;color:var(--text)}
.fchip:hover{border-color:var(--sage-300)}
.fchip.on{background:var(--sage-700);color:#fff;border-color:var(--sage-700)}
.fdrop{position:relative}
.fdrop-btn{border:1px solid var(--border);background:#fff;border-radius:10px;padding:5px 12px;font-size:13px}
.fdrop-panel{position:absolute;top:calc(100% + 4px);left:0;z-index:60;background:#fff;border:1px solid var(--border);border-radius:10px;box-shadow:var(--shadow);width:280px;padding:8px}
.fdrop-search{width:100%;padding:7px 10px;border:1px solid var(--border);border-radius:8px;font-size:13px;margin-bottom:6px;font-family:inherit}
.fdrop-list{max-height:230px;overflow:auto}
.fdrop-item{display:flex;align-items:center;gap:6px;padding:5px 6px;font-size:13px;border-radius:6px;cursor:pointer}
.fdrop-item:hover{background:var(--sage-50)}
.fclear{margin-left:auto;border:1px solid var(--border);background:#fff;border-radius:8px;padding:5px 12px;font-size:13px;color:var(--danger)}
.fclear:hover{background:var(--danger-100)}
.map-select{border:1px solid var(--border);background:#fff;border-radius:10px;padding:7px 12px;font-size:14px;font-family:inherit;color:var(--text);min-width:240px}
.map-select:focus{outline:none;border-color:var(--sage-500)}
.map-note{font-size:12px;color:var(--text-muted);margin-bottom:8px}
.map-full{height:calc(100vh - 330px);min-height:420px;border-radius:10px;border:1px solid var(--border)}
.nf-num{font-size:52px;color:var(--sage-600)}

/* ---------------- Responsive: sidebar เป็นแถบด้านบนบนจอเล็ก ---------------- */
@media(max-width:900px){
  .sidebar{position:static;width:auto;height:auto;flex-direction:row;flex-wrap:wrap;align-items:center;padding:10px 14px;gap:8px;border-right:none;border-bottom:1px solid var(--border)}
  .app{flex-direction:column}
  .main{margin-left:0}
  .brand{border:none;margin:0;padding:0}
  .brand-text small,.nav-label{display:none}
  .nav{flex-direction:row;flex-wrap:wrap;width:100%}
  .nav a{padding:7px 10px;font-size:13px}
  .nav a.active:before{display:none}
  .sidebar{position:relative}
  .topbar,.content{padding-left:16px;padding-right:16px}
  .topbar h2{font-size:21px}
  .form-grid,.two{grid-template-columns:1fr}
  .kpi-row{grid-template-columns:1fr 1fr}
  .table-scroll table{min-width:760px}
  .kpi{flex-direction:column;gap:8px}
}

/* ---------------- Print / PDF ---------------- */
@media print{
  .no-print,.sidebar{display:none!important}
  .main{margin-left:0!important}
  body{background:#fff}
  .topbar{background:#fff!important;border:none}
  .card,.table-card,.form-card,.col-card,.kpi{box-shadow:none;border:1px solid #ccc;break-inside:avoid}
}
