/* ============================================================
   1. Reset & base
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Montserrat:wght@400;500;600;700&display=swap');

:root {
    color-scheme: light;
    font-family: 'Montserrat', Helvetica, sans-serif;
}

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

body {
    background: #f5f9f2;
    color: #1f3d1f;
}

/* ============================================================
   2. Layout primitives
   ============================================================ */

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px 24px 60px;
}

/* ============================================================
   3. Navbar
   ============================================================ */

header {
    position: sticky;
    top: 0;
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
    padding: 1rem 2rem;
    background-color: #fff;
    color: #2E7D32;
    border-bottom: 2px solid #FFB343;
}

header h1,
.logo {
    margin: 0;
    font-size: 1.6rem;
    font-weight: bold;
}

.brand-area {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

img.logo-image {
    width: 42px;
    height: 42px;
    max-width: 100%;
    display: block;
    object-fit: contain;
    border-radius: 8px;
    background: transparent;
}

nav {
    display: flex;
    justify-content: flex-end;
}

nav ul {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    list-style: none;
    gap: 1rem;
    margin: 0;
    padding: 0;
}

nav li {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
}

nav a {
    color: #2E7D32;
    text-decoration: none;
    font-size: 1rem;
    display: inline-flex;
    align-items: center;
}

nav a:hover {
    color: #ddd;
}

nav a[href="/login"] {
    background-color: #2E7D32;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-weight: 700;
}

/* ============================================================
   4. AMEFIP page banner + body
   ============================================================ */

.machineries-page {
    background: #c8e6c9;
    min-height: calc(100vh - 90px);
    padding: 18px 22px 28px;
    display: grid;
    gap: 14px;
}

.mach-banner {
    background: #dcedc8;
    border: 1px solid #c5e1a5;
    border-radius: 4px;
    padding: 18px 24px;
    display: flex;
    align-items: center;
    gap: 22px;
}

.mach-logo {
    flex: 0 0 130px;
    width: 170px;
    height: 150px;
    object-fit: contain;
    object-position: center;
    background: #dcedc8;
    border-radius: 2px;
}

.mach-banner-text {
    flex: 1 1 auto;
}

.mach-agency {
    margin: 0;
    font-weight: 700;
    color: #1f1f1f;
    font-size: 0.95rem;
    line-height: 1.35;
    letter-spacing: 0.01em;
}

.mach-banner h1 {
    margin: 10px 0 4px;
    font-size: 2rem;
    font-weight: 800;
    color: #111;
    letter-spacing: 0.01em;
}

.mach-banner h2 {
    margin: 0;
    font-size: 1.7rem;
    font-weight: 800;
    color: #111;
}

.mach-accent {
    color: #c62828;
}

/* ============================================================
   5. Cards & stat blocks (dashboard summary + AMEFIP stat cards)
   ============================================================ */

.cards {
    display: flex;
    flex-wrap: nowrap;
    gap: 12px;
    margin-top: 24px;
    overflow-x: auto;
}

.card {
    background: white;
    padding: 10px 12px;
    border-bottom: 2px solid #FFB343;
    border-radius: 8px;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.06);
    min-height: 78px;
    max-width: 180px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.card h2 {
    margin-top: 0;
    font-size: 1.1rem;
}

.card p {
    margin-bottom: 0;
    color: #028b2b;
    line-height: 1.6;
}

.card__subtitle {
    display: block;
    margin-top: 4px;
    font-size: 0.78rem;
    font-weight: 600;
    color: #c62828;
}

.mach-stats {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
}

.mach-stat-card {
    background: #ffffff;
    border: 1px solid #b6cba9;
    border-radius: 6px;
    padding: 10px 18px;
    min-width: 220px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}

.mach-stat-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: #555;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.mach-stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: #1f1f1f;
}

/* ============================================================
   6. Chart cards + chart-level filters
   ============================================================ */

.chart-section {
    margin-top: 24px;
}

.chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 16px;
}

/* Stack successive chart grids with the same gap an inline
   `margin-top: 20px` was producing. Keeps the visual rhythm when
   a page has multiple grids back-to-back. */
.chart-grid + .chart-grid {
    margin-top: 20px;
}

.chart-box {
    background: white;
    padding: 20px;
    border-radius: 14px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.06);
}

.chart-box h3 {
    margin-top: 0;
    margin-bottom: 12px;
}

.chart-empty {
    margin: 0;
    padding: 48px 16px;
    text-align: center;
    color: #999;
}

/* Header row inside a chart card: title on the left, checklist
   filter widget on the right. The filter widget is the AMEFIP
   `.mach-filter` component reused so behaviour matches /infra and
   /machineries. */
.chart-box-header {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.chart-box-header h3 {
    margin: 0;
    flex: 0 1 auto;
}

.chart-box-header .mach-filter {
    margin-left: auto;
}

.note {
    margin-top: 12px;
    font-size: 0.95rem;
    color: #45654a;
}

/* ============================================================
   7. Tables (allocation + summary)
   ============================================================ */

.table-wrap {
    overflow-x: auto;
    background: white;
    border-radius: 16px;
    border: 1px solid #d7e7d1;
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.04);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 100%;
}

.data-table th,
.data-table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid #e0f2e9;
}

.data-table th {
    background: #f1f8ee;
    color: #2e7d32;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.82rem;
    letter-spacing: 0.05em;
}

