/* ══════════════════════════════════════════
   Smart PM — Main Stylesheet
   ══════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
    font-family: 'IBM Plex Sans Thai', 'Sarabun', sans-serif;
    background: #f5f7fa;
    color: #0f172a;
    -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ─────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── Icons ─────────────────────────────── */
.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 350, 'GRAD' 0, 'opsz' 24;
    vertical-align: middle; line-height: 1; user-select: none;
}
.icon-fill { font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24; }

/* ── Layout ────────────────────────────── */
.sidebar { width: 256px; transition: width .3s ease, transform .3s ease; }
.sidebar.collapsed { width: 72px; }
.main-content { margin-left: 256px; transition: margin-left .3s ease; }
.sidebar.collapsed ~ .main-content { margin-left: 72px; }

@media (max-width: 1023px) {
    .sidebar { transform: translateX(-100%); position: fixed; z-index: 50; }
    .sidebar.mobile-open { transform: translateX(0); }
    .main-content { margin-left: 0 !important; }
}

/* ── Nav ───────────────────────────────── */
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 9px 14px; border-radius: 10px;
    color: #475569; font-weight: 500; font-size: 14px;
    cursor: pointer; transition: all .18s;
    white-space: nowrap; overflow: hidden;
    text-decoration: none; margin-bottom: 2px;
}
.nav-item:hover { background: #eef2f7; color: #0f4c81; }
.nav-item.active { background: #e8f0f9; color: #0f4c81; font-weight: 600; }
.nav-item .nav-icon { font-size: 20px; flex-shrink: 0; }
.nav-item .nav-label { transition: opacity .2s; }
.sidebar.collapsed .nav-label { opacity: 0; width: 0; overflow: hidden; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 10px; gap: 0; }
.sidebar.collapsed .nav-item .badge { display: none; }
.sidebar.collapsed .nav-item {
    position: relative;
    --tooltip-text: attr(data-label);
}
.sidebar.collapsed .nav-item::after {
    content: attr(data-label);
    position: absolute; left: calc(100% + 10px); top: 50%;
    transform: translateY(-50%);
    background: #0f172a; color: #fff;
    padding: 5px 10px; border-radius: 6px; font-size: 12px;
    white-space: nowrap; opacity: 0; pointer-events: none;
    transition: opacity .2s; z-index: 999;
}
.sidebar.collapsed .nav-item:hover::after { opacity: 1; }

/* ── Cards ─────────────────────────────── */
.card {
    background: #fff; border-radius: 10px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    transition: box-shadow .2s;
}
.card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.08); }
.card-flat { background: #fff; border-radius: 10px; border: 1px solid #e2e8f0; }

/* ── Stat Cards ────────────────────────── */
.stat-card {
    background: #fff; border-radius: 10px;
    border: 1px solid #e2e8f0; padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    transition: all .25s; position: relative; overflow: hidden;
}
.stat-card::before {
    content: ''; position: absolute; top: 0; left: 0;
    width: 4px; height: 100%; border-radius: 4px 0 0 4px;
}
.stat-card.blue::before   { background: #1a6db5; }
.stat-card.green::before  { background: #059669; }
.stat-card.amber::before  { background: #d97706; }
.stat-card.red::before    { background: #dc2626; }
.stat-card.purple::before { background: #7c3aed; }
.stat-card.teal::before   { background: #0891b2; }
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,.1); }

/* ── Badges ────────────────────────────── */
.badge {
    display: inline-flex; align-items: center;
    padding: 3px 10px; border-radius: 20px;
    font-size: 11px; font-weight: 600; letter-spacing: .04em;
    font-family: 'IBM Plex Mono', monospace; white-space: nowrap;
}
.badge-active     { background: #dbeafe; color: #1e40af; }
.badge-completed  { background: #d1fae5; color: #065f46; }
.badge-hold       { background: #fef3c7; color: #92400e; }
.badge-planning   { background: #ede9fe; color: #5b21b6; }
.badge-validating { background: #cffafe; color: #164e63; }
.badge-failed     { background: #fee2e2; color: #991b1b; }
.badge-cancelled  { background: #f1f5f9; color: #475569; }
.badge-todo       { background: #f8fafc; color: #64748b; border: 1px solid #e2e8f0; }
.badge-in_progress{ background: #dbeafe; color: #1e40af; }
.badge-review     { background: #ede9fe; color: #5b21b6; }
.badge-done       { background: #d1fae5; color: #065f46; }
.badge-blocked    { background: #fee2e2; color: #991b1b; }

/* ── Priority ──────────────────────────── */
.priority-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.priority-critical { background: #dc2626; }
.priority-high     { background: #ea580c; }
.priority-medium   { background: #ca8a04; }
.priority-low      { background: #16a34a; }

/* ── Progress Bar ──────────────────────── */
.progress-bar  { height: 6px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; transition: width 1s ease; }

/* ── Table ─────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    padding: 12px 16px; text-align: left;
    font-size: 11px; font-weight: 600; letter-spacing: .08em;
    text-transform: uppercase; color: #94a3b8;
    background: #f8fafc; border-bottom: 1px solid #e2e8f0;
    white-space: nowrap;
}
.data-table td {
    padding: 13px 16px; font-size: 14px; color: #334155;
    border-bottom: 1px solid #f1f5f9; vertical-align: middle;
}
.data-table tbody tr { transition: background .15s; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { color: #0f4c81; }

/* ── Dropdown ──────────────────────────── */
.dropdown-menu {
    position: absolute; right: 0; top: calc(100% + 6px);
    background: #fff; border: 1px solid #e2e8f0;
    border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.12);
    min-width: 180px; z-index: 200;
    opacity: 0; visibility: hidden;
    transform: translateY(-6px); transition: all .2s;
}
.dropdown.open .dropdown-menu,
.dropdown:focus-within .dropdown-menu { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-menu a, .dropdown-menu button {
    display: flex; align-items: center; width: 100%;
    padding: 9px 16px; font-size: 14px; color: #334155;
    text-align: left; background: none; border: none; cursor: pointer;
    transition: background .15s; text-decoration: none; gap: 6px;
}
.dropdown-menu a:first-child, .dropdown-menu button:first-child { border-radius: 10px 10px 0 0; }
.dropdown-menu a:last-child,  .dropdown-menu button:last-child  { border-radius: 0 0 10px 10px; }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: #f8fafc; }
.dropdown-menu .divider { height: 1px; background: #e2e8f0; margin: 4px 0; }

/* ── Tooltip ───────────────────────────── */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute; bottom: calc(100% + 6px); left: 50%;
    transform: translateX(-50%);
    background: #0f172a; color: #fff;
    padding: 4px 10px; border-radius: 6px;
    font-size: 12px; white-space: nowrap;
    opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 999;
}
[data-tooltip]:hover::after { opacity: 1; }

/* ── Forms ─────────────────────────────── */
.form-input {
    width: 100%; border: 1px solid #e2e8f0; border-radius: 8px;
    padding: 10px 14px; font-size: 14px; color: #0f172a;
    background: #fff; transition: all .2s;
    font-family: inherit; outline: none;
}
.form-input:focus { border-color: #0f4c81; box-shadow: 0 0 0 3px rgba(15,76,129,.08); }
.form-input::placeholder { color: #94a3b8; }
.form-label {
    display: block; font-size: 13px; font-weight: 600;
    color: #334155; margin-bottom: 6px;
}
.form-hint { font-size: 12px; color: #94a3b8; margin-top: 4px; }
.form-error { font-size: 12px; color: #dc2626; margin-top: 4px; }

/* ── Buttons ───────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 18px; border-radius: 8px; font-size: 14px;
    font-weight: 600; cursor: pointer; border: none;
    transition: all .2s; white-space: nowrap; font-family: inherit;
}
.btn-primary {
    background: linear-gradient(135deg,#0f4c81,#1a6db5);
    color: #fff;
}
.btn-primary:hover { opacity: .9; transform: translateY(-1px); }
.btn-primary:active { transform: scale(.97); }
.btn-secondary {
    background: #fff; color: #334155;
    border: 1px solid #e2e8f0;
}
.btn-secondary:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn-danger { background: #fee2e2; color: #dc2626; }
.btn-danger:hover { background: #fecaca; }
.btn-ghost { background: transparent; color: #475569; }
.btn-ghost:hover { background: #f1f5f9; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none !important; }

/* ── Modal ─────────────────────────────── */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.45);
    backdrop-filter: blur(3px); z-index: 500;
    display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-box {
    background: #fff; border-radius: 16px;
    box-shadow: 0 24px 64px rgba(0,0,0,.18);
    width: 100%; max-height: 90vh; overflow-y: auto;
    animation: modalIn .25s ease;
}
@keyframes modalIn {
    from { opacity: 0; transform: scale(.96) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Sidebar Overlay ───────────────────── */
.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.4); z-index: 49;
    backdrop-filter: blur(2px);
}

/* ── Skeleton ──────────────────────────── */
.skeleton {
    background: linear-gradient(90deg,#e2e8f0 25%,#f1f5f9 50%,#e2e8f0 75%);
    background-size: 200% 100%;
    animation: skeletonWave 1.4s infinite; border-radius: 6px;
}
@keyframes skeletonWave { 0%{background-position:200%} 100%{background-position:-200%} }

/* ── Animations ────────────────────────── */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}
.fade-in-up { animation: fadeInUp .35s ease forwards; }
.delay-1 { animation-delay: .05s; }
.delay-2 { animation-delay: .10s; }
.delay-3 { animation-delay: .15s; }
.delay-4 { animation-delay: .20s; }
.delay-5 { animation-delay: .25s; }

/* ── Kanban ────────────────────────────── */
.kanban-col {
    background: #f8fafc; border-radius: 12px;
    border: 1px solid #e2e8f0; padding: 12px;
    min-width: 260px; max-width: 300px;
}
.kanban-card {
    background: #fff; border-radius: 8px;
    border: 1px solid #e2e8f0; padding: 14px;
    margin-bottom: 8px; cursor: grab;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
    transition: all .2s;
}
.kanban-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.1); transform: translateY(-1px); }
.kanban-card.dragging { opacity: .5; cursor: grabbing; }
.kanban-col.drag-over { border-color: #0f4c81; background: #e8f0f9; }

/* ── Timeline / Gantt ──────────────────── */
.gantt-bar {
    height: 24px; border-radius: 6px;
    display: flex; align-items: center; padding: 0 8px;
    font-size: 11px; color: #fff; font-weight: 600;
    white-space: nowrap; overflow: hidden;
    cursor: pointer; transition: opacity .2s;
}
.gantt-bar:hover { opacity: .85; }

/* ── Empty State ───────────────────────── */
.empty-state {
    text-align: center; padding: 60px 20px;
    color: #94a3b8;
}
.empty-state .icon {
    font-size: 48px; opacity: .3; display: block;
    margin: 0 auto 16px;
}
.empty-state h3 { font-size: 16px; font-weight: 600; color: #475569; margin-bottom: 6px; }
.empty-state p  { font-size: 14px; }

/* ── Activity Feed ─────────────────────── */
.activity-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid #f1f5f9; }
.activity-item:last-child { border-bottom: none; }
.activity-icon {
    width: 32px; height: 32px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; font-size: 16px;
}

/* ── Toast ─────────────────────────────── */
#toastContainer {
    position: fixed; bottom: 24px; left: 50%;
    transform: translateX(-50%);
    display: flex; flex-direction: column; gap: 8px;
    z-index: 9999; pointer-events: none; align-items: center;
}
.toast {
    background: #0f172a; color: #fff;
    padding: 12px 20px; border-radius: 10px;
    display: flex; align-items: center; gap: 10px;
    font-size: 14px; font-weight: 500;
    box-shadow: 0 8px 30px rgba(0,0,0,.2);
    pointer-events: auto; max-width: 90vw;
    animation: toastIn .3s ease; white-space: nowrap;
}
@keyframes toastIn { from { opacity:0; transform:translateY(20px); } to { opacity:1; transform:translateY(0); } }

/* ── Tabs ──────────────────────────────── */
.tab-list { display: flex; gap: 4px; border-bottom: 2px solid #e2e8f0; margin-bottom: 20px; }
.tab-btn {
    padding: 10px 18px; font-size: 14px; font-weight: 500;
    color: #475569; border-bottom: 2px solid transparent;
    margin-bottom: -2px; cursor: pointer; transition: all .2s;
    background: none; border-top: none; border-left: none; border-right: none;
    font-family: inherit;
}
.tab-btn:hover { color: #0f4c81; }
.tab-btn.active { color: #0f4c81; border-bottom-color: #0f4c81; font-weight: 600; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Responsive tweaks ─────────────────── */
@media (max-width: 768px) {
    .data-table td, .data-table th { padding: 10px 12px; font-size: 13px; }
    .btn { padding: 8px 14px; font-size: 13px; }
}
@media (max-width: 480px) {
    .stat-card { padding: 14px; }
}
