/* ==========================================================================
   1. FONTS & DESIGN TOKENS
   ========================================================================== */

:root {
    /* Brand */
    --primary-blue: #0056b3;
    --primary-blue-hover: #17357d;
    --accent-yellow: #f5dd05;

    /* Neutrals */
    --bg-light: #f8fafc;
    --bg-muted: #f5f6f8;
    --bg-input: #fafafa;
    --text-dark: #1e293b;
    --text-subtle: #94a3b8;
    --border-color: #e2e8f0;
    --border-strong: #ccc;
    --border-soft: #edf2f7;

    /* Focus */
    --focus-border: #4a90e2;
    --focus-shadow: 0 0 0 2px rgba(74, 144, 226, 0.15);

    /* Sizing */
    --row-height: 100px;
    --control-height: 36px;
    --control-radius: 8px;

    /* Shadows */
    --shadow-float: 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-table: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-sticky-col: 2px 0 4px -2px rgba(0, 0, 0, 0.15);
}

/* ==========================================================================
   2. BASE RESET
   ========================================================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-light);
    color: var(--text-dark);
    margin: 0;
    padding: 20px;
    line-height: 1.5;
}

/* ==========================================================================
   3. PAGE WRAPPER & STICKY FILTER
   ========================================================================== */
.page-wrapper {
    padding: 20px;
    background: var(--bg-muted);
}

.filter-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;

    padding: 16px;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 12px;

    position: sticky;
    top: 10px;
    z-index: 100;
    box-shadow: var(--shadow-float);
}

/* ==========================================================================
   4. FILTER GROUPS (legacy .filter-container)
   ========================================================================== */
.filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.filter-group label {
    font-size: 13px;
    font-weight: 600;
    color: #555;
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-group input,
.filter-group select {
    height: 40px;
    padding: 0 12px;
    border-radius: var(--control-radius);
    border: 1px solid var(--border-strong);
    font-size: 14px;
    background: var(--bg-input);
    transition: all 0.2s ease;
}

.filter-group input:focus,
.filter-group select:focus {
    outline: none;
    border-color: var(--focus-border);
    background: #fff;
    box-shadow: var(--focus-shadow);
}

.date-range {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 8px;
}

.date-range span {
    font-size: 13px;
    color: #777;
    text-align: center;
}

/* filter-actions: MERGED dari 2 rule duplikat */
.filter-actions {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    justify-content: flex-end;
    grid-column: 1 / -1;
}

.btn {
    height: 40px;
    padding: 0 16px;
    border-radius: var(--control-radius);
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.btn-search            { background: #2d89ef; color: #fff; }
.btn-search:hover      { background: #1b6fd1; }
.btn-reset             { background: #e5e7eb; color: var(--text-dark); }
.btn-reset:hover       { background: #d1d5db; }

/* ==========================================================================
   5. FILTER EXTRA (.filter-extra) — single-row responsive form
   ========================================================================== */
.filter-extra {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-float);
}

.filter-extra form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 12px;
}

/* Samakan tinggi SEMUA kontrol → baris selalu sejajar */
.filter-extra select,
.filter-extra form > div {
    height: var(--control-height);
}

/* 5 dropdown */
.filter-extra select {
    flex: 1 1 130px;
    min-width: 120px;
    padding: 0 30px 0 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--control-radius);
    background-color: var(--bg-input);
    font-size: 13px;
    color: var(--text-dark);
    cursor: pointer;

    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'></polyline></svg>");
    background-repeat: no-repeat;
    background-position: right 10px center;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.filter-extra select:focus {
    outline: none;
    border-color: var(--focus-border);
    background-color: #fff;
    box-shadow: var(--focus-shadow);
}

/* Search wrapper (no_notifikasi & keyword) */
/* FIX: position: relative DIPINDAH dari inline HTML ke CSS
   supaya icon tidak bergantung pada markup. */
.filter-extra form > div {
    position: relative;
    flex: 1.3 1 160px;
    min-width: 150px;
}

.filter-extra form > div i.fa-search {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-subtle);
    font-size: 14px;
    pointer-events: none;
}

.filter-extra form > div input[type="text"] {
    width: 100%;
    height: var(--control-height);
    padding: 0 12px 0 32px;
    border: 1px solid var(--border-strong);
    border-radius: var(--control-radius);
    background-color: var(--bg-input);
    font-size: 13px;
    color: var(--text-dark);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.filter-extra form > div input[type="text"]:focus {
    outline: none;
    border-color: var(--focus-border);
    background-color: #fff;
    box-shadow: var(--focus-shadow);
}

.filter-extra form > div input[type="text"]::placeholder {
    color: var(--text-subtle);
}

/* Tombol Filter & Reset */
.filter-extra .btn-modern-header {
    flex: 0 0 auto;
    height: var(--control-height);
    padding: 0 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: var(--control-radius);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.filter-extra .btn-modern-header:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.35);
}

.filter-extra .btn-modern-header:active {
    transform: scale(0.97);
}

.filter-extra .btn-header-primary {
    background-color: var(--primary-blue);
    color: #ffffff;
}
.filter-extra .btn-header-primary:hover {
    background-color: var(--primary-blue-hover);
}

.filter-extra .btn-header-secondary {
    background-color: #e5e7eb;
    color: var(--text-dark);
}
.filter-extra .btn-header-secondary:hover {
    background-color: #d1d5db;
}

/* ==========================================================================
   6. TABLE SYSTEM
   ========================================================================== */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    background: #fff;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-table);
    position: relative;
    -webkit-overflow-scrolling: touch;
}

/* FIX: pakai :focus-visible supaya outline tidak muncul saat klik mouse */
.table-responsive:focus-visible {
    outline: 3px solid var(--primary-blue);
    outline-offset: -2px;
}

/* Scrollbar horizontal */
.table-responsive::-webkit-scrollbar       { height: 12px; }
.table-responsive::-webkit-scrollbar-track { background: #f1f3f4; border-radius: 10px; }
.table-responsive::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 10px;
    border: 3px solid #f1f3f4;
}
.table-responsive::-webkit-scrollbar-thumb:hover { background: #64748b; }
.table-responsive {
    scrollbar-width: auto;
    scrollbar-color: #94a3b8 #f1f3f4;
}

.table-modern {
    width: 100%;
    min-width: 1250px;
    border-collapse: collapse;
    table-layout: auto;
}

/* Sticky kolom pertama (# NO) */
.table-modern th:first-child,
.table-modern td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    box-shadow: var(--shadow-sticky-col);
}

/* FIX: beri background eksplisit → sticky tidak transparan */
.table-modern td:first-child {
    background: #fff;
}

.table-modern thead th:first-child {
    z-index: 3;
}

.table-modern thead th {
    background-color: var(--primary-blue) !important;
    color: #ffffff !important;
    padding: 12px 15px;
    text-align: center;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    border-bottom: 3px solid var(--accent-yellow);
}

.table-modern tbody td {
    padding: 12px 15px;
    border: 1px solid var(--border-soft);
    vertical-align: top;
    background: #fff;
}

.text-left-top   { text-align: left; }
.text-center-top { text-align: center; }

.scrollable-column {
    max-height: var(--row-height);
    overflow-y: auto;
    font-size: 13px;
    scrollbar-width: thin;
}

.scrollable-column::-webkit-scrollbar       { width: 3px; }
.scrollable-column::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }

/* ==========================================================================
   7. DOCUMENTATION IMAGES
   ========================================================================== */
.doc-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-start;
}

.img-preview {
    width: 45px;
    height: 45px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    transition: transform 0.2s;
}

.img-preview:hover {
    transform: scale(1.1);
}

/* ==========================================================================
   8. BUTTONS, BADGES & ICON INPUTS
   ========================================================================== */
