/* ============================================================
   HỆ THỐNG QUẢN LÝ NHIỆM VỤ KH&CN — Trang chủ
   CSS thuần, không phụ thuộc internet / CDN
   ============================================================ */

:root {
  --navy-900: #0f2168;
  --navy-800: #12235f;
  --navy-700: #16307f;
  --navy-600: #1c3fa0;
  --navy-ink: #12225a;
  --nav-ink: #24346e;
  --nav-sub: #3c4a76;
  --nav-sub2: #58658d;
  --amber-500: #f0a12a;
  --amber-400: #f5b93f;
  --blue: #1668d8;
  --blue-dark: #1d4ed8;
  --green: #17a05a;
  --green-dark: #15803d;
  --purple: #6d3fc4;
  --purple-dark: #6d28d9;
  --orange: #f2841a;
  --orange-dark: #ea580c;
  --red: #e11d2b;
  --amber-warn: #f08a1d;
  --page-bg: #f2f5f9;
  --card-bd: #e6ebf3;
  --line: #e3e8f1;
  --text: #1f2937;
  --text-2: #374151;
  --text-3: #4b5563;
  --muted: #6b7280;
  --muted-2: #8a94ab;
  --radius: 12px;
  --sidebar-w: 252px;
  --sidebar-w-collapsed: 70px;
  --font: 'Segoe UI', Tahoma, Geneva, Verdana, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--page-bg);
  color: var(--text);
}

