/* ==========================================================================
   TaskFlow — ธีมหลัก
   ทุกคลาสขึ้นต้นด้วย tf- เสมอ ห้ามใช้คำกลางๆ อย่าง .overlay .panel .box
   เพราะเคยเกิดกรณีชื่อชนกันแล้วทั้งชั้นถูกซ่อนโดยไม่มี error
   ========================================================================== */

/* [hidden] เป็นกฎของเบราว์เซอร์ซึ่งแพ้กฎของเราเสมอ
   ถ้าไม่ประกาศทับ แถวที่ hidden จะยังกินพื้นที่เมื่อเราตั้ง display:grid/flex เอง */
[hidden] { display: none !important; }

:root{
	--ink:#1C2430;      --ink-soft:#5B6472;   --line:#E4E7EC;
	--surface:#FFFFFF;  --canvas:#F4F6F8;     --sidebar:#161D27;
	--accent:#0E7C7B;   --done:#3FA796;       --progress:#2E7DD1;
	--overdue:#D6534A;  --planned:#C7CDD6;    --amber:#E3A008;
	--radius:8px;
	--shadow:0 1px 2px rgba(28,36,48,.06), 0 4px 12px rgba(28,36,48,.05);
	--sidebar-w:232px;
}

*,*::before,*::after{ box-sizing:border-box; }

html,body{ margin:0; padding:0; }

body{
	background:var(--canvas);
	color:var(--ink);
	font-family:'Noto Sans Thai',-apple-system,'Segoe UI',sans-serif;
	font-size:14px;
	line-height:1.6;
	-webkit-font-smoothing:antialiased;
}

h1,h2,h3,h4,h5{ font-family:'Prompt',sans-serif; font-weight:600; margin:0; color:var(--ink); }
h1{ font-size:20px; } h2{ font-size:17px; } h3{ font-size:15px; }

a{ color:var(--accent); text-decoration:none; }
a:hover{ text-decoration:underline; }

.tf-num{ font-family:'IBM Plex Mono',monospace; font-variant-numeric:tabular-nums; }

/* ---------- โครงหน้า ---------- */

.tf-shell{ display:grid; grid-template-columns:var(--sidebar-w) 1fr; min-height:100vh; }
.tf-shell.is-collapsed{ grid-template-columns:64px 1fr; }

.tf-side{
	background:var(--sidebar); color:#AEB6C2;
	display:flex; flex-direction:column;
	position:sticky; top:0; height:100vh; overflow-y:auto;
}

.tf-side-brand{
	display:flex; align-items:center; gap:10px;
	padding:18px 18px 14px; color:#fff;
	font-family:'Prompt',sans-serif; font-weight:600; font-size:16px;
	border-bottom:1px solid rgba(255,255,255,.07);
	white-space:nowrap; overflow:hidden;
}
.tf-side-brand svg{ flex:0 0 auto; color:var(--done); }

.tf-side-nav{ padding:10px 8px; display:flex; flex-direction:column; gap:2px; flex:1; }