.btn-modern {
    padding: 8px 16px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary   { background: var(--primary-blue); color: #fff; }
.btn-secondary { background: #64748b; color: #fff; }
.btn-danger    { background: #ef4444; color: #fff; }

.status-badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    display: inline-block;
}

/* Input dengan ikon kiri */
.input-with-icon {
    position: relative;
}

.input-with-icon i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-subtle);
    font-size: 14px;
    pointer-events: none;
}

/* FIX UTAMA: border-box wajib di sini agar width:100% + padding tidak overflow */
.input-with-icon input {
    box-sizing: border-box;
    width: 100%;
    height: 40px;
    padding-left: 36px;
    border: 1px solid var(--border-strong);
    border-radius: var(--control-radius);
    font-size: 14px;
    background: var(--bg-input);
    transition: all 0.2s ease;
}

.input-with-icon input:focus {
    outline: none;
    border-color: var(--focus-border);
    background: #fff;
    box-shadow: var(--focus-shadow);
}

/* ==========================================================================
   9. RESPONSIVE
   ========================================================================== */
@media (max-width: 1100px) {
    .filter-extra select,
    .filter-extra form > div {
        flex-basis: 46%;
    }
}

@media (max-width: 640px) {
    .filter-extra form {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-extra select,
    .filter-extra form > div,
    .filter-extra .btn-modern-header {
        width: 100%;
        flex: 1 1 auto;
    }
}

@media (max-width: 480px) {
    body          { padding: 10px; }
    .page-wrapper { padding: 10px; }

    .filter-container { grid-template-columns: 1fr; }
    .date-range       { grid-template-columns: 1fr; }
    .date-range span  { display: none; }
}

/* ==========================================================================
   10. ACCESSIBILITY — reduced motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    .filter-group input,
    .filter-group select,
    .btn,
    .filter-extra select,
    .filter-extra form > div input[type="text"],
    .filter-extra .btn-modern-header,
    .img-preview,
    .input-with-icon input {
        transition: none !important;
    }
}

/* ==========================================================================
   11. KPI TILES (ringkasan kondisi alat di dashboard) — klik -> rekap_kondisi
   ========================================================================== */
.kpi-wrap {
    margin: 16px 24px 20px;
}

.kpi-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 6px 16px;
    margin-bottom: 12px;
}

.kpi-head h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 800;
    color: var(--text-dark);
}

.kpi-head span {
    font-size: 12.5px;
    color: #64748b;
}

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

.kpi-tile {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 108px;
    padding: 16px 18px;
    border-radius: 14px;
    border: 1px solid transparent;
    text-decoration: none;
    color: var(--text-dark);
    box-shadow: var(--shadow-float);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.kpi-tile:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 22px rgba(0, 0, 0, 0.14);
}

.kpi-tile:focus-visible {
    outline: 3px solid var(--primary-blue);
    outline-offset: 2px;
}

.kpi-num {
    font-family: 'Inter', sans-serif;
    font-size: 34px;
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -0.5px;
}

.kpi-label {
    font-size: 13px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.kpi-label i {
    font-size: 11px;
    transition: transform 0.15s ease;
}

.kpi-tile:hover .kpi-label i {
    transform: translateX(4px);
}

.kpi-sub {
    font-size: 11.5px;
    font-weight: 600;
    opacity: 0.8;
}

/* Warna kartu = warna badge kondisi di tabel (konsisten) */
.tile-danger  { background: #ff5f7a; color: #fff; }
.tile-warning { background: #ffe14d; }
.tile-info    { background: #7cc4ff; }
.tile-success { background: #34d9a0; }

/* Kartu status (putih) */
.kpi-plain {
    background: #fff;
    border-color: var(--border-color);
    min-height: 84px;
}

.kpi-plain .kpi-num {
    font-size: 26px;
}

.kpi-grid-sub {
    margin-bottom: 0;
}

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

@media (max-width: 480px) {
    .kpi-wrap { margin: 12px 10px 16px; }
    .kpi-num  { font-size: 28px; }
}

@media (prefers-reduced-motion: reduce) {
    .kpi-tile,
    .kpi-label i { transition: none !important; }
    .kpi-tile:hover { transform: none; }
}
