:root {
  --bg: #0b0f14;
  --bg-elevated: #0f1419;
  --surface: #151c28;
  --surface-2: #1e2938;
  --border: #2a3548;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-soft: rgba(59, 130, 246, 0.14);
  --accent-glow: rgba(59, 130, 246, 0.35);
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
  --radius-sm: 8px;
  --sidebar-w: 268px;
  --topbar-h: 56px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --transition: 0.22s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
}

body {
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body.nav-open {
  overflow: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* --- Layout --- */
.layout {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 199;
  opacity: 0;
  transition: opacity var(--transition);
  backdrop-filter: blur(2px);
}

body.nav-open .sidebar-overlay {
  display: block;
  opacity: 1;
}

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #161f2e 0%, #121820 100%);
  border-right: 1px solid var(--border);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 200;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  transition: transform var(--transition);
}

.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.brand {
  padding: 1.1rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--accent) 0%, #6366f1 100%);
  color: #fff;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.brand-mark svg { width: 20px; height: 20px; }

.brand-mark--custom {
  background: var(--surface-2);
  box-shadow: none;
  padding: 4px;
}

.brand-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 8px;
  display: block;
}

.brand-preview {
  margin-bottom: 1.25rem;
  padding: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.brand-preview-inner {
  margin: 0;
}

.brand-title {
  display: block;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.03em;
  color: var(--text);
}

.brand-text small {
  display: block;
  font-weight: 400;
  color: var(--muted);
  font-size: 0.68rem;
  margin-top: 0.12rem;
}

.nav {
  padding: 0.5rem 0.65rem 1rem;
  flex: 1;
}

.nav-label {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0.75rem 0.6rem 0.35rem;
  letter-spacing: 0.08em;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.6rem;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  border: 1px solid transparent;
}

.nav-icon {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  transition: background var(--transition), color var(--transition);
}

.nav-icon svg { width: 18px; height: 18px; }

.nav-text {
  line-height: 1.35;
  flex: 1;
  min-width: 0;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  text-decoration: none;
}

.nav-link:hover .nav-icon {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.nav-link.active {
  background: var(--accent-soft);
  color: #fff;
  border-color: rgba(59, 130, 246, 0.25);
  box-shadow: inset 3px 0 0 var(--accent);
}

.nav-link.active .nav-icon {
  background: rgba(59, 130, 246, 0.28);
  color: #93c5fd;
}

.nav-link--logout:hover .nav-icon {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
}

.nav-link--logout:hover { color: #fca5a5; }

.sidebar-foot {
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.sidebar-foot-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

/* --- Main --- */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  min-height: var(--topbar-h);
  padding: 0 1.25rem;
  background: rgba(21, 28, 40, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.topbar-start {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.topbar h1 {
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-user {
  flex-shrink: 0;
}

.topbar-user-name {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0.35rem 0.65rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
}

.menu-toggle {
  display: none;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition);
}

.menu-toggle:hover {
  background: var(--accent-soft);
  border-color: rgba(59, 130, 246, 0.35);
  color: var(--accent-hover);
}

.content {
  padding: 1.25rem 1.5rem 2rem;
  flex: 1;
  width: 100%;
  max-width: 1440px;
}

/* --- Flash --- */
.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  font-size: 0.9rem;
}

.flash-success {
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.35);
  color: #86efac;
}

.flash-error {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

/* --- Stats --- */
.stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  transition: border-color var(--transition), transform var(--transition);
}

.stat:hover {
  border-color: rgba(59, 130, 246, 0.25);
  transform: translateY(-1px);
}

.stat .label {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.3;
}

.stat .value {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 0.35rem;
  letter-spacing: -0.02em;
}

/* --- Cards --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.card-header {
  padding: 0.9rem 1.15rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  background: rgba(0, 0, 0, 0.12);
}

.card-header h2 {
  font-size: 0.95rem;
  font-weight: 600;
}

.card-body { padding: 1.15rem; }
.card-body.flush { padding: 0; }

.card-toolbar {
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--border);
}

/* --- Tables --- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.table-wrap::after {
  content: "";
  position: sticky;
  right: 0;
  top: 0;
  width: 24px;
  height: 100%;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(21, 28, 40, 0.9));
  display: none;
}

/* Bảng cấu hình không cần cuộn ngang */
.table-wrap--static {
  overflow-x: visible;
}

.table-wrap--static::after {
  display: none !important;
}

.form-hint {
  margin: 1rem 0;
  font-size: 0.85rem;
}

/* Nhật ký thông báo — cột nội dung rộng */
.data-table--logs .col-actions {
  width: 120px;
  min-width: 120px;
}


.data-table,
.card-body.flush > table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  table-layout: fixed;
}

/* Bảng trong card-body (form, cấu hình) */
.card-body > table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.card-body > table th,
.card-body > table td {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.card-body > table thead th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(0, 0, 0, 0.2);
}

.card-body > table tbody tr:last-child td {
  border-bottom: none;
}

/* Bảng cấu hình checkbox — cột căn giữa, độ rộng cố định */
.table-config {
  table-layout: fixed;
}

.table-config col.col-milestone { width: 26%; }
.table-config col.col-check { width: 14.8%; }

.table-config .col-milestone {
  width: 26%;
  text-align: left;
  font-weight: 500;
}

.table-config .col-check {
  width: 14.8%;
  text-align: center;
}

.table-config thead .col-check {
  font-size: 0.68rem;
  white-space: nowrap;
}

.table-config td.col-check {
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

.table-config input[type="checkbox"] {
  width: 1.125rem;
  height: 1.125rem;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
  vertical-align: middle;
}

.data-table th,
.data-table td,
.card-body.flush > table th,
.card-body.flush > table td {
  padding: 0.8rem 1rem;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
  word-wrap: break-word;
}

.data-table thead th,
.card-body.flush > table thead th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(0, 0, 0, 0.2);
}

.data-table tbody tr:hover td,
.card-body.flush > table tbody tr:hover td {
  background: rgba(255, 255, 255, 0.025);
}

.data-table tbody tr:last-child td,
.card-body.flush > table tbody tr:last-child td {
  border-bottom: none;
}

.col-narrow { width: 90px; text-align: center; }
.col-mst { width: 110px; }

.col-actions {
  width: 260px;
  min-width: 240px;
  text-align: right !important;
}

.data-table thead th.col-actions {
  text-align: right !important;
}

.cell-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 0.35rem;
}

.cell-actions .btn {
  min-height: 32px;
}

.cell-actions .form-delete {
  display: inline-flex;
  margin: 0;
}

/* Search */
.search-bar {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
}

.search-bar input[type="search"],
.search-bar input[type="text"] {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}

.search-bar input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-bar .btn {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}

/* Badges & Buttons */
.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success { background: rgba(34, 197, 94, 0.2); color: var(--success); }
.badge-warning { background: rgba(245, 158, 11, 0.2); color: var(--warning); }
.badge-danger { background: rgba(239, 68, 68, 0.2); color: var(--danger); }
.badge-info { background: var(--accent-soft); color: var(--accent-hover); }
.badge-muted { background: var(--surface-2); color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.95rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  transition: opacity 0.15s, background 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.98); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { opacity: 0.92; color: #fff; text-decoration: none; }

.btn-ghost {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-ghost:hover { background: rgba(255, 255, 255, 0.06); text-decoration: none; color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; text-decoration: none; }

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  min-height: 32px;
  gap: 0.25rem;
}

.btn-danger .btn-icon {
  display: inline-flex;
  margin-right: 0.15rem;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.form-group { margin-bottom: 0.65rem; }

.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
  font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  min-height: 40px;
}

.form-group textarea {
  min-height: 88px;
  resize: vertical;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-actions {
  margin-top: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.form-actions .btn-block-delete { margin-left: auto; }

.form-delete { display: inline; margin: 0; }

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

/* Login */
.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: radial-gradient(ellipse at top, #1a2744 0%, var(--bg) 55%);
}

.login-box {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.75rem;
  box-shadow: var(--shadow);
}

.login-brand {
  text-align: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.login-brand h1 {
  font-size: 1.2rem;
  margin: 0.75rem 0 0.25rem;
  letter-spacing: 0.02em;
}

.login-tagline {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0;
}

.login-logo {
  max-width: 72px;
  max-height: 72px;
  object-fit: contain;
  margin: 0 auto;
  display: block;
}

.login-brand-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent) 0%, #6366f1 100%);
  color: #fff;
}

.login-brand-icon svg { width: 24px; height: 24px; }

.login-heading {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.login-box > p:not(.login-tagline) { color: var(--muted); font-size: 0.85rem; margin-bottom: 1.5rem; }

/* Timeline & grid */
.timeline { list-style: none; }

.timeline li {
  padding-left: 1.25rem;
  border-left: 2px solid var(--border);
  margin-left: 0.5rem;
  padding-bottom: 1rem;
  position: relative;
}

.timeline li::before {
  content: "";
  width: 10px;
  height: 10px;
  background: var(--accent);
  border-radius: 50%;
  position: absolute;
  left: -6px;
  top: 4px;
}

.timeline .meta { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.chart-row {
  display: flex;
  align-items: flex-end;
  gap: 0.65rem;
  height: 140px;
  padding: 0.5rem 0;
  overflow-x: auto;
}

.chart-bar { flex: 1; min-width: 48px; text-align: center; }

.chart-bar .bar {
  background: linear-gradient(180deg, var(--accent), #1d4ed8);
  border-radius: 4px 4px 0 0;
  margin: 0 auto;
  max-width: 40px;
  min-height: 4px;
}

.chart-bar .lbl { font-size: 0.7rem; color: var(--muted); margin-top: 0.35rem; }

.text-muted { color: var(--muted); }
.text-right { text-align: right; }
.mb-1 { margin-bottom: 1rem; }

td.actions { vertical-align: middle !important; }

/* ========== RESPONSIVE ========== */

/* Tablet */
@media (max-width: 1200px) {
  .stats {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 1023px) {
  .menu-toggle {
    display: inline-flex;
  }

  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow);
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  .main {
    margin-left: 0;
    width: 100%;
  }

  .topbar-user-name {
    max-width: 120px;
    font-size: 0.75rem;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .stat .value {
    font-size: 1.35rem;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .data-table,
  .card-body.flush > table {
    table-layout: auto;
    min-width: 640px;
  }

  .table-config {
    min-width: 100%;
  }

  .table-config .col-check {
    width: 14%;
  }

  .table-wrap::after {
    display: block;
  }

  .col-actions {
    min-width: 220px;
  }

  .form-actions .btn-block-delete {
    margin-left: 0;
    width: 100%;
  }
}

/* Mobile */
@media (max-width: 640px) {
  .content {
    padding: 1rem 0.85rem 1.5rem;
  }

  .topbar {
    padding: 0 0.85rem;
  }

  .topbar h1 {
    font-size: 0.95rem;
  }

  .topbar-user-name {
    display: none;
  }

  .stats {
    grid-template-columns: 1fr;
    gap: 0.65rem;
  }

  .stat {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1rem;
  }

  .stat .value {
    font-size: 1.25rem;
    margin-top: 0;
  }

  .card-header {
    padding: 0.85rem 1rem;
  }

  .card-header h2 {
    font-size: 0.9rem;
    width: 100%;
  }

  .card-header .btn {
    width: 100%;
    justify-content: center;
  }

  .card-toolbar {
    padding: 0.85rem 1rem;
  }

  .search-bar {
    flex-direction: column;
  }

  .search-bar .btn {
    width: 100%;
  }

  .cell-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .col-actions {
    min-width: 200px;
    text-align: left !important;
  }

  .data-table thead th.col-actions {
    text-align: left !important;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-actions .btn {
    flex: 1 1 auto;
    min-width: calc(50% - 0.25rem);
  }

  .header-actions {
    width: 100%;
  }

  .header-actions .btn,
  .header-actions .form-delete .btn {
    flex: 1;
  }

  .login-box {
    padding: 1.5rem 1.25rem;
  }
}

@media (max-width: 380px) {
  .nav-text {
    font-size: 0.82rem;
  }

  .cell-actions .btn {
    padding: 0.35rem 0.5rem;
    font-size: 0.75rem;
  }
}