.tf-side-link{
	display:flex; align-items:center; gap:11px;
	padding:9px 11px; border-radius:6px;
	color:#AEB6C2; font-size:13.5px; white-space:nowrap; overflow:hidden;
	transition:background .12s,color .12s;
}
.tf-side-link:hover{ background:rgba(255,255,255,.06); color:#fff; text-decoration:none; }
.tf-side-link.is-active{ background:var(--accent); color:#fff; font-weight:500; }
.tf-side-link svg{ flex:0 0 auto; width:17px; height:17px; }

.tf-shell.is-collapsed .tf-side-link span,
.tf-shell.is-collapsed .tf-side-brand span,
.tf-shell.is-collapsed .tf-side-foot-name{ display:none; }

.tf-side-foot{
	padding:12px; border-top:1px solid rgba(255,255,255,.07);
	display:flex; align-items:center; gap:10px; font-size:12.5px;
}

.tf-main{ display:flex; flex-direction:column; min-width:0; }

.tf-top{
	background:var(--surface); border-bottom:1px solid var(--line);
	padding:0 22px; height:56px;
	display:flex; align-items:center; gap:14px;
	position:sticky; top:0; z-index:20;
}

.tf-top-title{ font-family:'Prompt',sans-serif; font-weight:600; font-size:16px; }

.tf-content{ padding:22px; flex:1; min-width:0; }

/* ---------- การ์ด ---------- */

.tf-card{
	background:var(--surface); border:1px solid var(--line);
	border-radius:var(--radius); box-shadow:var(--shadow);
	padding:18px; margin-bottom:16px;
}
.tf-card-head{
	display:flex; align-items:center; justify-content:space-between;
	gap:12px; margin-bottom:14px;
}

/* ---------- ปุ่ม ---------- */

.tf-btn{
	display:inline-flex; align-items:center; justify-content:center; gap:7px;
	padding:8px 15px; border-radius:6px; border:1px solid var(--line);
	background:var(--surface); color:var(--ink);
	font-family:'Noto Sans Thai',sans-serif; font-size:13.5px; font-weight:500;
	cursor:pointer; transition:background .12s,border-color .12s,opacity .12s;
}
.tf-btn:hover{ background:#F7F9FA; text-decoration:none; }
.tf-btn svg{ width:16px; height:16px; }

.tf-btn-primary{ background:var(--accent); border-color:var(--accent); color:#fff; }
.tf-btn-primary:hover{ background:#0B6968; }
.tf-btn-danger{ background:var(--overdue); border-color:var(--overdue); color:#fff; }
.tf-btn-danger:hover{ background:#BF453D; }
.tf-btn-sm{ padding:5px 10px; font-size:12.5px; }

.tf-btn:disabled,.tf-btn[disabled]{ opacity:.6; cursor:not-allowed; }

/* สปินเนอร์ในปุ่มตอนรอ server — ใส่โดย tf.js ไม่ต้องเขียนเองในแต่ละหน้า */
.tf-spin{
	width:14px; height:14px; border-radius:50%;
	border:2px solid rgba(255,255,255,.45); border-top-color:#fff;
	animation:tf-spin .6s linear infinite;
}
.tf-btn:not(.tf-btn-primary):not(.tf-btn-danger) .tf-spin{
	border-color:rgba(28,36,48,.25); border-top-color:var(--ink);
}
@keyframes tf-spin{ to{ transform:rotate(360deg); } }

/* ---------- ฟอร์ม ---------- */

.tf-field{ margin-bottom:14px; }
.tf-label{ display:block; font-size:13px; font-weight:500; margin-bottom:5px; color:var(--ink); }
.tf-label .tf-req{ color:var(--overdue); }

.tf-input,.tf-select,.tf-textarea{
	width:100%; padding:8px 11px;
	border:1px solid var(--line); border-radius:6px;
	background:var(--surface); color:var(--ink);
	font-family:'Noto Sans Thai',sans-serif; font-size:13.5px;
}
.tf-input:focus,.tf-select:focus,.tf-textarea:focus{
	outline:none; border-color:var(--accent); box-shadow:0 0 0 3px rgba(14,124,123,.12);
}
.tf-textarea{ min-height:96px; resize:vertical; }
.tf-hint{ font-size:12px; color:var(--ink-soft); margin-top:4px; }

.tf-row{ display:grid; grid-template-columns:repeat(auto-fit,minmax(180px,1fr)); gap:14px; }

/* ---------- ตาราง ---------- */

.tf-table-wrap{ overflow-x:auto; }
.tf-table{ width:100%; border-collapse:collapse; font-size:13.5px; }
.tf-table th{
	text-align:left; font-weight:600; font-size:12.5px; color:var(--ink-soft);
	padding:9px 12px; border-bottom:1px solid var(--line); white-space:nowrap;
	font-family:'Prompt',sans-serif;
}
.tf-table td{ padding:11px 12px; border-bottom:1px solid var(--line); vertical-align:middle; }
.tf-table tbody tr:hover{ background:#FAFBFC; }
.tf-table .tf-td-num{ font-family:'IBM Plex Mono',monospace; white-space:nowrap; }

.tf-empty{ text-align:center; padding:40px 20px; color:var(--ink-soft); }
.tf-empty svg{ width:34px; height:34px; margin-bottom:10px; color:var(--planned); }

/* ---------- ป้ายสถานะ ---------- */

.tf-badge{
	display:inline-flex; align-items:center; gap:5px;
	padding:2px 9px; border-radius:20px;
	font-size:12px; font-weight:500; white-space:nowrap;
}
.tf-badge::before{ content:''; width:6px; height:6px; border-radius:50%; background:currentColor; }

.tf-badge-pending{      background:#F1F3F5; color:#5B6472; }
.tf-badge-acknowledged{ background:#E7F0FB; color:#2E7DD1; }
.tf-badge-postpone{     background:#FDF3DC; color:#9A6B00; }
.tf-badge-done{         background:#E3F4F0; color:#2C7A6C; }
.tf-badge-cancelled{    background:#F1F3F5; color:#98A0AB; }
.tf-badge-overdue{      background:#FCEBE9; color:#C1443B; }

.tf-size{
	display:inline-block; padding:1px 7px; border-radius:4px;
	font-size:11.5px; font-weight:500; border:1px solid var(--line); color:var(--ink-soft);
}

/* ---------- avatar ---------- */

.tf-avatar{
	width:28px; height:28px; border-radius:50%;
	display:inline-flex; align-items:center; justify-content:center;
	color:#fff; font-size:11.5px; font-weight:600;
	font-family:'Prompt',sans-serif; flex:0 0 auto;
}
.tf-person{ display:inline-flex; align-items:center; gap:8px; }

/* ---------- แจ้งเตือน ---------- */

.tf-alert{
	padding:11px 14px; border-radius:6px; margin-bottom:14px;
	font-size:13.5px; border:1px solid transparent;
}
.tf-alert-success{ background:#E3F4F0; border-color:#B9E3D9; color:#1F6155; }
.tf-alert-error{   background:#FCEBE9; border-color:#F3C9C5; color:#A5352C; }
.tf-alert-warning{ background:#FDF3DC; border-color:#F0DCA8; color:#7A5400; }
.tf-alert-info{    background:#E7F0FB; border-color:#C4DAF3; color:#255F9E; }

/* ---------- ตัวเลขสรุป ---------- */

.tf-stat-grid{ display:grid; grid-template-columns:repeat(auto-fit,minmax(160px,1fr)); gap:14px; margin-bottom:16px; }
.tf-stat{
	background:var(--surface); border:1px solid var(--line); border-radius:var(--radius);
	padding:15px 17px; box-shadow:var(--shadow);
}
.tf-stat-label{ font-size:12.5px; color:var(--ink-soft); margin-bottom:6px; }
.tf-stat-value{ font-family:'Prompt',sans-serif; font-size:26px; font-weight:600; line-height:1.15; }
.tf-stat-sub{ font-size:12px; color:var(--ink-soft); margin-top:3px; }
.tf-stat.is-danger .tf-stat-value{ color:var(--overdue); }
.tf-stat.is-good .tf-stat-value{ color:var(--done); }
.tf-stat.is-warn .tf-stat-value{ color:var(--amber); }

/* ---------- overlay ระหว่างรอ ----------
   ชื่อเจาะจงว่า tf-loading-layer ไม่ใช่ .overlay ลอยๆ (ดู CLAUDE.md ข้อ 15) */

.tf-loading-layer{
	position:fixed; inset:0; z-index:9000;
	background:rgba(244,246,248,.75); backdrop-filter:blur(1.5px);
	display:flex; align-items:center; justify-content:center; gap:12px;
	font-family:'Prompt',sans-serif; color:var(--ink);
}
.tf-loading-layer .tf-spin{
	width:22px; height:22px;
	border-color:rgba(28,36,48,.2); border-top-color:var(--accent);
}

/* ---------- หน้า login ---------- */

.tf-login-wrap{
	min-height:100vh; display:flex; align-items:center; justify-content:center;
	padding:20px; background:var(--sidebar);
}
.tf-login-box{
	background:var(--surface); border-radius:12px; padding:32px;
	width:100%; max-width:380px; box-shadow:0 12px 40px rgba(0,0,0,.28);
}
.tf-login-brand{
	display:flex; align-items:center; gap:10px; justify-content:center;
	font-family:'Prompt',sans-serif; font-weight:600; font-size:20px; margin-bottom:6px;
}
.tf-login-brand svg{ color:var(--accent); }
.tf-login-sub{ text-align:center; color:var(--ink-soft); font-size:13px; margin-bottom:22px; }

/* ---------- ตอบสนองจอเล็ก ---------- */

@media (max-width:820px){
	.tf-shell{ grid-template-columns:1fr; }
	.tf-side{ position:static; height:auto; flex-direction:row; overflow-x:auto; }
	.tf-side-nav{ flex-direction:row; }
	.tf-side-brand{ border-bottom:none; }
	.tf-side-foot{ display:none; }
	.tf-content{ padding:16px; }
}
