/* ==========================================================================
   HamlyERP shared components  —  static/css/hamly-ui.css
   Load AFTER hamly-theme.css. Every colour here is a theme token, so all of
   these follow the selected theme and light/dark mode automatically.

   .hm-page-header   page title row (rendered by {% pageheader %})
   .hm-card          content panel            .hm-card-head / .hm-card-body
   .hm-table         data table inside a card (wrap in .hm-table-wrap)
   .hm-num           right-aligned tabular figures for money/quantities
   .hm-empty         "nothing here yet" state (partials/empty_state.html)
   .hm-pager         pagination row (partials/pagination.html)
   .hm-badge-*       status pills: ok / warn / bad / info / muted
   ========================================================================== */

/* Figures line up in columns everywhere numbers appear */
table, .hm-num { font-variant-numeric: tabular-nums; }
.hm-num        { text-align: right; white-space: nowrap; }

/* ---------- Page header ---------- */
.hm-page-header {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    margin: 0 0 18px;
}
.hm-ph-text   { flex: 1 1 auto; min-width: 0; }
.hm-ph-title  {
    margin: 0; font-size: 1.25rem; font-weight: 650; line-height: 1.3;
    color: var(--hm-text); display: flex; align-items: center; gap: 8px;
}
.hm-ph-icon   { color: var(--hm-primary); font-size: 1.1rem; }
.hm-ph-sub    { margin: 2px 0 0; font-size: .85rem; color: var(--hm-muted); }
.hm-ph-actions{ display: flex; gap: 8px; flex-wrap: wrap; }
.hm-ph-back {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border-radius: 8px;
    color: var(--hm-muted); border: 1px solid var(--hm-border); text-decoration: none;
}
.hm-ph-back:hover { color: var(--hm-text); background: var(--hm-primary-soft); }

/* ---------- Card ---------- */
.hm-card {
    background: var(--hm-surface); border: 1px solid var(--hm-border);
    border-radius: 12px; margin-bottom: 18px;
}
.hm-card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 12px 16px; border-bottom: 1px solid var(--hm-border);
    font-size: .9rem; font-weight: 600; color: var(--hm-text);
}
.hm-card-body { padding: 16px; }

/* ---------- Table ---------- */
.hm-table-wrap { overflow-x: auto; }
.hm-table      { width: 100%; margin: 0; border-collapse: collapse; font-size: .85rem; color: var(--hm-text); }
.hm-table th {
    text-align: left; font-weight: 600; font-size: .78rem; color: var(--hm-muted);
    padding: 10px 14px; border-bottom: 1px solid var(--hm-border); white-space: nowrap;
    background: var(--hm-app-bg);
}
.hm-table td   { padding: 10px 14px; border-bottom: 1px solid var(--hm-border); vertical-align: middle; }
.hm-table tbody tr:last-child td { border-bottom: 0; }
.hm-table tbody tr:hover         { background: var(--hm-primary-soft); }
.hm-table th.hm-num, .hm-table td.hm-num { text-align: right; }

/* ---------- Empty state ---------- */
.hm-empty      { text-align: center; padding: 40px 20px; color: var(--hm-muted); }
.hm-empty i    { font-size: 2rem; color: var(--hm-primary); opacity: .6; display: block; margin-bottom: 10px; }
.hm-empty h2   { font-size: 1rem; font-weight: 600; color: var(--hm-text); margin: 0 0 4px; }
.hm-empty p    { font-size: .85rem; margin: 0 auto 14px; max-width: 46ch; }

/* ---------- Pagination ---------- */
.hm-pager {
    display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
    padding: 10px 16px; border-top: 1px solid var(--hm-border); font-size: .8rem; color: var(--hm-muted);
}
.hm-pager .pagination { margin: 0; }

