/* ============================================================
   ApartmentPro — Main Stylesheet v2
   Desktop + Tablet + Mobile responsive
   ============================================================ */

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --sidebar: #0f172a;
  --sidebar-hover: #1e293b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --red: #ef4444;
  --red-bg: #fef2f2;
  --orange: #f97316;
  --orange-bg: #fff7ed;
  --green: #22c55e;
  --green-bg: #f0fdf4;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 16px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 10px 40px rgba(15, 23, 42, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 260px;
  --topbar-h: 64px;
  --transition: 0.25s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: inherit; }

img, svg { display: block; max-width: 100%; }

/* ── Layout ─────────────────────────────────────────────── */

body.app-body {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 300;
  transition: transform var(--transition);
  overflow-y: auto;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 250;
  opacity: 0;
  transition: opacity var(--transition);
}

.sidebar-overlay.active {
  display: block;
  opacity: 1;
}

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  width: calc(100% - var(--sidebar-w));
  display: flex;
  flex-direction: column;
}

/* ── Sidebar ──────────────────────────────────────────── */

.logo {
  padding: 22px 20px;
  border-bottom: 1px solid #1e293b;
  flex-shrink: 0;
}

.logo h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
}

.logo span {
  font-size: 0.72rem;
  color: #94a3b8;
  display: block;
  margin-top: 4px;
  line-height: 1.4;
}

.nav {
  padding: 14px 12px;
  flex: 1;
}

.nav-section-label {
  padding: 14px 16px 6px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
}

a.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  color: #94a3b8;
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
  margin-bottom: 3px;
}

a.nav-item:hover {
  background: var(--sidebar-hover);
  color: #e2e8f0;
}

a.nav-item.active {
  background: var(--primary);
  color: #fff;
}

a.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid #1e293b;
  font-size: 0.72rem;
  color: #64748b;
  flex-shrink: 0;
}

.admin-info {
  margin-bottom: 10px;
  line-height: 1.4;
}

.admin-info .admin-label {
  display: block;
  font-size: 0.68rem;
  color: #64748b;
  margin-bottom: 2px;
}

.admin-info strong {
  color: #e2e8f0;
  font-size: 0.85rem;
}

/* ── Topbar ───────────────────────────────────────────── */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar h2 {
  font-size: 1.15rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
}

.menu-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 8px;
  color: var(--text);
  flex-shrink: 0;
}

.content {
  padding: 24px;
  flex: 1;
}

/* ── Buttons ──────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  font-family: inherit;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.2;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-outline:hover {
  background: var(--bg);
  border-color: #cbd5e1;
}

.btn-danger {
  background: var(--surface);
  color: var(--red);
  border: 1px solid #fecaca;
}

.btn-danger:hover {
  background: var(--red-bg);
}

.btn-sm {
  padding: 7px 12px;
  font-size: 0.78rem;
}

.btn-block {
  width: 100%;
}

/* ── Alerts ───────────────────────────────────────────── */

.alert {
  margin-bottom: 20px;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  line-height: 1.5;
}

.alert-success {
  background: var(--green-bg);
  color: #166534;
  border: 1px solid #bbf7d0;
}

.alert-error {
  background: var(--red-bg);
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* ── Stats ────────────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.stat-card .label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-card .value {
  font-size: 1.85rem;
  font-weight: 700;
  margin: 6px 0 4px;
  line-height: 1.2;
}

.stat-card .value.value-sm {
  font-size: 1.25rem;
}

.stat-card .sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.stat-card.accent-blue { border-left: 4px solid var(--primary); }
.stat-card.accent-red { border-left: 4px solid var(--red); }
.stat-card.accent-orange { border-left: 4px solid var(--orange); }
.stat-card.accent-green { border-left: 4px solid var(--green); }

/* ── Panels ───────────────────────────────────────────── */

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 20px;
}

.panel.panel-narrow {
  max-width: 560px;
}

.panel-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.panel-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
}

.panel-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.panel-body {
  padding: 22px;
}

