/* ============================================================
   Sistema de Mantenimiento Predictivo - Estilos (UI moderna)
   ============================================================ */

:root {
    --primary:        #2563eb;
    --primary-dark:   #1d4ed8;
    --primary-soft:   #eff6ff;
    --bg:             #f1f5f9;
    --surface:        #ffffff;
    --text:           #0f172a;
    --muted:          #64748b;
    --border:         #e2e8f0;

    --normal:         #16a34a;
    --normal-bg:      #dcfce7;
    --alert:          #d97706;
    --alert-bg:       #fef3c7;
    --critical:       #dc2626;
    --critical-bg:    #fee2e2;

    --sidebar-w:      240px;
    --radius:         12px;
    --shadow:         0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
    --shadow-md:      0 4px 16px rgba(15,23,42,.10);
    --font: 'Inter', 'Segoe UI', Tahoma, sans-serif;
}

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

html, body { height: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

.login-wrapper { width: 100%; max-width: 420px; }

.login-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 36px 32px;
    box-shadow: 0 20px 50px rgba(0,0,0,.25);
    animation: pop .35s ease;
}

@keyframes pop { from { opacity:0; transform: translateY(12px) scale(.98);} to {opacity:1; transform: none;} }

.login-brand { text-align: center; margin-bottom: 24px; }
.brand-icon {
    width: 56px; height: 56px; margin: 0 auto 14px;
    display: grid; place-items: center;
    background: var(--primary-soft); color: var(--primary);
    border-radius: 16px;
}
.login-brand h1 { font-size: 20px; font-weight: 800; letter-spacing: -.02em; }
.login-brand p { color: var(--muted); font-size: 13px; margin-top: 6px; }

