:root {
    --bg: #0f172a;
    --panel: #1e293b;
    --panel-2: #263449;
    --border: #334155;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --danger: #ef4444;
    --radius: 12px;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}
a { color: #a5b4fc; text-decoration: none; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }

/* ---------- Topbar ---------- */
.topbar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 24px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
}
.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.home-link { text-decoration: none; opacity: .7; }
.home-link:hover { opacity: 1; }

.container { max-width: 1100px; margin: 24px auto; padding: 0 16px; }

/* ---------- Cards ---------- */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px; margin-bottom: 20px;
}
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}
.card-warn { border-color: #f59e0b; }
.card-label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.card-value { font-size: 22px; font-weight: 700; }
.fx-note { display: block; font-size: 12px; font-weight: 400; color: var(--muted); cursor: help; }

/* ---------- Panels & table ---------- */
.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 20px;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: none; }
.row-muted { opacity: .5; }
.actions { display: flex; gap: 6px; align-items: center; }
.actions form { margin: 0; }

.chip {
    background: var(--panel-2); border: 1px solid var(--border);
    border-radius: 999px; padding: 1px 8px; font-size: 11px; color: var(--muted); margin-left: 6px;
}
.badge { border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-green  { background: #064e3b; color: #6ee7b7; }
.badge-yellow { background: #4d3c05; color: #fde047; }
.badge-orange { background: #571f0c; color: #fdba74; }
.badge-red    { background: #5f1212; color: #fca5a5; }
.badge-blue   { background: #1e3a8a; color: #93c5fd; }
.badge-gray   { background: var(--panel-2); color: var(--muted); }

/* ---------- Buttons & inputs ---------- */
.btn {
    display: inline-block;
    background: var(--panel-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px;
    padding: 8px 14px; font-size: 14px; cursor: pointer;
}
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: #fca5a5; }
.btn-danger:hover { border-color: var(--danger); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.link-btn { background: none; border: none; color: #a5b4fc; cursor: pointer; padding: 0; font-size: 13px; }

input, select, textarea {
    width: 100%;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 14px;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
.date-input { cursor: pointer; }
.date-input::-webkit-calendar-picker-indicator { cursor: pointer; filter: invert(0.8); }

/* ---------- Form ---------- */
.grid-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}
.grid-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.grid-form .full { grid-column: 1 / -1; }
.checkbox-label { flex-direction: row !important; align-items: center; gap: 8px !important; }
.checkbox-label input { width: auto; }

code { background: var(--panel-2); border-radius: 4px; padding: 1px 5px; font-size: 13px; }
.code-block {
    background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
    padding: 12px 14px; overflow-x: auto; font-size: 12px; color: var(--text);
}

.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; font-family: monospace; font-size: 12px; }

/* ---------- Hub (trang trung gian) ---------- */
.hub-greeting { margin: 8px 0 22px; }
.hub-greeting h2 { font-size: 24px; margin: 0 0 4px; }

.hub-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}
.hub-card {
    display: flex; flex-direction: column;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    color: var(--text);
    text-decoration: none;
    transition: border-color .15s, transform .15s;
}
a.hub-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.hub-card-alert { border-color: #b45309; }
.hub-card-soon { opacity: .55; }

.hub-card-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 14px; }
.hub-icon { font-size: 30px; line-height: 1; }
.hub-card-head h3 { margin: 0 0 3px; font-size: 17px; }
.hub-card-head p { margin: 0; }

.hub-stats { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.hub-stats li { font-size: 14px; display: flex; gap: 8px; align-items: baseline; }
.hub-stat-icon { flex-shrink: 0; width: 18px; }
.hub-stats .tone-ok    { color: var(--muted); }
.hub-stats .tone-warn  { color: #fdba74; }
.hub-stats .tone-alert { color: #fca5a5; font-weight: 600; }

/* Xem trước vài mục cụ thể trong thẻ */
.hub-preview {
    list-style: none; margin: 0 0 14px; padding: 10px 12px;
    background: var(--bg); border-radius: 8px;
    display: flex; flex-direction: column; gap: 6px;
}
.hub-preview li { display: flex; gap: 10px; font-size: 13px; align-items: baseline; }
.hub-pre-left {
    flex-shrink: 0; min-width: 52px; color: #a5b4fc;
    font-variant-numeric: tabular-nums; font-size: 12.5px;
}
.hub-pre-right { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.hub-open { margin-top: auto; color: #a5b4fc; font-size: 14px; font-weight: 600; }

/* Bảng khóa-giá trị (trang cấu hình) */
table.kv { width: 100%; font-size: 14px; }
table.kv th { text-align: left; color: var(--muted); font-weight: 500; width: 170px;
              text-transform: none; letter-spacing: 0; font-size: 13px; }
.badge-red-text { color: #fca5a5; }
.badge-orange { background: #571f0c; color: #fdba74; border-radius: 999px; padding: 2px 9px; font-size: 11px; }
.btn-row { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.btn-row form { margin: 0; }

/* ---------- Nhắc việc ---------- */
.quick-add { display: flex; gap: 8px; margin-bottom: 6px; }
.quick-add input { flex: 1; font-size: 15px; padding: 12px 14px; }
.quick-hint { margin: 0 0 18px; }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab {
    padding: 7px 16px; border-radius: 999px; font-size: 14px;
    background: var(--panel); border: 1px solid var(--border); color: var(--muted);
}
.tab-on { background: var(--primary); border-color: var(--primary); color: #fff; }

.sec-overdue { border-color: #7f1d1d; }
.sec-today   { border-color: #3730a3; }

.task-list { list-style: none; margin: 0; padding: 0; }
.task-item {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 11px 0; border-bottom: 1px solid var(--border);
}
.task-item:last-child { border-bottom: none; }
.task-high { border-left: 3px solid #f59e0b; padding-left: 10px; margin-left: -13px; }
.task-done { opacity: .5; }
.task-done .task-title { text-decoration: line-through; }

.task-check { margin: 0; }
.check-btn {
    background: none; border: none; cursor: pointer;
    font-size: 18px; line-height: 1; padding: 2px; opacity: .75;
}
.check-btn:hover { opacity: 1; transform: scale(1.15); }

.task-body { flex: 1; min-width: 0; }
.task-title { font-size: 15px; margin-bottom: 3px; }
.task-meta { font-size: 12.5px; color: var(--muted); }
.task-late { color: #fca5a5; font-weight: 600; }
.chip-high { background: #78350f; color: #fcd34d; border-color: #92400e; }

.task-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.task-actions form { margin: 0; }

@media (max-width: 560px) {
    .task-actions .btn { padding: 3px 8px; font-size: 11px; }
    .quick-add { flex-direction: column; }
}

/* ---------- Thống kê & biểu đồ ---------- */
.stat-row {
    display: grid; gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
.stat-box {
    background: var(--panel-2); border: 1px solid var(--border);
    border-radius: 11px; padding: 13px 15px;
}
.stat-box.box-warn { border-color: #b45309; }
.stat-box small { display: block; color: var(--muted); font-size: 12px; margin-bottom: 5px; }
.stat-box b { display: block; font-size: 22px; font-weight: 750; letter-spacing: -.01em; }
.stat-box .sub { display: block; font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.stat-box .sub.up   { color: #fca5a5; }
.stat-box .sub.down { color: #6ee7b7; }

.chart-wrap { overflow-x: auto; margin: 6px 0 4px; }
/* min-width giữ cho nhãn đủ lớn (màn hình hẹp thì cuộn ngang trong khung biểu đồ),
   max-width để trên desktop biểu đồ không bị phóng quá to */
.chart {
    width: 100%; min-width: 430px; max-width: 760px;
    height: auto; display: block; color: var(--text);
}

.bar-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.bar-list li { display: flex; align-items: center; gap: 10px; font-size: 13.5px; }
.bl-label { flex: 0 0 34%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.bl-track { flex: 1; height: 9px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.bl-track i { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.bl-track i.teal { background: #2dd4bf; }
.bl-value { flex-shrink: 0; font-size: 12.5px; color: var(--text); font-variant-numeric: tabular-nums; }

.chip-trial { background: #4c1d95; color: #ddd6fe; border-color: #6d28d9; }
.chip-up    { background: #7c2d12; color: #fdba74; border-color: #9a3412; cursor: help; }

@media (max-width: 520px) {
    .bl-label { flex-basis: 30%; font-size: 12.5px; }
    .bl-value { font-size: 11.5px; }
}

/* ---------- Lịch tháng ---------- */
.cal-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px; margin-bottom: 14px; font-size: 16px;
}
.cal-head-right { display: flex; gap: 8px; align-items: center; }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-dow {
    text-align: center; font-size: 11px; color: var(--muted);
    padding: 2px 0 6px; text-transform: uppercase; letter-spacing: .04em;
}
.cal-day {
    aspect-ratio: 1 / 1;
    display: flex; flex-direction: column; align-items: center;
    padding: 5px 2px 6px;
    background: var(--panel-2); border: 1px solid transparent;
    border-radius: 9px; font-size: 12.5px; color: var(--text); text-decoration: none;
}
a.cal-day:hover { border-color: var(--primary); }
.cal-day.empty { background: transparent }
.cal-day.quiet { background: var(--bg); color: var(--muted) }
.cal-day.today { border-color: var(--primary); font-weight: 700 }
.cal-day.sel   { background: var(--primary); color: #fff; border-color: var(--primary) }
.cal-num { line-height: 1.3 }

.cal-dots { display: flex; gap: 3px; align-items: center; margin-top: auto; flex-wrap: wrap; justify-content: center }
.dot { width: 6px; height: 6px; border-radius: 50%; display: block }
.dot-red   { background: #f87171 }
.dot-amber { background: #fbbf24 }
.dot-green { background: #34d399 }
.dot-blue  { background: #60a5fa }
.dot-gray  { background: #94a3b8 }
.cal-more { font-size: 9px; color: var(--muted); font-weight: 700 }
.cal-day.sel .cal-more { color: #e0e7ff }

.cal-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 14px; font-size: 12.5px; color: var(--muted) }
.cal-legend span { display: inline-flex; align-items: center; gap: 6px }

.day-detail { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px }
.day-detail h3 { font-size: 15px; margin-bottom: 10px }
.day-list { list-style: none; margin: 0; padding: 0 }
.day-list li {
    display: flex; gap: 10px; align-items: baseline;
    padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px;
}
.day-list li:last-child { border-bottom: none }
.day-list .dl-meta { margin-left: auto; color: var(--muted); font-size: 12.5px; white-space: nowrap }

@media (max-width: 400px) {
    .cal-grid { gap: 3px }
    .cal-day { font-size: 11.5px; padding: 4px 1px 5px }
    .dot { width: 5px; height: 5px }
}

/* ---------- Login ---------- */
.login-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh;
}
.login-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 36px 32px;
    width: 100%; max-width: 380px;
    text-align: center;
}
.login-logo { font-size: 40px; margin-bottom: 8px; }
.login-card h1 { margin-bottom: 16px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.login-card button[type=submit] {
    background: var(--primary); color: #fff; border: none;
    border-radius: 8px; padding: 11px; font-size: 15px; cursor: pointer;
}
.login-card button[type=submit]:hover { background: var(--primary-hover); }
.otp-input { text-align: center; font-size: 24px; letter-spacing: 12px; }
.resend-form { margin-top: 4px !important; }

.alert { border-radius: 8px; padding: 10px 14px; font-size: 13px; text-align: left; }
.alert-info  { background: #1e3a5f; color: #93c5fd; }
.alert-error { background: #5f1212; color: #fca5a5; }

/* ---------- App Chạy bộ: lịch chuỗi tuần ---------- */
/* Giới hạn bề rộng: ô ngày dùng aspect-ratio 1/1 nên nếu để giãn hết panel trên
   desktop thì mỗi ô thành hình tròn ~136px, to lố. 460px cho ô cỡ ~55px. */
.run-cal-wrap { max-width: 460px; margin: 0 auto; }
.run-cal {
    display: grid;
    grid-template-columns: repeat(7, 1fr) 30px;
    gap: 6px; margin-top: 12px;
}
.run-cal-dow { text-align: center; font-size: 11.5px; color: var(--muted); padding-bottom: 2px; }
.run-cal-day {
    aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center;
    border-radius: 50%; font-size: 13px; background: var(--bg); color: var(--muted);
}
.run-cal-day.run   { background: var(--primary); color: #fff; font-size: 15px; }
.run-cal-day.out   { background: transparent; }
.run-cal-day.today { outline: 2px solid var(--primary); outline-offset: 1px; font-weight: 700; }
.run-cal-rail { display: flex; align-items: center; justify-content: center; }
.run-cal-rail i {
    width: 20px; height: 20px; border-radius: 50%; font-style: normal; font-size: 11px;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg); color: var(--muted);
}
.run-cal-rail i.on { background: #34d399; color: #052e1a; font-weight: 700; }

@media (max-width: 520px) {
    .run-cal { gap: 4px; grid-template-columns: repeat(7, 1fr) 24px; }
    .run-cal-day { font-size: 11.5px; }
    .run-cal-day.run { font-size: 13px; }
}
