@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
  --primary: #2d6a4f;
  --primary-light: #40916c;
  --primary-dark: #1b4332;
  --accent: #52b788;
  --accent-light: #74c69d;
  --bg: #f0f4f0;
  --sidebar-w: 240px;
  --sidebar-collapsed: 60px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Sarabun', sans-serif; background: var(--bg); display: flex; min-height: 100vh; color: #2d3436; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w); background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: #fff; position: fixed; top: 0; left: 0; height: 100vh; z-index: 100;
  transition: width 0.3s; overflow: hidden; display: flex; flex-direction: column;
}
.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .sidebar-header span,
.sidebar.collapsed .sidebar-menu li span,
.sidebar.collapsed .sidebar-footer { display: none; }

.sidebar-header {
  padding: 20px 16px; font-size: 1.4rem; font-weight: 700;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}
.sidebar-header i { font-size: 1.6rem; color: var(--accent-light); }
.sidebar-brand { font-size: 1.2rem; font-weight: 700; line-height: 1.1; }
.sidebar-sub { font-size: .7rem; color: rgba(255,255,255,.5); font-weight: 400; }

.sidebar-menu { list-style: none; padding: 12px 0; flex: 1; }
.sidebar-menu li {
  padding: 12px 20px; cursor: pointer; display: flex; align-items: center; gap: 12px;
  transition: all 0.2s; font-size: 0.95rem; border-left: 3px solid transparent;
}
.sidebar-menu li:hover { background: rgba(255,255,255,0.1); }
.sidebar-menu li.active { background: rgba(255,255,255,0.15); border-left-color: var(--accent-light); font-weight: 600; }
.sidebar-menu li i { width: 20px; text-align: center; font-size: 1rem; }

.sidebar-links { padding: 8px 12px; border-top: 1px solid rgba(255,255,255,0.1); }
.sidebar-link-label { font-size: .65rem; color: rgba(255,255,255,.4); text-transform: uppercase; padding: 4px 8px; letter-spacing: 1px; }
.sidebar-link { display: flex; align-items: center; gap: 10px; padding: 8px 14px; color: rgba(255,255,255,.7); text-decoration: none; border-radius: 8px; font-size: .85rem; transition: all .2s; }
.sidebar-link:hover { background: rgba(255,255,255,.12); color: #fff; }
.sidebar-link i { width: 18px; text-align: center; }
.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,0.15); }

/* Main Content */
.main-content { margin-left: var(--sidebar-w); flex: 1; transition: margin-left 0.3s; padding: 0; }
.sidebar.collapsed ~ .main-content { margin-left: var(--sidebar-collapsed); }

.top-bar {
  background: #fff; padding: 12px 24px; display: flex; align-items: center;
  gap: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); position: sticky; top: 0; z-index: 50;
}
.top-bar .btn-link { color: var(--primary); font-size: 1.2rem; text-decoration: none; }

.page { display: none; padding: 24px; }
.page.active { display: block; }

/* Cards */
.stat-card {
  background: #fff; border-radius: 12px; padding: 20px; display: flex;
  align-items: center; gap: 16px; box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 4px 20px rgba(0,0,0,0.1); }