a { color: var(--blue-dark); text-decoration: none; }
a:hover { color: var(--navy-700); text-decoration: underline; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #c7cdd6; border-radius: 4px; }

.icon { display: block; width: 100%; height: 100%; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Khung trang ---------- */
.app { display: flex; flex-direction: column; min-height: 100vh; }
.app__body { display: flex; flex: 1; min-height: 0; }

/* ---------- Header ---------- */
.header {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 10px 22px;
  background: linear-gradient(100deg, var(--navy-900) 0%, var(--navy-700) 55%, var(--navy-600) 100%);
}

.header__logo {
  width: 44px; height: 44px; flex-shrink: 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: conic-gradient(from 200deg, #e8462f 0deg 85deg, #f2b418 85deg 175deg, #2fae5f 175deg 265deg, #2a7de1 265deg 360deg);
}
.header__logo span { width: 17px; height: 17px; border-radius: 50%; background: var(--navy-800); }

.header__titles { flex: 1; min-width: 230px; }
.header__title {
  margin: 0;
  color: #fff;
  font-size: clamp(15px, 1.75vw, 23px);
  font-weight: 800;
  letter-spacing: .2px;
  line-height: 1.15;
}
.header__subtitle { color: #f5c033; font-size: clamp(11px, 1vw, 14px); font-weight: 700; margin-top: 2px; }

.header__tools { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }

.lang {
  display: flex; align-items: center; gap: 7px;
  background: #fff; padding: 6px 10px; border-radius: 8px;
  border: 0; cursor: pointer; font-family: inherit;
}
.lang__flag {
  width: 22px; height: 15px; border-radius: 2px; background: #da251d;
  display: flex; align-items: center; justify-content: center;
}
.lang__flag .icon { width: 11px; height: 11px; }
.lang__code { color: var(--text); font-size: 13px; font-weight: 600; }
.lang .caret { width: 10px; height: 10px; }

.bell { position: relative; display: flex; align-items: center; }
.bell .icon { width: 23px; height: 23px; }
.bell__badge {
  position: absolute; top: -5px; right: -7px;
  background: #3b82f6; color: #fff;
  font-size: 10px; font-weight: 700;
  border-radius: 9px; min-width: 17px; text-align: center;
  padding: 1px 4px; border: 1.5px solid var(--navy-700);
}

.who { display: flex; align-items: center; gap: 9px; }
.who__avatar {
  width: 36px; height: 36px; border-radius: 50%; background: #cfd6e6;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.who__avatar .icon { width: 21px; height: 21px; }
.who__name { color: #fff; font-size: 13px; font-weight: 600; }
.who__role { color: #b9c3e0; font-size: 11.5px; }
.who .caret { width: 11px; height: 11px; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .2s ease;
}

.sidebar__toggle {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 12px 4px;
  background: none; border: 0; cursor: pointer;
  font-family: inherit; width: 100%;
}
.sidebar__toggle .icon { width: 20px; height: 20px; }
.sidebar__toggle-text { color: var(--muted-2); font-size: 11.5px; }

.nav { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px; }

.nav__link {
  display: flex; align-items: center; gap: 11px;
  width: 100%; padding: 11px 12px;
  border: 0; border-radius: 8px; background: none;
  color: var(--nav-ink); font-family: inherit; font-size: 13.5px;
  text-align: left; cursor: pointer;
}
.nav__link:hover { background: #eef2fa; }
.nav__link .icon { width: 19px; height: 19px; flex-shrink: 0; }
.nav__label { flex: 1; min-width: 0; }
.nav__caret { font-size: 9px; color: #7b87a8; flex-shrink: 0; transition: transform .18s ease; }
.nav__link[aria-expanded="true"] .nav__caret { transform: rotate(90deg); }

.nav__link--active {
  background: linear-gradient(90deg, var(--amber-500), var(--amber-400));
  color: #fff; font-weight: 700;
  box-shadow: 0 2px 6px rgba(240, 161, 42, .35);
}
.nav__link--active:hover { background: linear-gradient(90deg, var(--amber-500), var(--amber-400)); }

/* cấp 2 + cấp 3 */
.nav__sub { display: none; flex-direction: column; gap: 1px; margin: 2px 0 4px; }
.nav__sub.is-open { display: flex; }

.nav__sublink {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 8px 12px 8px 34px;
  border: 0; border-radius: 8px; background: none;
  color: var(--nav-sub); font-family: inherit; font-size: 12.5px;
  text-align: left; cursor: pointer;
}
.nav__sublink:hover { background: #eef2fa; }
.nav__dot { width: 5px; height: 5px; border-radius: 50%; background: #8494c4; flex-shrink: 0; }

.nav__sublink--l3 { padding: 7px 12px 7px 52px; color: var(--nav-sub2); font-size: 12px; }
.nav__sublink--l3 .nav__dot { width: 4px; height: 4px; background: #a4b0d2; }

.sidebar__footer {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding: 16px 18px;
  display: flex; align-items: center; gap: 11px;
}
.sidebar__avatar {
  width: 40px; height: 40px; border-radius: 50%; background: #d8dfec;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.sidebar__avatar .icon { width: 23px; height: 23px; }
.sidebar__name { color: var(--navy-ink); font-size: 13px; font-weight: 700; }
.sidebar__role { color: var(--muted-2); font-size: 11.5px; }
.sidebar__logout { padding: 0 20px 10px; background: none; border: 0; cursor: pointer; }
.sidebar__logout .icon { width: 24px; height: 24px; }

/* trạng thái thu gọn */
.sidebar.is-collapsed { width: var(--sidebar-w-collapsed); }
.sidebar.is-collapsed .nav__label,
.sidebar.is-collapsed .nav__caret,
.sidebar.is-collapsed .nav__sub,
.sidebar.is-collapsed .sidebar__toggle-text,
.sidebar.is-collapsed .sidebar__meta,
.sidebar.is-collapsed .sidebar__logout { display: none; }
.sidebar.is-collapsed .sidebar__toggle { justify-content: center; }
.sidebar.is-collapsed .nav__link { justify-content: center; padding: 11px 8px; }
.sidebar.is-collapsed .sidebar__footer { justify-content: center; padding: 16px 8px; }

/* ---------- Vùng nội dung ---------- */
.main {
  flex: 1; min-width: 0;
  padding: clamp(12px, 1.6vw, 20px) clamp(12px, 2vw, 22px) 32px;
  overflow-y: auto;
}

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 16px;
}
.page-head__title {
  margin: 0;
  font-size: clamp(17px, 2.1vw, 27px);
  color: var(--navy-ink);
  font-weight: 800;
  letter-spacing: -.2px;
  text-wrap: pretty;
}

/* chọn năm */
.year-picker {
  background: #fff; border: 1px solid #dbe1ea; border-radius: 8px;
  padding: 4px 10px 5px;
  display: flex; align-items: center; gap: 10px; min-width: 152px;
}
.year-picker__label { font-size: 10.5px; color: var(--muted-2); padding-left: 2px; }
.year-picker__field { flex: 1; min-width: 0; }
.year-picker .caret { width: 12px; height: 12px; flex-shrink: 0; }

.select {
  width: 100%;
  border: 0; outline: none; background: transparent;
  font-family: inherit; font-size: 15px; color: var(--text); font-weight: 600;
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  cursor: pointer; padding: 0 0 0 1px;
}
.select--sm { font-size: 12.5px; font-weight: 400; color: var(--text-3); width: auto; }

/* ---------- Thẻ chỉ số ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(196px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}
.stat {
  background: #fff; border: 1px solid var(--card-bd); border-radius: var(--radius);
  padding: 16px 18px 18px;
  box-shadow: 0 1px 2px rgba(18, 34, 90, .05);
}
.stat__head { display: flex; align-items: flex-start; gap: 11px; margin-bottom: 12px; }
.stat__icon {
  width: 40px; height: 40px; border-radius: 11px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.stat__icon .icon { width: 22px; height: 22px; }
.stat__label { font-size: 13px; color: var(--text-3); line-height: 1.32; font-weight: 500; }
.stat__body { text-align: center; }
.stat__value { font-size: 40px; font-weight: 800; line-height: 1; }
.stat__unit { font-size: 13px; color: var(--muted); margin-top: 6px; }
.stat__delta { font-size: 12px; margin-top: 8px; color: var(--muted); }
.stat__delta--up { color: #16a34a; }

/* nền icon */
.bg-blue { background: #e7effd; }
.bg-green { background: #e5f6ed; }
.bg-purple { background: #efe9fb; }
.bg-orange { background: #fdeee4; }
.bg-red { background: #fde8e8; }
.bg-amber { background: #fdefe2; }

.t-blue { color: var(--blue-dark); }
.t-green { color: var(--green-dark); }
.t-purple { color: var(--purple-dark); }
.t-orange { color: var(--orange-dark); }

/* ---------- Hàng biểu đồ ---------- */
.panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
  align-items: start;
}
.panel {
  background: #fff; border: 1px solid var(--card-bd); border-radius: var(--radius);
  padding: 16px 18px;
}
.panel__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 10px;
}
.panel__title { font-size: 16px; font-weight: 700; color: var(--navy-ink); }
.panel__caption { text-align: center; font-size: 12.5px; color: var(--muted); margin-top: 10px; }

.chip-select {
  border: 1px solid #dbe1ea; border-radius: 7px; padding: 4px 8px;
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--text-3);
}
.chip-select .caret { width: 10px; height: 10px; flex-shrink: 0; }

/* biểu đồ tròn thuần CSS */
.chart { display: flex; align-items: center; justify-content: center; gap: 26px; flex-wrap: wrap; }
.pie { width: 210px; height: 210px; border-radius: 50%; position: relative; flex-shrink: 0; }
.pie--tasks {
  background: conic-gradient(var(--blue) 0deg 60deg, var(--green) 60deg 180deg,
                             var(--purple) 180deg 276deg, var(--orange) 276deg 360deg);
}
.pie--funds {
  background: conic-gradient(var(--blue) 0deg 60deg, var(--green) 60deg 184.8deg,
                             var(--purple) 184.8deg 283.2deg, var(--orange) 283.2deg 360deg);
}
.pie__label {
  position: absolute;
  transform: translate(-50%, -50%);
  text-align: center;
  color: #fff;
  font-weight: 700;
  line-height: 1.15;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .18);
}
.pie__num { font-size: 19px; }
.pie__num--sm { font-size: 17px; }
.pie__pct { font-size: 11px; font-weight: 600; }

.legend { display: flex; flex-direction: column; gap: 16px; font-size: 14px; color: var(--text-2); font-weight: 500; }
.legend__item { display: flex; align-items: center; gap: 10px; }
.legend__swatch { width: 13px; height: 13px; border-radius: 3px; flex-shrink: 0; }
.sw-blue { background: var(--blue); }
.sw-green { background: var(--green); }
.sw-purple { background: var(--purple); }
.sw-orange { background: var(--orange); }

/* ---------- Cảnh báo ---------- */
.alerts { display: flex; flex-direction: column; gap: 18px; }
.alert { display: flex; align-items: center; gap: 12px; }
.alert__icon {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.alert__icon .icon { width: 21px; height: 21px; }
.alert__text { flex: 1; font-size: 13.5px; color: var(--text-2); line-height: 1.3; font-weight: 500; }
.alert__meta { text-align: center; flex-shrink: 0; }
.alert__count {
  color: #fff; font-size: 19px; font-weight: 800;
  border-radius: 7px; padding: 2px 11px; line-height: 1.25;
}
.alert__tag {
  color: #fff; font-size: 8.5px; font-weight: 600;
  border-radius: 4px; padding: 1px 4px; margin-top: 3px;
}
.fill-red { background: var(--red); }
.fill-amber { background: var(--amber-warn); }

/* ---------- Sản phẩm KH&CN ---------- */
.products {
  background: #fff; border: 1px solid var(--card-bd); border-radius: var(--radius);
  padding: 16px 18px 18px; margin-top: 14px;
}
.products__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 8px;
}
.product { display: flex; align-items: center; gap: 14px; padding: 4px 22px; border-left: 1px solid #eef1f5; }
.product:first-child { border-left: 0; }
.product__icon {
  width: 46px; height: 46px; border-radius: 12px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.product__icon .icon { width: 25px; height: 25px; }
.product__label { font-size: 13px; color: var(--text-3); font-weight: 500; }
.product__figure { display: flex; align-items: baseline; gap: 6px; }
.product__value { font-size: 27px; font-weight: 800; }
.product__suffix { font-size: 13px; color: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .pie { width: 180px; height: 180px; }
  .pie__num { font-size: 17px; }
  .pie__num--sm { font-size: 15px; }
  .chart { gap: 18px; }
}

@media (max-width: 980px) {
  .sidebar { width: var(--sidebar-w-collapsed); }
  .sidebar .nav__label,
  .sidebar .nav__caret,
  .sidebar .sidebar__toggle-text,
  .sidebar .sidebar__meta,
  .sidebar .sidebar__logout { display: none; }
  .sidebar .nav__link { justify-content: center; padding: 11px 8px; }
  .sidebar .sidebar__toggle { justify-content: center; }
  .sidebar .sidebar__footer { justify-content: center; padding: 16px 8px; }
  /* khi người dùng bấm mở lại thì hiện đầy đủ */
  .sidebar.is-expanded { width: var(--sidebar-w); }
  .sidebar.is-expanded .nav__label,
  .sidebar.is-expanded .nav__caret,
  .sidebar.is-expanded .sidebar__toggle-text,
  .sidebar.is-expanded .sidebar__meta,
  .sidebar.is-expanded .sidebar__logout { display: block; }
  .sidebar.is-expanded .nav__sub.is-open { display: flex; }
  .sidebar.is-expanded .nav__link { justify-content: flex-start; padding: 11px 12px; }
  .sidebar.is-expanded .sidebar__toggle { justify-content: space-between; }
  .sidebar.is-expanded .sidebar__footer { justify-content: flex-start; padding: 16px 18px; }
}

@media (max-width: 760px) {
  .header { padding: 10px 14px; }
  .who__name, .who__role { display: none; }
  .product { border-left: 0; padding: 4px 6px; }
  .page-head__title { font-size: 19px; }
}

@media (max-width: 520px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stat__value { font-size: 32px; }
  .pie { width: 168px; height: 168px; }
  .legend { font-size: 13px; gap: 12px; }
}

/* ---------- In ấn ---------- */
@media print {
  .sidebar, .header__tools { display: none; }
  .main { overflow: visible; }
  body { background: #fff; }
}