.data-table tbody tr:hover {
    background: #f7fff4;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* Per-table sort strip + buttons. Each `.mfo-sort` group is wired
   independently to its own table + sort state in the page's JS. */
.mfo-sort {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.mfo-sort__label {
    font-weight: 600;
    color: #1f3d1f;
    font-size: 14px;
}

.mfo-sort__btn {
    padding: 6px 14px;
    border: 1px solid #2e7d32;
    background: #ffffff;
    color: #1f3d1f;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s ease, color 0.15s ease;
}

.mfo-sort__btn:hover,
.mfo-sort__btn:focus-visible {
    background: #f1f7ee;
    outline: none;
}

.mfo-sort__btn.is-active {
    background: #2e7d32;
    color: #ffffff;
}

.mfo-sort__btn.is-active:hover {
    background: #256628;
}

.mfo-sort__caret {
    font-size: 11px;
    line-height: 1;
}

/* ============================================================
   8. AMEFIP body, table, chart placeholder
   ============================================================ */

/* `infra` and `machineries` always use `mach-body--no-sidebar`
   which collapses to a single column. The base `.mach-body`
   selector is kept for future variants that may want a sidebar
   alongside the content. */
.mach-body {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

@media (max-width: 900px) {
    .mach-body {
        grid-template-columns: minmax(0, 1fr);
    }
}

.mach-body--no-sidebar {
    grid-template-columns: minmax(0, 1fr);
}

.mach-content {
    display: grid;
    gap: 14px;
}

.mach-content--full {
    width: 100%;
}

.mach-table-wrap {
    background: #ffffff;
    border: 1px solid #b6cba9;
    border-radius: 6px;
    overflow: hidden;
}

.mach-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.86rem;
}

.mach-table thead th {
    background: #ffffff;
    color: #1f1f1f;
    font-weight: 700;
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid #d7e7d1;
    letter-spacing: 0.04em;
    font-size: 0.78rem;
    white-space: nowrap;
}

.mach-table tbody td {
    padding: 8px 12px;
    border-bottom: 1px solid #ecf3e6;
    color: #1f1f1f;
    vertical-align: middle;
}

.mach-table tbody tr:nth-child(even) {
    background: #f6fbf2;
}

.mach-table tbody tr:hover {
    background: #eef7e6;
}

.mach-col-num {
    text-align: center;
    white-space: nowrap;
}

.mach-table-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin: 0 0 10px;
}

.mach-table-header h3 {
    margin: 0;
    color: #1f3d1f;
    font-size: 1rem;
    flex: 1 1 100%;
}

.infra-chart-box {
    background: #ffffff;
    border: 1px solid #b6cba9;
    border-radius: 6px;
    padding: 14px 16px;
}

.infra-chart-box h3 {
    margin: 0 0 12px;
    color: #1f3d1f;
    font-size: 1rem;
}

.mach-chart-empty {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b6b6b;
    font-size: 0.9rem;
    font-style: italic;
}

/* ============================================================
   9. AMEFIP filter widgets (multi-select dropdown)
   ============================================================ */

.mach-filter-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex: 1 1 auto;
}

.mach-filter {
    position: relative;
    display: inline-block;
}

.mach-filter__button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #ffffff;
    border: 1px solid #b6cba9;
    border-radius: 999px;
    color: #1f3d1f;
    font-size: 0.85rem;
    padding: 4px 12px;
    cursor: pointer;
    transition: border-color 120ms ease, background-color 120ms ease;
}

.mach-filter__button:hover,
.mach-filter__button:focus-visible {
    border-color: #2e7d32;
    background: #f1f7ee;
    outline: none;
}

.mach-filter__button[aria-expanded="true"] {
    border-color: #2e7d32;
    background: #f1f7ee;
}

.mach-filter__label {
    color: #6b6b6b;
    font-weight: 600;
    margin-right: 2px;
}

.mach-filter__value {
    color: #1f3d1f;
    font-weight: 600;
}

.mach-filter__value--all {
    color: #2e7d32;
}

.mach-filter__value--partial {
    color: #c62828;
}

.mach-filter__value--none {
    color: #c62828;
    font-style: italic;
}

.mach-filter__caret {
    font-size: 0.7rem;
    line-height: 1;
}

.mach-filter__panel {
    position: absolute;
    left: 0;
    top: calc(100% + 6px);
    min-width: 220px;
    background: #ffffff;
    border: 1px solid #b6cba9;
    border-radius: 6px;
    box-shadow: 0 6px 16px rgba(31, 61, 31, 0.12);
    z-index: 20;
    padding: 8px 0 6px;
}

.mach-filter__actions {
    display: flex;
    gap: 8px;
    padding: 0 12px 6px;
    border-bottom: 1px solid #e3eedd;
    margin-bottom: 4px;
}

.mach-filter__action {
    background: none;
    border: none;
    color: #2e7d32;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0;
}

.mach-filter__action:hover,
.mach-filter__action:focus-visible {
    text-decoration: underline;
    outline: none;
}

.mach-filter__list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 220px;
    overflow-y: auto;
}

.mach-filter__item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    font-size: 0.85rem;
    color: #1f3d1f;
    cursor: pointer;
}

.mach-filter__item:hover {
    background: #f1f7ee;
}

.mach-filter__item input[type="checkbox"] {
    accent-color: #2e7d32;
    cursor: pointer;
}

.mach-filter__empty {
    padding: 8px 12px;
    color: #6b6b6b;
    font-size: 0.82rem;
}