:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --text: #1c2330;
  --muted: #6b7280;
  --border: #e3e6eb;
  /* Màu thương hiệu MAT Group */
  --brand: #e30000;        /* đỏ logo */
  --accent: #c8000a;       /* đỏ đậm: nút chính, chart, viền chọn */
  --accent-ink: #8b0a14;   /* đỏ đô: chữ nhấn, hover */
  --accent-soft: #fdeced;
  --accent-rgb: 200, 0, 10;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #b45309;
  --radius: 10px;
  --sidebar: 220px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111419;
    --panel: #1a1e26;
    --panel-2: #20252e;
    --text: #e6e8ec;
    --muted: #9aa1ad;
    --border: #2b313c;
    --accent: #e30000;
    --accent-ink: #ff6b6b;
    --accent-soft: #33161a;
    --accent-rgb: 227, 0, 0;
    --warn: #f59e0b;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
a { color: inherit; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.ico { width: 16px; height: 16px; flex: none; vertical-align: -3px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 7px;
  cursor: pointer;
  font: inherit;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--panel-2); border-color: var(--border); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn.icon { padding: 5px; }
input, select, textarea {
  font: inherit;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 28px; display: flex; flex-direction: column; gap: 14px;
}
.login-card label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.login-card p { margin: 0; }
.login-card .btn { justify-content: center; padding: 9px; }
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-decoration: none; }
.brand-logo { display: block; height: 30px; width: auto; max-width: 100%; object-fit: contain; }
.brand-logo.on-dark { display: none; }
.brand-name {
  font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--accent-ink);
}
@media (prefers-color-scheme: dark) {
  .brand-logo.on-light { display: none; }
  .brand-logo.on-dark { display: block; }
}
.alert { background: #fde8e8; color: var(--danger); padding: 8px 10px; border-radius: 7px; }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); flex: none;
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 4px 8px 18px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent-ink); }
.nav a .ico { width: 18px; height: 18px; }
.sidebar .foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.user-chip {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; font: inherit; color: var(--text);
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); cursor: pointer;
}
.user-chip:hover { border-color: var(--accent); }
.user-text { display: flex; flex-direction: column; min-width: 0; font-size: 12px; }
.user-text b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.avatar {
  flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 13px;
}
.content { flex: 1; min-width: 0; }
.page { max-width: 1200px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-head .spacer { flex: 1; }

.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 18px; box-shadow: var(--shadow);
}
.panel h2 { font-size: 14px; margin: 0 0 14px; display: flex; align-items: center; gap: 8px; }
.panel h2 .spacer { flex: 1; }

