/* YMTP MES - giao diện chung. Màu báo cáo theo BCSX: teal (sản xuất), xanh lá (tiêu hao), xanh dương (kế hoạch). */
:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #1d2939;
  --muted: #667085;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --primary: #0b7a83;
  --primary-600: #09656c;
  --primary-50: #e7f5f6;
  --green: #2e7d32;
  --blue: #1565c0;
  --ok: #067647;
  --ok-bg: #ecfdf3;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --danger: #c4320a;
  --danger-bg: #fef3f2;
  --info-bg: #eff8ff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --sidebar: 236px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.hidden { display: none !important; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* ---------------- Layout ---------------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); background: #0f2a2d; color: #d6e4e5; flex-shrink: 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 9px; background: var(--primary); display: grid; place-items: center;
  font-weight: 800; font-size: 13px; letter-spacing: .5px; color: #fff; flex-shrink: 0;
}
.brand-name { font-weight: 700; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 11px; color: #9fb7b9; }
.nav { padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: #7f9a9c; padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: #d6e4e5;
  font-weight: 500; text-decoration: none;
}
.nav a:hover { background: rgba(255, 255, 255, .07); }
.nav a.active { background: var(--primary); color: #fff; }
.nav a svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav .badge { margin-left: auto; background: var(--danger); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; font-weight: 700; line-height: 18px; }
.sidebar-foot { padding: 12px 18px 16px; font-size: 11px; color: #7f9a9c; border-top: 1px solid rgba(255, 255, 255, .08); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center;
  gap: 10px; padding: 0 20px; position: sticky; top: 0; z-index: 30;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-btn { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 10px; font-size: 12px; background: var(--surface-2); white-space: nowrap;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: #98a2b3; }
.dot.on { background: #12b76a; box-shadow: 0 0 0 3px rgba(18, 183, 106, .18); }
.dot.off { background: #f04438; box-shadow: 0 0 0 3px rgba(240, 68, 56, .18); }
.user-menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: 8px; border: 0; background: none; cursor: pointer; padding: 6px 8px; border-radius: 8px; }
.user-btn:hover { background: var(--surface-2); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary-50); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); min-width: 220px; padding: 6px; z-index: 50;
}
.dropdown button { display: flex; width: 100%; gap: 8px; align-items: center; border: 0; background: none; padding: 9px 10px; border-radius: 6px; cursor: pointer; text-align: left; }
.dropdown button:hover { background: var(--surface-2); }
.dropdown .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }

.content { padding: 20px; max-width: 1600px; width: 100%; margin: 0 auto; }
.backdrop { display: none; }

@media (max-width: 960px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 35; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 0 12px; }
  .topbar .hide-sm { display: none; }
  .content { padding: 12px; }
}

/* ---------------- Controls ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); border-radius: 8px; padding: 8px 14px; font-weight: 600;
  cursor: pointer; min-height: 38px; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #a3290a; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: rgba(0, 0, 0, .05); }
.btn-on-color { background: rgba(255, 255, 255, .16); border-color: rgba(255, 255, 255, .35); color: #fff; }
.btn-on-color:hover { background: rgba(255, 255, 255, .26); }
.btn-sm { padding: 5px 10px; min-height: 30px; font-size: 13px; }
.btn-icon { padding: 6px; min-height: 32px; min-width: 32px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.input, .select, .textarea {
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px; background: var(--surface);
  min-height: 38px; width: 100%;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(11, 122, 131, .15); }
.input.num-input { text-align: right; font-variant-numeric: tabular-nums; }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-2); color: #475467; cursor: not-allowed; }
.input.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(196, 50, 10, .12); }
.textarea { min-height: 72px; resize: vertical; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: 12px; font-weight: 600; color: #344054; }
.field .hint { font-size: 11px; color: var(--muted); }
.field .hint.ok { color: var(--ok); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px 14px; }
.form-grid.wide { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }

.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 7px 14px; cursor: pointer; font-weight: 600; color: var(--muted); min-height: 36px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active { background: var(--primary); color: #fff; }
.on-color .seg { background: rgba(255, 255, 255, .14); border-color: rgba(255, 255, 255, .35); }
.on-color .seg button { color: #fff; }
.on-color .seg button.active { background: #fff; color: var(--primary); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; margin-bottom: 16px; }
.tabs button {
  border: 0; background: none; padding: 10px 14px; cursor: pointer; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center;
}
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs .tab-dot { width: 7px; height: 7px; border-radius: 50%; background: #d0d5dd; }
.tabs .tab-dot.filled { background: #12b76a; }
.tabs .tab-dot.dirty { background: #f79009; }

/* ---------------- Cards & report blocks ---------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 16px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 15px; }
.section-title { font-size: 16px; font-weight: 750; color: var(--primary); margin: 6px 0 10px; text-transform: uppercase; letter-spacing: .2px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.section-title.green { color: var(--green); }
.section-title.blue { color: var(--blue); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3-2 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; }
@media (max-width: 1100px) { .grid-2, .grid-3-2 { grid-template-columns: minmax(0, 1fr); } }

.report-bar {
  border-radius: var(--radius); padding: 14px 18px; color: #fff; display: flex; align-items: center; gap: 12px;
  flex-wrap: wrap; margin-bottom: 16px; box-shadow: var(--shadow);
}
.report-bar h2 { margin: 0; font-size: 22px; font-weight: 750; letter-spacing: .2px; margin-right: auto; }
.report-bar.teal { background: linear-gradient(120deg, #0b7a83, #0d8f99); }
.report-bar.green { background: linear-gradient(120deg, #2e7d32, #388e3c); }
.report-bar.blue { background: linear-gradient(120deg, #1565c0, #1976d2); }
.report-bar .filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.report-bar .select, .report-bar .input { background: rgba(255, 255, 255, .96); border-color: transparent; min-width: 120px; width: auto; color: var(--text); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); text-align: center; }
.kpi .label { color: #2b6cb0; font-size: 13px; }
.kpi .value { font-size: 30px; font-weight: 650; color: #1f4e9c; line-height: 1.2; margin: 4px 0; font-variant-numeric: tabular-nums; }
.kpi .value small { font-size: 14px; color: var(--muted); font-weight: 500; }
.kpi .delta { font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.kpi .delta svg { width: 14px; height: 14px; }
.kpi .delta.good { color: var(--ok); }
.kpi .delta.bad { color: var(--danger); }
.kpi .delta.flat { color: var(--muted); }

.chart-card { padding: 12px 14px; }
.chart-box { position: relative; height: 300px; }
.chart-box.short { height: 240px; }
.chart-title { font-weight: 650; font-size: 13px; color: #344054; margin-bottom: 6px; }

/* ---------------- Tables ---------------- */
.table-wrap { overflow: auto; max-height: 460px; border-radius: 0 0 var(--radius) var(--radius); }
.table-wrap.tall { max-height: 640px; }
.table-wrap.free { max-height: none; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.data th {
  position: sticky; top: 0; z-index: 2; background: #eef1f4; color: #344054; font-weight: 650; font-size: 12px;
  padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border-strong); vertical-align: bottom; white-space: nowrap;
}
table.data th.num { text-align: right; }
table.data td { padding: 7px 10px; border-bottom: 1px solid #eef0f3; vertical-align: top; white-space: nowrap; }
table.data tbody tr:hover td { background-color: rgba(11, 122, 131, .04); }
table.data tbody tr.clickable { cursor: pointer; }
table.data tfoot td {
  position: sticky; bottom: 0; background: #fff; font-weight: 700; border-top: 2px solid var(--border-strong); z-index: 1;
}
table.data td.heat { color: #101828; }
table.data td.wrap { white-space: pre-wrap; min-width: 160px; max-width: 320px; }
table.data .sub { display: block; font-size: 11px; color: var(--muted); font-weight: 400; }
.table-empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.th-red th { background: #e53935; color: #fff; }

/* ---------------- Status, badges, misc ---------------- */
.select.status-select { min-width: 150px; min-height: 32px; padding: 4px 8px; }
.pill { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.danger { background: var(--danger-bg); color: var(--danger); }
.pill.info { background: var(--info-bg); color: #175cd3; }
.pill.neutral { background: #f2f4f7; color: #475467; }
.progress { height: 8px; background: #eef1f4; border-radius: 99px; overflow: hidden; min-width: 80px; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.callout { border-radius: var(--radius); padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; border: 1px solid; }
.callout svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.callout.info { background: var(--info-bg); border-color: #b2ddff; color: #194185; }
.callout.warn { background: var(--warn-bg); border-color: #fedf89; color: #93370d; }
.callout.danger { background: var(--danger-bg); border-color: #fecdca; color: #912018; }
.callout.ok { background: var(--ok-bg); border-color: #abefc6; color: #05603a; }
.empty-state { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty-state svg { width: 36px; height: 36px; color: #98a2b3; margin-bottom: 8px; }
.empty-state .title { font-weight: 650; color: var(--text); margin-bottom: 4px; }

.skeleton { background: linear-gradient(90deg, #eef1f4 25%, #f7f8fa 37%, #eef1f4 63%); background-size: 400% 100%; animation: shimmer 1.2s ease infinite; border-radius: 8px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Thẻ giá trị realtime */
.live-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.live { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); border-left: 4px solid #d0d5dd; }
.live.normal { border-left-color: #12b76a; }
.live.warning { border-left-color: #f79009; background: #fffcf5; }
.live.critical { border-left-color: #f04438; background: #fffbfa; }
.live .label { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }
.live .value { font-size: 28px; font-weight: 700; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.live .value small { font-size: 13px; color: var(--muted); font-weight: 500; margin-left: 3px; }
.live .meta { font-size: 11px; color: var(--muted); }

/* Lịch tình trạng nhập liệu */
.status-grid { display: grid; gap: 4px; overflow-x: auto; }
.status-grid .cell { border-radius: 6px; padding: 4px 6px; font-size: 11px; text-align: center; border: 1px solid var(--border); background: var(--surface); cursor: pointer; white-space: nowrap; }
.status-grid .cell.done { background: var(--ok-bg); border-color: #abefc6; color: var(--ok); }
.status-grid .cell.partial { background: var(--warn-bg); border-color: #fedf89; color: var(--warn); }
.status-grid .cell.missing { background: #fff; color: #98a2b3; }
.status-grid .cell.current { outline: 2px solid var(--primary); }
.status-grid .head { font-size: 11px; color: var(--muted); text-align: center; padding: 2px; }

/* Thanh lưu cố định cuối form nhập liệu */
.save-bar {
  position: sticky; bottom: 0; background: rgba(255, 255, 255, .96); border-top: 1px solid var(--border);
  padding: 10px 16px; display: flex; gap: 10px; align-items: center; z-index: 5; border-radius: 0 0 var(--radius) var(--radius);
}
.summary-strip { display: flex; gap: 10px; flex-wrap: wrap; }
.summary-strip .item { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; min-width: 120px; }
.summary-strip .item .k { font-size: 11px; color: var(--muted); }
.summary-strip .item .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------------- Modal & toast ---------------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 480px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modal.wide { max-width: 760px; }
.modal-head { padding: 16px 20px 8px; display: flex; align-items: center; gap: 10px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 8px 20px 16px; overflow-y: auto; }
.modal-foot { padding: 12px 20px 16px; display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--border); }
.modal .error { color: var(--danger); background: var(--danger-bg); border-radius: 8px; padding: 8px 10px; margin-bottom: 10px; font-size: 13px; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: calc(100vw - 32px); }
.toast { background: #101828; color: #fff; padding: 11px 14px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13px; display: flex; gap: 8px; align-items: center; min-width: 240px; animation: toast-in .18s ease-out; }
.toast.ok { background: #054f31; }
.toast.error { background: #7a271a; }
.toast svg { width: 16px; height: 16px; flex-shrink: 0; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------------- Login ---------------- */
.login-page { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; background: var(--surface); }
.login-hero {
  background: linear-gradient(150deg, #0b4f55, #0b7a83 55%, #12a2ad); color: #fff; padding: 48px; display: flex;
  flex-direction: column; justify-content: space-between;
}
.login-hero h1 { font-size: 34px; margin: 0 0 12px; line-height: 1.2; }
.login-hero p { opacity: .9; font-size: 15px; max-width: 460px; }
.login-hero ul { list-style: none; padding: 0; margin: 24px 0 0; display: grid; gap: 10px; }
.login-hero li { display: flex; gap: 10px; align-items: center; opacity: .95; }
.login-hero li svg { width: 18px; height: 18px; }
.login-form-wrap { display: grid; place-items: center; padding: 32px 20px; background: var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 32px; }
.login-card h2 { margin: 0 0 4px; font-size: 22px; }
.login-card .stack { gap: 14px; margin-top: 22px; }
.login-card .btn { width: 100%; min-height: 44px; font-size: 15px; }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 44px; }
.pw-wrap button { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
@media (max-width: 860px) { .login-page { grid-template-columns: 1fr; } .login-hero { display: none; } }

@media print {
  .sidebar, .topbar, .report-bar .filters, .btn { display: none !important; }
  .content { padding: 0; }
  .table-wrap { max-height: none; overflow: visible; }
}