.stat-icon {
  width: 52px; height: 52px; border-radius: 12px; display: flex;
  align-items: center; justify-content: center; font-size: 1.3rem;
}
.stat-value { font-size: 1.8rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 0.8rem; color: #636e72; margin-top: 2px; }

.card { border: none; border-radius: 12px; }
.card-title { font-weight: 600; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }

/* Table */
.table th { font-weight: 600; font-size: 0.8rem; text-transform: uppercase; color: #636e72; border-bottom: 2px solid #dee2e6; }
.table td { vertical-align: middle; font-size: 0.9rem; }

/* Status badges */
.badge-status { padding: 4px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 500; }
.badge-pending { background: #ffeaa7; color: #6c5ce7; }
.badge-completed { background: #d4edda; color: #155724; }
.badge-in_progress { background: #cce5ff; color: #004085; }
.badge-overdue { background: #f8d7da; color: #721c24; }

/* Progress bar */
.progress-thin { height: 6px; border-radius: 3px; background: #e9ecef; }
.progress-thin .progress-bar { border-radius: 3px; }

/* Category cards */
.cat-card {
  background: #fff; border-radius: 12px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  border-left: 4px solid var(--accent);
}
.cat-card h6 { font-weight: 600; margin-bottom: 4px; }
.cat-card .freq { font-size: 0.8rem; color: #636e72; }

/* Zone cards */
.zone-card {
  background: #fff; border-radius: 10px; padding: 12px 16px; box-shadow: 0 1px 6px rgba(0,0,0,0.05);
  text-align: center; transition: transform 0.2s;
}
.zone-card:hover { transform: scale(1.05); }
.zone-code { font-size: 1.2rem; font-weight: 700; color: var(--primary); }
.zone-group { font-size: 0.75rem; color: #636e72; }

/* ===== Frequency Page Styles ===== */
.freq-page-header {
  background: #fff; border-radius: 14px; padding: 18px 24px; margin-bottom: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05); display: flex; align-items: center; gap: 16px;
}
.freq-badge {
  padding: 8px 18px; border-radius: 10px; font-weight: 700; font-size: 1.1rem;
  display: flex; align-items: center; gap: 8px; color: #fff; white-space: nowrap;
}
.freq-badge.daily { background: linear-gradient(135deg, #f4a261, #e76f51); }
.freq-badge.weekly { background: linear-gradient(135deg, #118ab2, #073b4c); }
.freq-badge.monthly { background: linear-gradient(135deg, #2d6a4f, #52b788); }
.freq-badge.quarterly { background: linear-gradient(135deg, #7b2cbf, #c77dff); }

/* Frequency Summary Cards */
.freq-summary-card {
  background: #fff; border-radius: 14px; padding: 18px; box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  border-left: 5px solid; cursor: pointer; transition: all 0.2s;
}
.freq-summary-card:hover { transform: translateY(-3px); box-shadow: 0 6px 20px rgba(0,0,0,0.1); }
.freq-summary-card.daily { border-left-color: #e76f51; }
.freq-summary-card.weekly { border-left-color: #118ab2; }
.freq-summary-card.monthly { border-left-color: #2d6a4f; }
.freq-summary-card.quarterly { border-left-color: #7b2cbf; }
.freq-summary-card .freq-title { font-weight: 700; font-size: 1rem; margin-bottom: 4px; }
.freq-summary-card .freq-sub { font-size: .8rem; color: #888; }
.freq-summary-card .freq-nums { display: flex; gap: 12px; margin-top: 8px; }
.freq-summary-card .freq-nums .fn { text-align: center; }
.freq-summary-card .freq-nums .fn-val { font-size: 1.3rem; font-weight: 700; line-height: 1; }
.freq-summary-card .freq-nums .fn-lbl { font-size: .65rem; color: #888; }

/* Zone Group Card */
.zone-group-card {
  background: #fff; border-radius: 14px; padding: 16px 20px; margin-bottom: 16px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}
.zone-group-title {
  font-weight: 700; font-size: 1.05rem; color: var(--primary); margin-bottom: 10px;
  display: flex; align-items: center; gap: 8px;
}
.zone-group-title .zg-count {
  font-size: .75rem; font-weight: 500; color: #888; background: #f0f0f0;
  padding: 2px 8px; border-radius: 10px;
}
.zone-group-title .zg-pct {
  font-size: .8rem; font-weight: 600; margin-left: auto;
}

/* Zone Task Card */
.zt-card {
  background: #f8faf8; border-radius: 10px; padding: 10px 14px; margin-bottom: 8px;
  border: 1px solid #e8ece8; display: flex; align-items: center; gap: 12px;
}
.zt-zone-badge {
  font-weight: 700; font-size: .85rem; padding: 4px 10px; border-radius: 8px;
  min-width: 48px; text-align: center; flex-shrink: 0;
}
.zt-zone-badge.done { background: #d8f3dc; color: #1b5e20; }
.zt-zone-badge.pending { background: #fff3e0; color: #e65100; }
.zt-zone-badge.partial { background: #e3f2fd; color: #0d47a1; }
.zt-tasks { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.zt-chip {
  padding: 2px 8px; border-radius: 6px; font-size: .7rem; font-weight: 500;
}
.zt-chip.done { background: #d8f3dc; color: #1b5e20; text-decoration: line-through; opacity: .6; }
.zt-chip.pending { background: #fff3e0; color: #e65100; }
.zt-chip.ip { background: #e3f2fd; color: #0d47a1; }
.zt-progress { width: 60px; flex-shrink: 0; }
.zt-pct { font-size: .75rem; font-weight: 700; text-align: right; flex-shrink: 0; min-width: 40px; }

/* Frequency mini-stats */
.mini-stat {
  background: #fff; border-radius: 10px; padding: 12px 16px; text-align: center;
  box-shadow: 0 1px 6px rgba(0,0,0,0.05);
}
.mini-stat .ms-val { font-size: 1.5rem; font-weight: 700; line-height: 1; }
.mini-stat .ms-lbl { font-size: .7rem; color: #888; margin-top: 2px; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { width: var(--sidebar-collapsed); }
  .sidebar .sidebar-header span, .sidebar .sidebar-menu li span, .sidebar .sidebar-footer { display: none; }
  .main-content { margin-left: var(--sidebar-collapsed); }
  .top-bar { padding: 8px 12px; }
  .page { padding: 12px; }
  .freq-page-header { flex-direction: column; align-items: flex-start; }
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #b2bec3; border-radius: 3px; }

/* Clickable */
.clickable { cursor: pointer; transition: all .15s; }
.clickable:hover { opacity: .8; transform: scale(1.02); }
.task-link { color: var(--primary); text-decoration: none; font-weight: 600; }
.task-link:hover { text-decoration: underline; }
.badge-freq { background: #e8e8e8; color: #555; font-size: .7rem; }

/* Language Switch */
.lang-switch { display: flex; gap: 2px; }
.lang-sw-btn { border: 1px solid #ddd; background: #fff; border-radius: 6px; padding: 2px 6px; font-size: .8rem; cursor: pointer; transition: all .2s; }
.lang-sw-btn.active { border-color: var(--accent); background: #d8f3dc; }

/* Portal Links */
.portal-link { font-size: .8rem !important; }

/* Work Log Modal */
.worklog-overlay { position: fixed; inset: 0; z-index: 9999; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; }
.worklog-box { background: #fff; border-radius: 16px; width: 94%; max-width: 500px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.worklog-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid #eee; }
.worklog-header h5 { margin: 0; color: var(--primary); }
.worklog-body { padding: 20px; }
.wl-preview { display: flex; gap: 6px; flex-wrap: wrap; }
.wl-preview img { width: 60px; height: 60px; object-fit: cover; border-radius: 8px; border: 2px solid var(--accent); }
.wl-user-info { background: #f0f7f0; border-radius: 10px; padding: 10px 14px; display: flex; align-items: center; gap: 10px; }
.wl-user-info .wl-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1rem; }
.wl-user-info .wl-uname { font-weight: 600; font-size: .95rem; }
.wl-user-info .wl-uchange { font-size: .7rem; color: var(--primary); cursor: pointer; text-decoration: underline; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.zone-group-card, .zt-card, .freq-summary-card { animation: fadeIn .3s ease; }
