/* ระบบติดตาม KRs กทม. 2569 — ย้ายมาจาก apps/bmaokr69/index.php (inline style) */
  :root {
    --bg:        #f5f7fa;
    --surface:   #ffffff;
    --surface2:  #f0f2f6;
    --border:    #dde1e9;
    --text:      #1a2233;
    --muted:     #6b7585;
    --accent:    #2563eb;
    --green:     #16a34a;
    --yellow:    #ca8a04;
    --red:       #dc2626;
    --purple:    #7c3aed;
    --orange:    #ea580c;

    --d1: #3B82F6; --d2: #EF4444; --d3: #8B5CF6;
    --d4: #22C55E; --d5: #F97316; --d6: #EAB308;
    --d7: #06B6D4; --d8: #EC4899; --d9: #6366F1;
    --font: 'Sarabun', sans-serif;
    --mono: 'IBM Plex Mono', monospace;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 16px rgba(0,0,0,.1);
    --radius: 8px;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  html { scroll-behavior: smooth; }
  body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.6;
  }

  /* ── HEADER ── */
  header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    position: sticky; top: 0; z-index: 100;
    box-shadow: var(--shadow);
  }
  .logo {
    display: flex; align-items: center; gap: 10px;
    font-weight: 700; font-size: 15px; letter-spacing: .3px;
  }
  .logo-badge {
    background: linear-gradient(135deg, #2563eb, #6366f1);
    color: #fff; border-radius: 6px;
    padding: 3px 8px; font-size: 11px; font-weight: 700;
    font-family: var(--mono);
  }
  .header-actions { display: flex; gap: 8px; }

  /* ── LAYOUT ── */
  .app-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    min-height: calc(100vh - 56px);
  }
  .sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 16px 0;
    position: sticky; top: 56px;
    height: calc(100vh - 56px);
    overflow-y: auto;
  }
  .sidebar-section { padding: 6px 0 10px; }
  .sidebar-label {
    padding: 0 16px 6px;
    font-size: 11px; font-weight: 600;
    color: var(--muted); text-transform: uppercase;
    letter-spacing: .8px;
  }
  .nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 7px 16px; cursor: pointer;
    font-size: 13px; transition: all .15s; color: var(--muted);
    border-left: 3px solid transparent;
  }
  .nav-item:hover { background: var(--surface2); color: var(--text); }
  .nav-item.active {
    background: rgba(37,99,235,.07);
    color: var(--accent); border-left-color: var(--accent);
    font-weight: 500;
  }
  .nav-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
  .nav-count {
    margin-left: auto;
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 10px; padding: 1px 6px; font-size: 10px;
    font-family: var(--mono); color: var(--muted);
  }

  .main { padding: 24px; overflow-x: hidden; }

  /* ── STATS ── */
  .stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px; margin-bottom: 24px;
  }
  .stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px;
    box-shadow: var(--shadow); transition: box-shadow .2s;
  }
  .stat-card:hover { box-shadow: var(--shadow-md); }
  .stat-value {
    font-size: 28px; font-weight: 700;
    font-family: var(--mono); color: var(--accent);
    line-height: 1;
  }
  .stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

  /* ── DIMENSION GRID ── */
  .dim-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px; margin-bottom: 24px;
  }
  .dim-card {
    border-radius: 10px; padding: 16px;
    cursor: pointer; transition: transform .15s, box-shadow .15s;
    border: 1.5px solid transparent;
    background: var(--surface);
    box-shadow: var(--shadow);
  }
  .dim-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
  .dim-card.active { border-color: var(--accent); }
  .dim-icon { font-size: 22px; margin-bottom: 8px; }
  .dim-name { font-size: 13px; font-weight: 600; line-height: 1.3; }
  .dim-count { font-size: 24px; font-weight: 700; font-family: var(--mono); margin-top: 4px; }
  .dim-sub { font-size: 11px; color: var(--muted); }

  /* ── TOOLBAR ── */
  .toolbar {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 16px; flex-wrap: wrap;
  }
  .search-box {
    flex: 1; min-width: 200px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 6px; padding: 8px 12px;
    color: var(--text); font-family: var(--font); font-size: 13px;
    outline: none; transition: border-color .2s; box-shadow: var(--shadow);
  }
  .search-box:focus { border-color: var(--accent); }
  .search-box::placeholder { color: var(--muted); }
  select.filter-sel {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 6px; padding: 8px 12px;
    color: var(--text); font-family: var(--font); font-size: 13px;
    outline: none; cursor: pointer; box-shadow: var(--shadow);
  }
  .btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px; border-radius: 6px;
    font-family: var(--font); font-size: 13px; font-weight: 500;
    cursor: pointer; border: none; transition: all .15s;
  }
  .btn-primary { background: var(--accent); color: #fff; }
  .btn-primary:hover { background: #1d4ed8; }
  .btn-secondary { background: var(--surface); border: 1px solid var(--border); color: var(--text); box-shadow: var(--shadow); }
  .btn-secondary:hover { background: var(--surface2); border-color: var(--accent); color: var(--accent); }
  .btn-danger { background: #fef2f2; border: 1px solid #fca5a5; color: var(--red); }
  .btn-danger:hover { background: #fee2e2; }
  .btn-sm { padding: 5px 10px; font-size: 12px; }

  /* ── TABLE ── */
  .table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden;
    box-shadow: var(--shadow);
  }
  table { width: 100%; border-collapse: collapse; }
  thead { background: var(--surface2); }
  thead th {
    padding: 10px 14px; text-align: left;
    font-size: 11px; font-weight: 600;
    color: var(--muted); text-transform: uppercase;
    letter-spacing: .5px; white-space: nowrap;
    border-bottom: 1px solid var(--border);
  }
  tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; cursor: pointer; }
  tbody tr:last-child { border-bottom: none; }
  tbody tr:hover { background: #f0f6ff; }
  td { padding: 10px 14px; font-size: 13px; vertical-align: middle; }
  .td-code { font-family: var(--mono); font-size: 12px; color: var(--accent); white-space: nowrap; }
  .td-name { max-width: 320px; }
  .td-name .kr-title { font-weight: 500; line-height: 1.4; }
  .td-name .kr-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
  .td-target { font-family: var(--mono); font-size: 12px; white-space: nowrap; }
  .td-agency { font-size: 12px; color: var(--muted); }
  .td-actions { white-space: nowrap; }

  /* ── BADGES ── */
  .badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px; border-radius: 12px;
    font-size: 11px; font-weight: 500; white-space: nowrap;
  }
  .badge-sub { background: #eff6ff; color: var(--accent); border: 1px solid #bfdbfe; }
  .badge-on-track { background: #f0fdf4; color: var(--green); border: 1px solid #bbf7d0; }
  .badge-at-risk  { background: #fefce8; color: var(--yellow); border: 1px solid #fde68a; }
  .badge-behind   { background: #fef2f2; color: var(--red); border: 1px solid #fca5a5; }
  .badge-completed{ background: #f5f3ff; color: var(--purple); border: 1px solid #ddd6fe; }
  .badge-not-started { background: var(--surface2); color: var(--muted); border: 1px solid var(--border); }

  /* ── MODAL ── */
  .modal-overlay {
    position: fixed; inset: 0;
    background: rgba(15,23,42,.4); backdrop-filter: blur(3px);
    z-index: 200; display: flex; align-items: center; justify-content: center;
    padding: 20px;
  }
  .modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px; width: 100%; max-width: 760px;
    max-height: 90vh; overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,.18);
  }
  .modal-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  }
  .modal-header h2 { font-size: 16px; font-weight: 600; line-height: 1.4; color: var(--text); }
  .modal-close {
    background: none; border: none; color: var(--muted);
    cursor: pointer; font-size: 20px; padding: 0 4px; flex-shrink: 0;
  }
  .modal-close:hover { color: var(--text); background: var(--surface2); border-radius: 4px; }
  .modal-body { padding: 20px 24px; }
  .modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex; gap: 8px; justify-content: flex-end;
    background: var(--surface2); border-radius: 0 0 12px 12px;
  }

  /* ── DETAIL GRID ── */
  .detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
  .detail-field.full { grid-column: 1 / -1; }
  .field-label { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
  .field-value {
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 6px; padding: 8px 10px; font-size: 13px; min-height: 36px;
    word-break: break-word; line-height: 1.5; color: var(--text);
  }
  .field-value.mono { font-family: var(--mono); font-size: 12px; }

  /* ── FORM ── */
  .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .form-field.full { grid-column: 1 / -1; }
  .form-label { font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 5px; display: block; }
  .form-label .required { color: var(--red); }
  .form-input {
    width: 100%;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 6px; padding: 8px 10px;
    color: var(--text); font-family: var(--font); font-size: 13px;
    outline: none; transition: border-color .2s;
  }
  .form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
  textarea.form-input { resize: vertical; min-height: 80px; }
  select.form-input { cursor: pointer; }

  /* ── LINKS ── */
  .link-row {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 10px;
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 6px; margin-bottom: 6px;
  }
  .link-icon { font-size: 14px; }
  .link-text { flex: 1; font-size: 12px; color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .link-btn {
    background: #eff6ff; border: 1px solid #bfdbfe;
    color: var(--accent); border-radius: 5px; padding: 4px 8px;
    font-size: 11px; cursor: pointer; transition: all .15s; white-space: nowrap;
    text-decoration: none; display: inline-flex; align-items: center; gap: 4px;
  }
  .link-btn:hover { background: #dbeafe; }

  /* ── SECTION TITLE ── */
  .section-title {
    font-size: 11px; font-weight: 600;
    color: var(--muted); text-transform: uppercase;
    letter-spacing: .8px; margin-bottom: 10px;
    padding-bottom: 6px; border-bottom: 1px solid var(--border);
  }

  /* ── PROGRESS BAR ── */
  .progress-bar-wrap { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
  .progress-bar-fill { height: 100%; border-radius: 3px; transition: width .5s; }

  /* ── PAGINATION ── */
  .pagination {
    display: flex; align-items: center; gap: 6px;
    padding: 12px 14px; border-top: 1px solid var(--border);
    justify-content: space-between; background: var(--surface2);
  }
  .page-info { font-size: 12px; color: var(--muted); }
  .page-btn {
    background: var(--surface); border: 1px solid var(--border);
    color: var(--text); border-radius: 5px; padding: 5px 10px;
    font-size: 12px; cursor: pointer; transition: all .15s;
  }
  .page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
  .page-btn:hover:not(.active) { border-color: var(--accent); color: var(--accent); }

  /* ── TOAST ── */
  .toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
  .toast {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; padding: 12px 16px;
    font-size: 13px; min-width: 220px;
    box-shadow: var(--shadow-md);
    animation: slideIn .2s ease;
  }
  .toast.success { border-left: 3px solid var(--green); }
  .toast.error   { border-left: 3px solid var(--red); }
  @keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

  /* ── VIEW TOGGLE ── */
  .view-toggle { display: flex; background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
  .view-btn { padding: 6px 12px; cursor: pointer; font-size: 13px; background: none; border: none; color: var(--muted); transition: all .15s; }
  .view-btn.active { background: var(--accent); color: #fff; }

  /* ── LOADING ── */
  .loading { display: flex; align-items: center; justify-content: center; padding: 48px; color: var(--muted); gap: 12px; }
  .spinner { width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .6s linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }

  .hidden { display: none !important; }
  .page-section { animation: fadeIn .2s ease; }
  @keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

  /* ── CARD GRID ── */
  .card-item {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 10px; padding: 16px; cursor: pointer;
    transition: all .15s; box-shadow: var(--shadow);
  }
  .card-item:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