/* ---------- Status badges ---------- */
.hm-badge-ok, .hm-badge-warn, .hm-badge-bad, .hm-badge-info, .hm-badge-muted {
    display: inline-block; padding: 2px 9px; border-radius: 999px;
    font-size: .75rem; font-weight: 600; white-space: nowrap;
}
.hm-badge-ok    { background: #dcfce7; color: #166534; }
.hm-badge-warn  { background: #fef3c7; color: #92400e; }
.hm-badge-bad   { background: #fee2e2; color: #991b1b; }
.hm-badge-info  { background: var(--hm-primary-soft); color: var(--hm-primary); }
.hm-badge-muted { background: var(--hm-app-bg); color: var(--hm-muted); border: 1px solid var(--hm-border); }
[data-bs-theme="dark"] .hm-badge-ok   { background: rgba(34,197,94,.15);  color: #86efac; }
[data-bs-theme="dark"] .hm-badge-warn { background: rgba(245,158,11,.15); color: #fcd34d; }
[data-bs-theme="dark"] .hm-badge-bad  { background: rgba(239,68,68,.15);  color: #fca5a5; }

/* ---------- Small screens ---------- */
@media (max-width: 576px) {
    .hm-ph-actions { width: 100%; }
    .hm-ph-actions .btn { flex: 1 1 auto; }
    .hm-table th, .hm-table td { padding: 9px 10px; }
}

/* ---------- Stat tiles (dashboards, report summaries) ---------- */
.hm-stats {
    display: grid; gap: 12px; margin-bottom: 18px;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}
.hm-stat {
    background: var(--hm-surface); border: 1px solid var(--hm-border);
    border-radius: 12px; padding: 14px 16px;
}
.hm-stat-label {
    display: flex; align-items: center; gap: 6px;
    font-size: .78rem; font-weight: 600; color: var(--hm-muted); margin-bottom: 6px;
}
.hm-stat-value {
    font-size: 1.4rem; font-weight: 700; line-height: 1.2; color: var(--hm-text);
    font-variant-numeric: tabular-nums; word-break: break-word;
}
.hm-stat-value.is-warn { color: #b45309; }
.hm-stat-value.is-bad  { color: #b91c1c; }
[data-bs-theme="dark"] .hm-stat-value.is-warn { color: #fbbf24; }
[data-bs-theme="dark"] .hm-stat-value.is-bad  { color: #f87171; }
.hm-section-title { font-size: .95rem; font-weight: 650; color: var(--hm-text); margin: 4px 0 10px; }

/* ---------- Segmented toggle (Month | Year) ---------- */
.hm-segmented {
    display: inline-flex; padding: 3px; gap: 2px; border-radius: 9px;
    background: var(--hm-app-bg); border: 1px solid var(--hm-border);
}
.hm-segmented a {
    padding: 4px 12px; border-radius: 7px; font-size: .8rem; font-weight: 600;
    color: var(--hm-muted); text-decoration: none;
}
.hm-segmented a[aria-current="true"] { background: var(--hm-primary); color: var(--hm-on-primary); }

/* ---------- Quick links ---------- */
.hm-links { display: flex; flex-direction: column; gap: 8px; }
.hm-link {
    display: flex; align-items: center; gap: 10px; padding: 11px 14px;
    background: var(--hm-surface); border: 1px solid var(--hm-border); border-radius: 10px;
    color: var(--hm-text); font-size: .85rem; font-weight: 600; text-decoration: none;
}
.hm-link i     { color: var(--hm-primary); }
.hm-link:hover { background: var(--hm-primary-soft); color: var(--hm-text); }

/* Plain text links inside tables (client names etc.) */
.hm-table a.hm-row-link       { color: var(--hm-text); font-weight: 600; text-decoration: none; }
.hm-table a.hm-row-link:hover { color: var(--hm-primary); text-decoration: underline; }
.hm-table tfoot td { font-weight: 700; background: var(--hm-app-bg); border-top: 1px solid var(--hm-border); }

/* ---------- Ageing heat scale (1–30 … 120+ days) ---------- */
.hm-age { padding: 2px 8px; border-radius: 6px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.hm-age:hover { text-decoration: underline; }
.hm-age-1 { background: #f0fdf4; color: #166534; }
.hm-age-2 { background: #fffbeb; color: #92400e; }
.hm-age-3 { background: #fff7ed; color: #c2410c; }
.hm-age-4 { background: #fef2f2; color: #b91c1c; }
.hm-age-5 { background: #fee2e2; color: #7f1d1d; }
[data-bs-theme="dark"] .hm-age-1 { background: rgba(34,197,94,.14);  color: #86efac; }
[data-bs-theme="dark"] .hm-age-2 { background: rgba(245,158,11,.14); color: #fcd34d; }
[data-bs-theme="dark"] .hm-age-3 { background: rgba(249,115,22,.16); color: #fdba74; }
[data-bs-theme="dark"] .hm-age-4 { background: rgba(239,68,68,.16);  color: #fca5a5; }
[data-bs-theme="dark"] .hm-age-5 { background: rgba(239,68,68,.26);  color: #fecaca; }

/* ---------- Forms on narrow pages ---------- */
.hm-form       { max-width: 640px; }
.hm-form .form-label { font-size: .85rem; font-weight: 600; }
.hm-form-actions { display: flex; gap: 8px; margin-top: 18px; }

/* ---------- Print: reports print as plain black on white ---------- */
@media print {
    .sidebar, .topbar, .hm-no-print, .hm-ph-actions, .hm-pager { display: none !important; }
    .main-content { margin-left: 0 !important; }
    body, .hm-card, .hm-stat, .hm-table th, .hm-table tfoot td { background: #fff !important; color: #000 !important; }
    .hm-card, .hm-stat { border-color: #999 !important; }
    .hm-table th, .hm-table td { border: 1px solid #999 !important; }
    .hm-age { background: none !important; color: #000 !important; }
}

/* ---------- Chat bubble clearance ----------
   The floating chat button sits over the bottom-right corner. Give every page
   room to scroll its last row (pagination, totals, Save buttons) above it.
   Full-height pages (Asset Explorer) handle this inside their own layout. */
.page-content { padding-bottom: 96px; }
.page-content:has(.explorer-wrap) { padding-bottom: 20px; }