.login-form { display: flex; flex-direction: column; gap: 16px; margin-top: 8px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; font-weight: 600; color: #334155; }
.form-group input {
    padding: 11px 14px; font-size: 14px;
    border: 1px solid var(--border); border-radius: 10px;
    transition: border .15s, box-shadow .15s; width: 100%;
}
.form-group input:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

.btn-block { width: 100%; justify-content: center; padding: 12px; font-size: 15px; font-weight: 600; }

.login-footer {
    margin-top: 22px; display: flex; align-items: center; justify-content: space-between;
    font-size: 12px; color: var(--muted);
}
.demo-hint { background: #f8fafc; border: 1px dashed var(--border); padding: 5px 9px; border-radius: 8px; }

.alert { padding: 11px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 14px; }
.alert-error { background: var(--critical-bg); color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: var(--normal-bg); color: #166534; border: 1px solid #bbf7d0; margin-bottom: 8px; }

.lang-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.lang-toggle a {
    padding: 5px 11px; font-size: 12px; font-weight: 600;
    color: var(--muted); text-decoration: none; background: #fff;
}
.lang-toggle a.active { background: var(--primary); color: #fff; }

/* ============================================================
   LAYOUT (Sidebar + Main)
   ============================================================ */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: #0f172a;
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
}

.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 20px 22px; color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-icon-sm {
    width: 38px; height: 38px; display: grid; place-items: center;
    background: var(--primary); border-radius: 10px; color: #fff;
}
.brand-text { font-weight: 800; font-size: 17px; line-height: 1; display: flex; flex-direction: column; }
.brand-text small { font-size: 10px; font-weight: 500; color: #94a3b8; letter-spacing: .08em; text-transform: uppercase; }

.sidebar-nav { flex: 1; padding: 14px 12px; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 14px; border-radius: 10px;
    color: #cbd5e1; text-decoration: none; font-size: 14px; font-weight: 500;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.sidebar-footer { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.nav-item.logout:hover { background: rgba(239,68,68,.15); color: #fca5a5; }

.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }

/* Topbar */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 28px;
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 40;
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.topbar-left h2 { font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.topbar-sub { font-size: 12px; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 16px; }

.hamburger { display: none; background: none; border: none; cursor: pointer; color: var(--text); }

.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: grid; place-items: center; font-weight: 700; font-size: 15px;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta strong { font-size: 13px; }
.user-meta small { font-size: 11px; color: var(--muted); }

.content { padding: 24px 28px; display: flex; flex-direction: column; gap: 22px; }

/* ============================================================
   KPI CARDS
   ============================================================ */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 16px;
}
.kpi-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 18px;
    display: flex; align-items: center; gap: 14px;
    box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi-icon { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; }
.kpi-icon.blue   { background: #dbeafe; color: #2563eb; }
.kpi-icon.green  { background: var(--normal-bg); color: var(--normal); }
.kpi-icon.amber  { background: var(--alert-bg); color: var(--alert); }
.kpi-icon.red    { background: var(--critical-bg); color: var(--critical); }
.kpi-icon.purple { background: #ede9fe; color: #7c3aed; }
.kpi-data { display: flex; flex-direction: column; }
.kpi-value { font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.kpi-label { font-size: 12px; color: var(--muted); }

/* ============================================================
   PANELS / CHART
   ============================================================ */
.panel-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.panel {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.panel-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.panel-head h3 { font-size: 15px; font-weight: 700; }
.panel-body { padding: 20px; }

.chart-body { display: flex; align-items: center; gap: 30px; flex-wrap: wrap; justify-content: center; }
.donut {
    --deg-n: calc(var(--normal) / var(--total) * 360deg);
    --deg-a: calc((var(--normal) + var(--alert)) / var(--total) * 360deg);
    width: 160px; height: 160px; border-radius: 50%;
    background: conic-gradient(
        var(--normal, #16a34a) 0 var(--deg-n),
        #d97706 var(--deg-n) var(--deg-a),
        #dc2626 var(--deg-a) 360deg
    );
    position: relative; flex-shrink: 0;
}
.donut::after {
    content: ""; position: absolute; inset: 26px; background: var(--surface); border-radius: 50%;
}
.donut-center {
    position: absolute; inset: 0; display: grid; place-items: center; text-align: center; z-index: 1;
}
.donut-center strong { font-size: 26px; font-weight: 800; }
.donut-center small { font-size: 11px; color: var(--muted); }

.legend { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend b { margin-left: auto; }
.dot { width: 12px; height: 12px; border-radius: 50%; }
.dot.green { background: var(--normal); }
.dot.amber { background: var(--alert); }
.dot.red   { background: var(--critical); }

.health-panel .panel-body { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.gauge {
    width: 130px; height: 130px; border-radius: 50%;
    display: grid; place-items: center;
    background: conic-gradient(currentColor calc(var(--p,0) * 1%), #e2e8f0 0);
}
.gauge.good { color: var(--normal); }
.gauge.warn { color: var(--alert); }
.gauge.bad  { color: var(--critical); }
.gauge-value {
    width: 96px; height: 96px; background: var(--surface); border-radius: 50%;
    display: grid; place-items: center; font-size: 26px; font-weight: 800; color: var(--text);
}
.health-bar { width: 100%; height: 10px; background: #e2e8f0; border-radius: 99px; overflow: hidden; }
.health-fill { height: 100%; background: linear-gradient(90deg, var(--critical), var(--alert), var(--normal)); border-radius: 99px; }

/* ============================================================
   FILTROS
   ============================================================ */
.table-head { flex-wrap: wrap; gap: 12px; }
.filters {
    padding: 14px 20px; display: flex; align-items: center; gap: 12px;
    border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.search-box { position: relative; flex: 1; min-width: 220px; }
.search-box svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-box input { width: 100%; padding: 9px 12px 9px 36px; border: 1px solid var(--border); border-radius: 10px; font-size: 13px; }
.search-box input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
#filter-condition { padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 13px; background: #fff; cursor: pointer; }
.result-info { font-size: 12px; color: var(--muted); margin-left: auto; }

.badge-count {
    background: rgba(255,255,255,.25); color: #fff; border-radius: 99px;
    padding: 1px 8px; font-size: 11px; font-weight: 700; min-width: 20px; text-align: center;
}

/* ============================================================
   TABLA
   ============================================================ */
.table-wrapper { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 1150px; }

thead th {
    background: #f8fafc; padding: 11px 12px; text-align: left;
    font-weight: 600; font-size: 12px; color: var(--muted);
    border-bottom: 1px solid var(--border); white-space: nowrap;
    position: sticky; top: 0; z-index: 5; text-transform: uppercase; letter-spacing: .03em;
}

tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: #f8fafc; }
tbody tr.selected { background: var(--primary-soft) !important; }
.empty-row td { text-align: center; padding: 40px; color: var(--muted); }

.cell-tag { font-weight: 700; font-family: 'Inter', monospace; }
.cell-text { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

/* Borde izquierdo de color por condicion */
tr.status-normal   td:first-child { box-shadow: inset 3px 0 0 var(--normal); }
tr.status-alert    td:first-child { box-shadow: inset 3px 0 0 var(--alert); }
tr.status-critical td:first-child { box-shadow: inset 3px 0 0 var(--critical); }

/* Pills de condicion */
.pill {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-normal   { background: var(--normal-bg);   color: var(--normal); }
.pill-alert    { background: var(--alert-bg);     color: var(--alert); }
.pill-critical { background: var(--critical-bg);  color: var(--critical); }

/* Inputs */
input[type="text"], input[type="date"] {
    padding: 7px 10px; font-size: 13px; border: 1px solid var(--border);
    border-radius: 8px; width: 100%; min-width: 110px; transition: border .15s, box-shadow .15s;
}
input[type="text"]:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
input.ot-input:disabled { background: #f1f5f9; cursor: not-allowed; color: #94a3b8; }
input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }
.col-check { width: 44px; text-align: center; }
.col-ot { min-width: 140px; }
.col-actions { width: 90px; text-align: center; }

/* Botones de accion por fila */
.row-actions { display: flex; gap: 6px; justify-content: center; }
.icon-btn {
    width: 30px; height: 30px; display: grid; place-items: center;
    border: 1px solid var(--border); background: #fff; border-radius: 8px;
    cursor: pointer; color: var(--muted); transition: all .15s;
}
.icon-btn:hover { color: #fff; }
.btn-edit:hover   { background: var(--primary); border-color: var(--primary); }
.btn-delete:hover { background: var(--critical); border-color: var(--critical); }

/* ============================================================
   BOTONES
   ============================================================ */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 18px; font-size: 14px; font-weight: 600;
    border: none; border-radius: 10px; cursor: pointer;
    transition: background .15s, opacity .15s, transform .1s; font-family: inherit;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e2e8f0; color: #334155; }
.btn-secondary:hover { background: #cbd5e1; }
.btn-success { background: var(--normal); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* ============================================================
   TOAST
   ============================================================ */
#toast-container {
    position: fixed; top: 24px; right: 24px; z-index: 1000;
    display: flex; flex-direction: column; gap: 10px;
}
.toast {
    padding: 13px 18px; border-radius: 10px; color: #fff; font-size: 13.5px; font-weight: 500;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18); animation: slideIn .3s ease; max-width: 360px;
    display: flex; align-items: center; gap: 10px;
}
.toast.success { background: #16a34a; }
.toast.error   { background: #dc2626; }
.toast.info    { background: #2563eb; }
@keyframes slideIn { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(15,23,42,0.55); backdrop-filter: blur(2px);
    display: none; justify-content: center; align-items: center; z-index: 200; padding: 20px;
}
.modal-overlay.active { display: flex; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
    background: #fff; border-radius: 16px; width: 520px; max-width: 100%; max-height: 85vh;
    overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    animation: pop .25s ease;
}
.modal-header {
    padding: 18px 22px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 16px;
    display: flex; align-items: center; justify-content: space-between;
}
.modal-close { background: none; border: none; font-size: 26px; line-height: 1; color: var(--muted); cursor: pointer; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 18px 22px; overflow-y: auto; font-size: 14px; line-height: 1.5; }
.modal-body ul { list-style: none; padding: 0; margin-top: 12px; }
.modal-body li {
    padding: 10px 12px; margin-bottom: 6px; border-radius: 8px; background: #f8fafc;
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.modal-lg { width: 680px; }

/* Acciones de cabecera de tabla */
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Formulario nuevo registro */
.form-section {
    font-size: 13px; font-weight: 700; color: var(--primary);
    margin: 4px 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
    text-transform: uppercase; letter-spacing: .04em;
}
.form-section:not(:first-child) { margin-top: 22px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-grid .form-group label { font-size: 12.5px; font-weight: 600; color: #334155; }
.form-grid .form-group label small { font-weight: 400; color: var(--muted); }
.form-grid input, .form-grid select {
    padding: 9px 12px; font-size: 13.5px; border: 1px solid var(--border);
    border-radius: 9px; width: 100%; background: #fff; font-family: inherit;
}
.form-grid input:focus, .form-grid select:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-grid input.invalid, .form-grid select.invalid { border-color: var(--critical); box-shadow: 0 0 0 3px rgba(220,38,38,.12); }
.form-grid input.locked { background: #f1f5f9; color: #64748b; cursor: not-allowed; }
.form-col-2 { grid-column: 1 / -1; }

/* ============================================================
   SPINNER
   ============================================================ */
.spinner {
    display: inline-block; width: 15px; height: 15px;
    border: 2px solid rgba(255,255,255,0.35); border-radius: 50%;
    border-top-color: #fff; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   RESPONSIVE
   ============================================================ */
.sidebar-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 45;
}

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

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); transition: transform .25s ease; }
    .sidebar.open { transform: translateX(0); }
    .sidebar-backdrop.show { display: block; }
    .main { margin-left: 0; }
    .hamburger { display: inline-flex; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .content { padding: 16px; }
    .topbar { padding: 12px 16px; }
    .user-meta { display: none; }
    .result-info { width: 100%; margin-left: 0; }
}

@media (max-width: 460px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .lang-toggle { display: none; }
}
