/* ============================================================
   Nhật ký chạy — hệ thiết kế
   Token màu ở :root, tối định nghĩa lại theo máy (prefers-color-scheme) hoặc theo lựa chọn (data-theme).
   Màu chính teal = chạy/tiến độ · cam = thành tích/điểm cần chú ý · đỏ/vàng/xanh lá chỉ dùng cho trạng thái.
   ============================================================ */
:root {
  --nen: #F5F7F8;
  --the: #FFFFFF;
  --the-2: #F0F3F5;
  --chu: #0F1C24;
  --chu-2: #4F5E68;
  --chu-3: #7B8892;
  --vien: #E2E7EB;
  --chinh: #0E9F8E;
  --chinh-dam: #0A7D70;
  --chinh-nhat: #E2F5F2;
  --nhan: #E8691F;
  --nhan-nhat: #FDEEE4;
  --tot: #1E9E5A;
  --canh: #B7850A;
  --xau: #D14343;
  --xau-nhat: #FCEBEB;
  --hr: #D9485F;
  --bong: 0 1px 2px rgba(15, 28, 36, .05), 0 4px 16px rgba(15, 28, 36, .05);
  --bo: 14px;
  --bo-nho: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --nen: #0B1217; --the: #121C23; --the-2: #18242C; --chu: #E8EEF1; --chu-2: #A3B1BA; --chu-3: #74838D; --vien: #22313B;
    --chinh: #2CC4B0; --chinh-dam: #5AD6C5; --chinh-nhat: #12302D; --nhan: #FF8A47; --nhan-nhat: #3A2416;
    --tot: #3CC97E; --canh: #E3B341; --xau: #F06C6C; --xau-nhat: #3A1A1C; --hr: #FF6B81;
    --bong: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --nen: #0B1217; --the: #121C23; --the-2: #18242C; --chu: #E8EEF1; --chu-2: #A3B1BA; --chu-3: #74838D; --vien: #22313B;
  --chinh: #2CC4B0; --chinh-dam: #5AD6C5; --chinh-nhat: #12302D; --nhan: #FF8A47; --nhan-nhat: #3A2416;
  --tot: #3CC97E; --canh: #E3B341; --xau: #F06C6C; --xau-nhat: #3A1A1C; --hr: #FF6B81;
  --bong: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--nen); color: var(--chu);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "cv11", "ss01";
}
.so, .kpi-so, td.so, .tabular { font-variant-numeric: tabular-nums; }
a { color: var(--chinh-dam); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 24px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--chinh); outline-offset: 2px; }
[hidden] { display: none !important; }
.an-chu { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Bố cục ---------- */
.khung { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.thanh-ben {
  position: sticky; top: 0; height: 100vh; padding: 20px 14px; border-right: 1px solid var(--vien);
  background: var(--the); display: flex; flex-direction: column; gap: 4px;
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 4px 10px 18px; color: var(--chu); }
.logo img { width: 30px; height: 30px; }
.muc-menu {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--bo-nho);
  color: var(--chu-2); font-weight: 500; text-decoration: none !important;
}
.muc-menu svg { width: 20px; height: 20px; flex: none; }
.muc-menu:hover { background: var(--the-2); color: var(--chu); }
.muc-menu.dang { background: var(--chinh-nhat); color: var(--chinh-dam); }
.muc-menu.nut-them { margin-top: 10px; background: var(--chinh); color: #fff; justify-content: center; font-weight: 600; }
.muc-menu.nut-them:hover { background: var(--chinh-dam); color: #fff; }
.thanh-ben .day { margin-top: auto; }
.noi-dung { padding: 28px 32px 48px; max-width: 1240px; width: 100%; min-width: 0; }
.dau-trang { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.dau-trang p { margin: 4px 0 0; color: var(--chu-2); }
.dieu-huong-day { display: none; }

@media (max-width: 860px) {
  .khung { grid-template-columns: minmax(0, 1fr); }
  .thanh-ben { display: none; }
  .noi-dung { padding: 18px 16px calc(96px + env(safe-area-inset-bottom)); }
  .dieu-huong-day {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--the); border-top: 1px solid var(--vien); padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  }
  .dieu-huong-day a {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; min-height: 52px;
    font-size: 11.5px; font-weight: 500; color: var(--chu-3); text-decoration: none !important; border-radius: 10px;
  }
  .dieu-huong-day a svg { width: 22px; height: 22px; }
  .dieu-huong-day a.dang { color: var(--chinh-dam); }
  .dieu-huong-day a.nut-them svg { background: var(--chinh); color: #fff; border-radius: 50%; padding: 4px; width: 30px; height: 30px; margin-top: -4px; }
  h1 { font-size: 21px; }
}

/* ---------- Thẻ, lưới ---------- */
.the { background: var(--the); border: 1px solid var(--vien); border-radius: var(--bo); padding: 18px; box-shadow: var(--bong); min-width: 0; }
.the > h2, .the-dau { margin-bottom: 14px; }
.the-dau { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.the-dau h2 { margin: 0; }
.luoi { display: grid; gap: 16px; }
.luoi-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.luoi-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1000px) { .luoi-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 680px) { .luoi-2, .luoi-3 { grid-template-columns: minmax(0, 1fr); } }
.khoi { margin-bottom: 16px; }
.mo { color: var(--chu-2); }
.mo-3 { color: var(--chu-3); font-size: 13px; }

/* ---------- KPI ---------- */
.kpi-luoi { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--the); border: 1px solid var(--vien); border-radius: var(--bo); padding: 14px 16px; box-shadow: var(--bong); min-width: 0; }
.kpi-nhan { font-size: 13px; color: var(--chu-2); font-weight: 500; }
.kpi-so { font-size: 26px; font-weight: 600; letter-spacing: -.02em; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-so small { font-size: 14px; font-weight: 500; color: var(--chu-2); margin-left: 3px; letter-spacing: 0; }
.kpi-phu { font-size: 12.5px; color: var(--chu-3); margin-top: 2px; min-height: 19px; }
.tang { color: var(--tot); font-weight: 600; }
.giam { color: var(--xau); font-weight: 600; }
.ngang { color: var(--chu-3); font-weight: 600; }

/* ---------- Nút, chip, form ---------- */
.nut {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 16px;
  border-radius: var(--bo-nho); border: 1px solid var(--vien); background: var(--the); color: var(--chu);
  font-weight: 600; cursor: pointer; text-decoration: none !important; white-space: nowrap;
}
.nut:hover { background: var(--the-2); }
.nut svg { width: 18px; height: 18px; }
.nut-chinh { background: var(--chinh); border-color: var(--chinh); color: #fff; }
.nut-chinh:hover { background: var(--chinh-dam); border-color: var(--chinh-dam); }
:root[data-theme="dark"] .nut-chinh, :root[data-theme="dark"] .muc-menu.nut-them { color: #06201C; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .nut-chinh, :root:not([data-theme="light"]) .muc-menu.nut-them { color: #06201C; } }
.nut-xau { color: var(--xau); }
.nut-xau:hover { background: var(--xau-nhat); }
.nut-nho { min-height: 34px; padding: 0 12px; font-size: 13.5px; }
.nut:disabled { opacity: .55; cursor: not-allowed; }
.hang-nut { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.chip-nhom { display: inline-flex; gap: 4px; padding: 4px; background: var(--the-2); border-radius: 12px; flex-wrap: wrap; }
.chip { border: 0; background: transparent; padding: 7px 12px; border-radius: 9px; font-weight: 500; font-size: 13.5px; color: var(--chu-2); cursor: pointer; min-height: 34px; }
.chip.dang { background: var(--the); color: var(--chu); box-shadow: var(--bong); }

.nhan-loai {
  display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600;
  background: var(--the-2); color: var(--chu-2); white-space: nowrap;
}
.nhan-loai.race { background: var(--nhan-nhat); color: var(--nhan); }
.nhan-loai.long, .nhan-loai.tempo, .nhan-loai.interval { background: var(--chinh-nhat); color: var(--chinh-dam); }

.form { display: grid; gap: 14px; }
.form-luoi { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.truong { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.truong > span { font-size: 13px; font-weight: 500; color: var(--chu-2); }
.truong em { font-style: normal; color: var(--chu-3); font-weight: 400; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid var(--vien); border-radius: var(--bo-nho);
  background: var(--the); font-size: 16px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--chinh); box-shadow: 0 0 0 3px var(--chinh-nhat); }
.o-thoi-gian { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.o-thoi-gian input { text-align: center; padding: 9px 4px; }
.loi-form { color: var(--xau); font-size: 14px; min-height: 20px; }
.goi-y { font-size: 13px; color: var(--chu-3); }

/* ---------- Danh sách hoạt động ---------- */
.ds-hd { display: flex; flex-direction: column; }
.dong-hd {
  display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 14px; align-items: center;
  padding: 12px 6px; border-bottom: 1px solid var(--vien); color: inherit; text-decoration: none !important; border-radius: 8px;
}
.dong-hd:last-child { border-bottom: 0; }
.dong-hd:hover { background: var(--the-2); }
.ngay-o { text-align: center; line-height: 1.1; }
.ngay-o b { display: block; font-size: 20px; font-weight: 600; }
.ngay-o span { font-size: 12px; color: var(--chu-3); }
.hd-ten { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hd-phu { font-size: 13px; color: var(--chu-3); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 2px; }
.hd-so { display: flex; gap: 22px; text-align: right; }
.hd-so div b { display: block; font-size: 16px; font-weight: 600; }
.hd-so div span { font-size: 12px; color: var(--chu-3); }
@media (max-width: 680px) {
  .dong-hd { grid-template-columns: 44px minmax(0, 1fr); }
  .hd-so { grid-column: 2; justify-content: flex-start; gap: 18px; text-align: left; margin-top: 2px; }
}

/* ---------- Bộ lọc ---------- */
.loc { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.loc .truong > span { font-size: 12px; }
.tong-loc { display: flex; gap: 18px; flex-wrap: wrap; font-size: 14px; color: var(--chu-2); margin: 12px 0 4px; }
.tong-loc b { color: var(--chu); }

/* ---------- Lịch tháng ---------- */
.lich { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.lich-thu { font-size: 12px; font-weight: 600; color: var(--chu-3); text-align: center; padding-bottom: 4px; }
.lich-o {
  aspect-ratio: 1 / 1; min-height: 44px; border-radius: 10px; border: 1px solid var(--vien); background: var(--the);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; padding: 2px;
}
.lich-o.trong { visibility: hidden; }
.lich-o .n { font-size: 13px; color: var(--chu-2); }
.lich-o .k { font-size: 11.5px; font-weight: 600; }
.lich-o.co { background: var(--chinh-nhat); border-color: transparent; }
.lich-o.co .k { color: var(--chinh-dam); }
.lich-o.muc-2 { background: color-mix(in srgb, var(--chinh) 35%, var(--the)); }
.lich-o.muc-3 { background: color-mix(in srgb, var(--chinh) 60%, var(--the)); }
.lich-o.muc-3 .k, .lich-o.muc-3 .n { color: #fff; }
.lich-o.race { box-shadow: inset 0 0 0 2px var(--nhan); }
.lich-o.hom-nay .n { font-weight: 700; color: var(--chu); text-decoration: underline; }
.lich-o.chon { outline: 2px solid var(--chu); outline-offset: 1px; }

/* ---------- Chi tiết ---------- */
.so-luoi { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); border: 1px solid var(--vien); border-radius: var(--bo-nho); overflow: hidden; }
.so-luoi > div { background: var(--the); padding: 12px 14px; box-shadow: 1px 1px 0 var(--vien); }
.so-luoi span { display: block; font-size: 12.5px; color: var(--chu-3); }
.so-luoi b { font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; }
.so-luoi b small { font-size: 13px; color: var(--chu-2); font-weight: 500; margin-left: 2px; }
.ban-do { height: 360px; border-radius: var(--bo-nho); overflow: hidden; border: 1px solid var(--vien); z-index: 0; }
@media (max-width: 680px) { .ban-do { height: 260px; } }
.bang-cuon { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.bang { width: 100%; border-collapse: collapse; font-size: 14px; }
.bang th { text-align: left; font-size: 12px; color: var(--chu-3); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--vien); white-space: nowrap; }
.bang td { padding: 8px 10px; border-bottom: 1px solid var(--vien); white-space: nowrap; }
.bang td.so, .bang th.so { text-align: right; }
.bang tr:last-child td { border-bottom: 0; }
.thanh-split { position: relative; height: 18px; min-width: 120px; background: var(--the-2); border-radius: 5px; overflow: hidden; }
.thanh-split i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--chinh); border-radius: 5px; opacity: .85; }
.thanh-split.nhanh i { background: var(--tot); }
.thanh-split.cham i { background: var(--nhan); }
.anh-luoi { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.anh-o { position: relative; aspect-ratio: 1; border-radius: var(--bo-nho); overflow: hidden; background: var(--the-2); }
.anh-o img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; }
.anh-o button { position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .55); color: #fff; cursor: pointer; }
.ghi-chu-o { white-space: pre-wrap; }
.nhan-nguon { font-size: 12px; color: var(--chu-3); }

/* ---------- Biểu đồ ---------- */
.bd { position: relative; width: 100%; }
.bd svg { display: block; width: 100%; overflow: visible; }
.bd .truc text { font-size: 11px; fill: var(--chu-3); }
.bd .luoi-ngang { stroke: var(--vien); stroke-width: 1; }
.bd-tip {
  position: absolute; pointer-events: none; background: var(--chu); color: var(--the); font-size: 12.5px; line-height: 1.4;
  padding: 6px 9px; border-radius: 8px; white-space: nowrap; transform: translate(-50%, -100%); margin-top: -10px; z-index: 5;
  font-variant-numeric: tabular-nums;
}
.bd-tip b { font-weight: 600; }
.bd-trong { height: 160px; display: flex; align-items: center; justify-content: center; color: var(--chu-3); font-size: 14px; border: 1px dashed var(--vien); border-radius: var(--bo-nho); }
.chu-giai { display: flex; gap: 14px; font-size: 12.5px; color: var(--chu-2); flex-wrap: wrap; }
.chu-giai i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- Nhập file ---------- */
.vung-tha {
  border: 2px dashed var(--vien); border-radius: var(--bo); padding: 32px 20px; text-align: center; cursor: pointer;
  background: var(--the); transition: border-color .15s, background .15s;
}
.vung-tha:hover, .vung-tha.keo { border-color: var(--chinh); background: var(--chinh-nhat); }
.vung-tha svg { width: 36px; height: 36px; color: var(--chinh); }
.vung-tha b { display: block; margin: 8px 0 4px; font-size: 16px; }
.the-nhap { border: 1px solid var(--vien); border-radius: var(--bo); padding: 16px; background: var(--the); display: grid; gap: 12px; }
.the-nhap.loi { border-color: var(--xau); }
.the-nhap.xong { border-color: var(--tot); }
.trang-thai { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; padding: 3px 10px; border-radius: 99px; }
.trang-thai.moi { background: var(--chinh-nhat); color: var(--chinh-dam); }
.trang-thai.trung { background: var(--xau-nhat); color: var(--xau); }
.trang-thai.nghi { background: var(--nhan-nhat); color: var(--nhan); }
.trang-thai.xong { background: var(--chinh-nhat); color: var(--tot); }
.canh-bao { background: var(--nhan-nhat); color: var(--chu); border-radius: var(--bo-nho); padding: 10px 12px; font-size: 14px; }

/* ---------- Trống / tải / lỗi ---------- */
.trong-o { text-align: center; padding: 40px 16px; color: var(--chu-2); }
.trong-o svg { width: 44px; height: 44px; color: var(--chu-3); }
.trong-o h3 { margin: 10px 0 6px; color: var(--chu); }
.trong-o p { margin: 0 auto 16px; max-width: 420px; }
.tai-trang { display: flex; align-items: center; justify-content: center; min-height: 50vh; }
.vong-quay { width: 28px; height: 28px; border: 3px solid var(--vien); border-top-color: var(--chinh); border-radius: 50%; animation: quay .8s linear infinite; }
@keyframes quay { to { transform: rotate(360deg); } }
.xuong { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--the-2), var(--vien), var(--the-2)); background-size: 200% 100%; animation: song 1.2s infinite; }
@keyframes song { to { background-position: -200% 0; } }
.loi-o { background: var(--xau-nhat); color: var(--xau); padding: 14px 16px; border-radius: var(--bo-nho); }

/* ---------- Thông báo, hộp thoại ---------- */
.thong-bao {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--chu); color: var(--the); padding: 12px 16px; border-radius: 12px; z-index: 100; display: flex; gap: 14px; align-items: center;
  max-width: calc(100vw - 32px); transition: opacity .2s, transform .2s; font-size: 14.5px;
}
.thong-bao.hien { opacity: 1; transform: translateX(-50%); pointer-events: auto; }
.thong-bao.loi { background: var(--xau); color: #fff; }
.thong-bao button { background: transparent; border: 0; color: var(--chinh); font-weight: 700; cursor: pointer; padding: 4px; }
@media (max-width: 860px) { .thong-bao { bottom: calc(84px + env(safe-area-inset-bottom)); } }
dialog { border: 0; border-radius: var(--bo); padding: 22px; background: var(--the); color: var(--chu); max-width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
dialog::backdrop { background: rgba(8, 15, 20, .5); }
dialog h3 { margin-bottom: 8px; font-size: 17px; }
dialog p { margin: 0 0 18px; color: var(--chu-2); }
dialog .hang-nut { justify-content: flex-end; }
dialog.xem-anh { max-width: 96vw; padding: 0; background: transparent; box-shadow: none; }
dialog.xem-anh img { max-width: 96vw; max-height: 90vh; display: block; border-radius: 10px; }

/* ---------- Đăng nhập ---------- */
.dang-nhap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.dang-nhap .the { width: 100%; max-width: 380px; padding: 28px; }
.dang-nhap .logo { padding: 0 0 18px; }

/* ---------- Hồ sơ ---------- */
.ho-so-dai { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.anh-dd { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; background: var(--chinh-nhat); color: var(--chinh-dam); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 22px; flex: none; }
.ho-so-dai .thong-tin { display: flex; gap: 6px 18px; flex-wrap: wrap; font-size: 13.5px; color: var(--chu-2); }
.ho-so-dai .thong-tin b { color: var(--chu); font-weight: 600; }
.dong-phien { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--vien); flex-wrap: wrap; }
.dong-phien:last-child { border-bottom: 0; }