/* ---------- Dashboard ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 14px; }
.tile .label { color: var(--muted); font-size: 12px; font-weight: 500; }
.tile .value { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; }
.tile .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.dash-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; margin-bottom: 14px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 13px; align-items: center; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent-ink);
}
.badge.ok { background: rgba(22, 163, 74, .12); color: var(--ok); }
.badge.warn { background: rgba(245, 158, 11, .15); color: var(--warn); }
.quota { margin-top: 14px; }
.quota .row { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 5px; }
.meter { height: 8px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 99px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; min-width: 2px; }
.quota + .quota { margin-top: 12px; }
.note { font-size: 12px; color: var(--muted); margin-top: 12px; line-height: 1.5; }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--border); stroke-width: 1; }
.chart .axis-text { fill: var(--muted); font-size: 10px; }
.chart .bar { fill: var(--accent); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .bar.hover { fill: var(--accent-ink); }
.tip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--text); color: var(--panel); font-size: 12px; padding: 5px 8px; border-radius: 6px;
  white-space: nowrap; transform: translate(-50%, -100%); margin-top: -8px; display: none;
}
.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar .row { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; }
.hbar .row b { font-weight: 600; }
.hbar .track { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

.list { display: flex; flex-direction: column; }
.list .item {
  display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border);
}
.list .item:first-child { border-top: 0; padding-top: 0; }
.list .item img { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; background: var(--panel-2); }
.list .item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.list .item .size { font-size: 12px; color: var(--muted); }

/* ---------- Dropzone ---------- */
.dropzone {
  border: 2px dashed var(--border); border-radius: 14px;
  background: var(--panel);
  padding: 40px 16px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .big { font-size: 17px; font-weight: 600; margin: 8px 0 4px; }
.dropzone .ico { width: 38px; height: 38px; color: var(--accent); }

.queue { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.qitem {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 12px;
}
.qitem img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; background: var(--bg); }
.qitem .info { flex: 1; min-width: 0; }
.qitem .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qitem .url { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qitem .acts { display: flex; gap: 6px; }
.bar-prog { height: 4px; background: var(--border); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.bar-prog > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .1s; }
.qitem.done .bar-prog > i { background: var(--ok); }
.qitem.error .url { color: var(--danger); }

/* ---------- Toolbar & gallery ---------- */
.toolbar { display: flex; align-items: center; gap: 12px; margin: 28px 0 8px; flex-wrap: wrap; }
.toolbar h2 { margin: 0; font-size: 16px; }
.day { margin-top: 22px; }
.day h3 {
  font-size: 14px; margin: 0 0 10px; padding-bottom: 6px;
  border-bottom: 1px solid var(--border); display: flex; gap: 8px; align-items: baseline;
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column;
}
.thumb {
  aspect-ratio: 4 / 3; display: block;
  background: repeating-conic-gradient(var(--panel-2) 0 25%, var(--panel) 0 50%) 0 0 / 16px 16px;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.card .meta { padding: 8px 10px 4px; }
.card .fname { font-size: 12px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .sub { font-size: 11px; color: var(--muted); }
.card .actions { display: flex; gap: 6px; padding: 6px 10px 10px; flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* ---------- Toast & modal ---------- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1c2330; color: #fff; padding: 9px 16px; border-radius: 8px;
  opacity: 0; transition: .2s; pointer-events: none; z-index: 1000;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.8); display: none;
  align-items: center; justify-content: center; padding: 24px; z-index: 900; cursor: zoom-out;
}
.lightbox.show { display: flex; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; }
.dialog-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 800;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.dialog {
  background: var(--panel); border-radius: 14px; width: 100%; max-width: 900px; max-height: 100%;
  display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--border);
}
.dialog-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.dialog-head h3 { margin: 0; font-size: 15px; flex: 1; }
.dialog-body { padding: 16px; overflow: auto; }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.picker-grid button {
  padding: 0; border: 2px solid var(--border); border-radius: 8px; overflow: hidden; cursor: pointer; background: none;
}
.picker-grid button:hover { border-color: var(--accent); }
.picker-grid .thumb { aspect-ratio: 1; }

@media (max-width: 1000px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: sticky; z-index: 20; flex-direction: row; align-items: center;
    padding: 8px 12px; gap: 8px; border-right: 0; border-bottom: 1px solid var(--border);
  }
  .sidebar .brand { padding: 0; }
  .brand-logo { height: 22px; }
  .sidebar .brand-name, .nav a span, .sidebar .foot > a span, .user-text { display: none; }
  .user-chip { padding: 3px; border: 0; background: none; width: auto; }
  .nav { flex-direction: row; }
  .sidebar .foot { margin: 0 0 0 auto; }
  .page { padding: 16px; }
  .grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Multi-user ---------- */
.thumb { position: relative; }
.used-badge {
  position: absolute; top: 6px; right: 6px; display: inline-flex; align-items: center; gap: 3px;
  background: rgba(0, 0, 0, .65); color: #fff; font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 99px;
}
.used-badge .ico { width: 12px; height: 12px; }
.card .who { display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.card .who .ico { width: 12px; height: 12px; }
.filter-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.filter-chip input { accent-color: var(--accent); }

.dialog.dialog-sm { max-width: 440px; }
.form-stack { display: flex; flex-direction: column; gap: 12px; }
.form-stack label { display: flex; flex-direction: column; gap: 5px; font-weight: 500; font-size: 13px; }
.form-stack label.inline { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.form-stack hr { border: 0; border-top: 1px solid var(--border); margin: 2px 0; width: 100%; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr.inactive td { opacity: .5; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data th.num { text-align: right; }
.cell-user { display: flex; align-items: center; gap: 10px; }
.cell-user .avatar { width: 28px; height: 28px; font-size: 12px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.badge.muted { background: var(--panel-2); color: var(--muted); }

.feed { display: flex; flex-direction: column; }
.feed .item { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); font-size: 13px; align-items: baseline; }
.feed .item:first-child { border-top: 0; padding-top: 0; }
.feed .time { color: var(--muted); font-size: 12px; white-space: nowrap; width: 92px; flex: none; }
.feed .text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