/* ── Search & Filter ──────────────────────────────────── */

.search-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  width: auto;
  flex: 1;
  justify-content: flex-end;
  min-width: 0;
}

.search-bar .search-input,
.search-bar .filter-select {
  flex: 1;
  min-width: 140px;
}

.search-input {
  padding: 10px 14px 10px 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: inherit;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242 1.156a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E") 12px center no-repeat;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input:focus,
.filter-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.filter-select {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: inherit;
  background: var(--surface);
  cursor: pointer;
}

/* ── Tables (desktop / tablet scroll) ───────────────────── */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  min-width: 640px;
}

/* Bảng danh sách hợp đồng */
.table-contracts {
  min-width: 1180px;
  table-layout: fixed;
}

.table-contracts th,
.table-contracts td {
  padding: 10px 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

.table-contracts .col-code { width: 11%; }
.table-contracts .col-tenant { width: 12%; }
.table-contracts .col-phone { width: 10%; }
.table-contracts .col-date { width: 8%; }
.table-contracts .col-money {
  width: 10%;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.table-contracts th.col-money { text-align: right; }

.table-contracts .col-days,
.table-contracts .col-status {
  width: 9%;
  text-align: center;
}

.table-contracts th.col-days,
.table-contracts th.col-status { text-align: center; }

.table-contracts .col-actions {
  width: 14%;
  overflow: visible;
  text-overflow: clip;
  text-align: right;
}

.table-contracts .col-code strong {
  font-weight: 600;
  color: var(--text);
}

.table-contracts .phone-link {
  white-space: nowrap;
}

.table-contracts tr:hover td { background: #f8fafc; }

.table-contracts td[colspan] {
  overflow: visible;
  text-align: center;
  white-space: normal;
}

@media (min-width: 769px) {
  .search-bar .search-input {
    max-width: 260px;
  }

  .search-bar .filter-select {
    flex: 0 0 auto;
    min-width: 150px;
  }
}

th {
  text-align: left;
  padding: 12px 18px;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

/* ── Badges & Pills ─────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-red { background: var(--red-bg); color: var(--red); }
.badge-orange { background: var(--orange-bg); color: var(--orange); }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-gray { background: #f1f5f9; color: #64748b; }

.days-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 60px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.8rem;
  white-space: nowrap;
}

.days-red { background: var(--red-bg); color: var(--red); }
.days-orange { background: var(--orange-bg); color: var(--orange); }
.days-green { background: var(--green-bg); color: var(--green); }
.days-gray { background: #f1f5f9; color: #64748b; }

.phone-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.phone-link:hover { text-decoration: underline; }

.action-btns {
  display: inline-flex;
  gap: 5px;
  flex-wrap: nowrap;
  justify-content: flex-end;
  align-items: center;
}

.action-btns .btn-sm {
  padding: 5px 9px;
  font-size: 0.72rem;
  flex-shrink: 0;
}

/* ── Mobile Cards ───────────────────────────────────────── */

.card-list {
  display: none;
  padding: 14px;
  gap: 14px;
  flex-direction: column;
}

.contract-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.contract-card .card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.contract-card .apt-code {
  font-weight: 700;
  font-size: 0.95rem;
  word-break: break-word;
}

.contract-card .tenant {
  color: var(--text-muted);
  font-size: 0.84rem;
  margin-top: 2px;
}

.contract-card .card-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 8px;
  font-size: 0.8rem;
  margin: 12px 0;
}

.contract-card .card-meta > div {
  min-width: 0;
}

.contract-card .card-meta span {
  color: var(--text-muted);
  display: block;
  font-size: 0.72rem;
  margin-bottom: 2px;
}

.contract-card .card-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.contract-card .card-actions .btn {
  flex: 1;
  min-width: calc(50% - 4px);
}

/* ── Forms ────────────────────────────────────────────── */

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
  padding: 22px;
}

.form-grid.form-grid-1 {
  grid-template-columns: 1fr;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.form-group.full { grid-column: 1 / -1; }

.form-group label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-family: inherit;
  width: 100%;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: var(--surface);
}

.form-group input:disabled {
  background: var(--bg);
  color: var(--text-muted);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.duration-row {
  display: flex;
  gap: 8px;
}

.duration-row input { flex: 1; }
.duration-row select { width: 110px; flex-shrink: 0; }

.preview-box {
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.preview-item label {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
}

.preview-item .val {
  font-size: 1.05rem;
  font-weight: 700;
}

.form-actions {
  padding: 0 22px 22px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.textarea-lg {
  width: 100%;
  min-height: 140px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.88rem;
  resize: vertical;
  line-height: 1.6;
}

.textarea-lg:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* ── Templates ──────────────────────────────────────────── */

.template-list {
  padding: 14px 22px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.template-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition: border-color 0.2s, background 0.2s;
}

.template-item:hover {
  border-color: var(--primary);
  background: #f8fbff;
}

.template-item h4 {
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.template-item p {
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.6;
  word-break: break-word;
}

.template-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Legend ───────────────────────────────────────────── */

.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 22px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-dot.red { background: var(--red); }
.legend-dot.orange { background: var(--orange); }
.legend-dot.green { background: var(--green); }

/* ── Empty state ──────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ── User menu ────────────────────────────────────────── */

.user-menu { position: relative; }

.user-menu-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 12px 5px 5px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.user-menu-btn:hover,
.user-menu.open .user-menu-btn {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.82rem;
  flex-shrink: 0;
}

.user-name {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chevron {
  color: var(--text-muted);
  transition: transform 0.2s;
  flex-shrink: 0;
}

.user-menu.open .user-chevron { transform: rotate(180deg); }

.user-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  overflow: hidden;
}

.user-menu.open .user-dropdown { display: block; }

.user-dropdown-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.user-dropdown-header strong {
  display: block;
  font-size: 0.88rem;
}

.user-dropdown-header span {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.user-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  font-size: 0.85rem;
  color: var(--text);
  text-decoration: none;
  transition: background 0.15s;
}

.user-dropdown-item:hover { background: var(--bg); }

.user-dropdown-item.logout {
  color: var(--red);
  border-top: 1px solid var(--border);
}

/* ── Login page ───────────────────────────────────────── */

body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #2563eb 100%);
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  text-align: center;
  margin-bottom: 24px;
}

.login-logo h1 {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--primary);
}

.login-logo p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.login-card h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 18px;
  text-align: center;
}

.login-card .form-group { margin-bottom: 14px; }

.login-btn {
  width: 100%;
  margin-top: 6px;
  padding: 12px;
}

.login-error {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid #fecaca;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  margin-bottom: 14px;
}

.login-info {
  background: var(--primary-light);
  color: #1e40af;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  margin-bottom: 14px;
  text-align: center;
  line-height: 1.5;
}

.login-info a {
  color: var(--primary);
  font-weight: 600;
}

/* ── Dashboard Charts ───────────────────────────────────── */

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.chart-panel-wide {
  grid-column: 1 / -1;
}

.chart-wrap {
  position: relative;
  height: 260px;
  padding: 16px 20px 20px;
}

.chart-wrap-bar {
  height: 220px;
}

/* ── Dashboard split: timeline + table ───────────────── */

.dashboard-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.panel-body-timeline {
  max-height: 420px;
  overflow-y: auto;
  padding: 8px 20px 16px !important;
}

.table-wrap-compact table {
  min-width: 0;
}

.table-wrap-compact th,
.table-wrap-compact td {
  padding: 12px 16px;
}

/* ── Timeline ─────────────────────────────────────────── */

.timeline {
  position: relative;
  padding-left: 4px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 19px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--border);
}

.timeline-item {
  display: flex;
  gap: 14px;
  padding: 12px 0;
  position: relative;
}

.timeline-dot {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 700;
  flex-shrink: 0;
  z-index: 1;
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-sm);
}

.timeline-green { background: var(--green-bg); color: var(--green); }
.timeline-blue { background: var(--primary-light); color: var(--primary); }
.timeline-red { background: var(--red-bg); color: var(--red); }
.timeline-orange { background: var(--orange-bg); color: var(--orange); }
.timeline-purple { background: #f3e8ff; color: #9333ea; }
.timeline-gray { background: #f1f5f9; color: #64748b; }

.timeline-content {
  flex: 1;
  min-width: 0;
  padding-top: 2px;
}

.timeline-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.timeline-type {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 4px;
}

.timeline-type-green { background: var(--green-bg); color: var(--green); }
.timeline-type-blue { background: var(--primary-light); color: var(--primary); }
.timeline-type-red { background: var(--red-bg); color: var(--red); }
.timeline-type-orange { background: var(--orange-bg); color: var(--orange); }
.timeline-type-purple { background: #f3e8ff; color: #9333ea; }
.timeline-type-gray { background: #f1f5f9; color: #64748b; }

.timeline-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.timeline-desc {
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.45;
  margin-bottom: 6px;
}

.timeline-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.72rem;
}

.timeline-apt {
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 4px;
  color: var(--primary);
  font-weight: 600;
}

.timeline-admin {
  color: var(--text-muted);
}

.timeline-admin::before {
  content: '• ';
}

/* ── Utility ──────────────────────────────────────────── */

.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.85rem; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.flex-wrap { display: flex; gap: 10px; flex-wrap: wrap; }
.mt-4 { margin-top: 16px; }

.info-line strong { color: var(--text); }

/* ── Responsive: Tablet (≤1024px) ─────────────────────── */

@media (max-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ── Responsive: Mobile (≤768px) ──────────────────────── */

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main {
    margin-left: 0;
    width: 100%;
  }

  .menu-toggle { display: flex; }

  .topbar {
    padding: 0 14px;
    min-height: 56px;
  }

  .topbar h2 {
    font-size: 1rem;
  }

  .content {
    padding: 14px;
  }

  .btn-label-hide {
    display: none;
  }

  .topbar-actions .btn-primary {
    padding: 9px 12px;
  }

  .user-name { display: none; }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .stat-card {
    padding: 16px;
  }

  .stat-card .value {
    font-size: 1.5rem;
  }

  .stat-card .value.value-sm {
    font-size: 1rem;
  }

  .panel-header {
    padding: 14px 16px;
    flex-direction: column;
    align-items: stretch;
  }

  .panel-header h3 {
    font-size: 0.9rem;
  }

  .search-bar {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    flex: none;
  }

  .search-bar .search-input,
  .search-bar .filter-select,
  .search-bar .btn {
    width: 100%;
    min-width: 0;
  }

  .table-wrap { display: none; }
  .card-list { display: flex; }

  .form-grid {
    grid-template-columns: 1fr;
    padding: 16px;
    gap: 14px;
  }

  .preview-box {
    grid-template-columns: 1fr;
  }

  .form-actions {
    padding: 0 16px 16px;
    flex-direction: column-reverse;
  }

  .form-actions .btn {
    width: 100%;
  }

  .legend {
    flex-direction: column;
    gap: 8px;
    padding: 12px 16px;
  }

  .panel-body {
    padding: 16px;
  }

  .template-list {
    padding: 12px 16px 16px;
  }

  .contract-card .card-meta {
    grid-template-columns: 1fr;
  }

  .contract-card .card-actions .btn {
    min-width: calc(33.33% - 6px);
    flex: 1;
  }

  .charts-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-split {
    grid-template-columns: 1fr;
  }

  .chart-wrap {
    height: 220px;
  }

  .panel-body-timeline {
    max-height: 320px;
  }
}

/* ── Responsive: Small phone (≤480px) ─────────────────── */

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    gap: 6px;
  }

  .contract-card .card-actions .btn {
    min-width: calc(50% - 4px);
  }

  .login-card {
    padding: 28px 22px;
  }
}
