:root {
    --navy-900: #0e1a2b;
    --navy-800: #152238;
    --navy-700: #1d3050;
    --navy-border: #2a3c5c;
    --orange: #f5941f;
    --orange-dark: #d97e0a;
    --orange-bg: #fef1de;
    --color-text: #1f2937;
    --color-muted: #6b7280;
    --color-border: #e2e6ec;
    --color-bg: #f3f5f8;
    --color-card: #ffffff;
    --color-red: #b91c1c;
    --color-red-bg: #fde8e8;
    --color-amber: #b45309;
    --color-amber-bg: #fef3c7;
    --color-green: #15803d;
    --color-green-bg: #dcfce7;
    --color-gray: #4b5563;
    --color-gray-bg: #e5e7eb;
    --radius: 10px;
    --sidebar-width: 240px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.45;
}

a { color: var(--orange-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.4rem; margin: 0.2em 0 0.6em; }
h2 { font-size: 1.1rem; margin: 0 0 0.6em; }
h3 { font-size: 1rem; margin: 1em 0 0.4em; }

/* ============ App shell: sidebar + topbar + content ============ */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: var(--navy-800);
    color: #d7deea;
    padding: 1.1rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}

.sidebar-callout {
    background: var(--navy-700);
    border: 1px solid var(--navy-border);
    border-radius: var(--radius);
    padding: 0.9rem;
}
.sidebar-callout h2 { color: #fff; font-size: 0.92rem; margin-bottom: 0.4rem; }
.sidebar-callout p { font-size: 0.82rem; color: #aab6ca; margin: 0 0 0.7rem; }

.sidebar-section-label {
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #7c8aa5;
    padding: 0 0.4rem;
    margin: 0.2rem 0 -0.4rem;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 0.15rem; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.6rem;
    border-radius: 8px;
    color: #c3cce0;
    font-size: 0.9rem;
    border-left: 3px solid transparent;
}
.sidebar-nav a:hover { background: var(--navy-700); text-decoration: none; }
.sidebar-nav a.active {
    background: var(--navy-700);
    color: #fff;
    font-weight: 600;
    border-left-color: var(--orange);
}
.sidebar-nav .nav-icon { font-size: 1.05rem; width: 1.2em; text-align: center; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* --- Topbar --- */
.topbar {
    background: var(--navy-900);
    color: #fff;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.65rem 1.25rem;
    flex-wrap: wrap;
}
.topbar-brand { display: flex; align-items: center; gap: 0.7rem; margin-right: auto; }
.topbar-brand .brand-icon { font-size: 1.5rem; }
.topbar-brand .brand-name { font-weight: 800; font-size: 1.02rem; letter-spacing: 0.01em; }
.topbar-brand .brand-name .accent { color: var(--orange); }
.topbar-brand .brand-company { display: block; font-size: 0.76rem; color: #9fb0c9; font-weight: 400; }
.brand-logo-chip { background: #fff; border-radius: 6px; padding: 4px 10px; display: inline-flex; align-items: center; line-height: 0; }
.brand-logo-chip img { display: block; height: 34px; width: auto; }
.brand-subtitle { font-size: 0.76rem; color: #9fb0c9; }
.print-header .brand-logo-chip { background: none; padding: 0; margin-bottom: 0.3rem; }
.print-header .brand-logo-chip img { height: 44px; }
.topbar-actions { display: flex; align-items: center; gap: 0.6rem; }
.sidebar-toggle { display: none; background: none; border: none; color: #fff; font-size: 1.4rem; cursor: pointer; }

.btn-topbar {
    background: var(--navy-700);
    border: 1px solid var(--navy-border);
    color: #e6ebf3;
    padding: 0.45rem 0.8rem;
    border-radius: 7px;
    font-size: 0.85rem;
}
.btn-topbar:hover { background: var(--navy-border); text-decoration: none; }
.btn-cta {
    background: var(--orange);
    border: 1px solid var(--orange);
    color: #1a1206;
    font-weight: 700;
    padding: 0.5rem 0.95rem;
    border-radius: 7px;
    font-size: 0.87rem;
}
.btn-cta:hover { background: var(--orange-dark); border-color: var(--orange-dark); text-decoration: none; color: #1a1206; }

.content { padding: 1.25rem 1.5rem 3rem; flex: 1; }

/* --- Flash messages --- */
.flash { padding: 0.6rem 0.9rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.95rem; }
.flash-success { background: var(--color-green-bg); color: var(--color-green); }
.flash-error { background: var(--color-red-bg); color: var(--color-red); }
.flash-info { background: var(--color-gray-bg); color: var(--color-gray); }

/* --- Auth (login/setup): no sidebar, standalone centered layout --- */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--navy-900); }
.auth-box {
    width: 100%;
    max-width: 380px;
    margin: 1rem;
    background: var(--color-card);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.auth-box h1 { text-align: center; color: var(--navy-900); }
.auth-box .brand-icon { display: block; text-align: center; font-size: 2.2rem; margin-bottom: 0.3rem; }
.auth-box .brand-logo { display: block; margin: 0 auto 0.8rem; max-width: 220px; height: auto; }

/* --- Page header / actions --- */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 1rem; }
.page-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.subtitle { color: var(--color-muted); margin: -0.5em 0 1em; }
.hint { color: var(--color-muted); font-size: 0.88rem; }

/* --- Hero banner --- */
.hero-banner {
    background: linear-gradient(135deg, var(--navy-900), var(--navy-700));
    color: #fff;
    border-radius: var(--radius);
    padding: 1.4rem 1.6rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.hero-banner h1 { margin: 0.1em 0; color: #fff; }
.hero-banner p { margin: 0; color: #b7c2d6; max-width: 46em; }
.hero-banner .eyebrow { color: var(--orange); font-weight: 700; font-size: 0.78rem; letter-spacing: 0.06em; text-transform: uppercase; }

/* --- Cards --- */
.card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
}
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.card-header-row { display: flex; justify-content: space-between; align-items: center; }

/* --- Forms --- */
.form-card { background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1.25rem; max-width: 900px; }
.form-inline { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; max-width: none; }
.form-row { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.25rem; }
.form-group { margin-bottom: 0.9rem; flex: 1 1 180px; }
.form-narrow { flex: 0 1 140px; }
.form-grow { flex: 2 1 260px; }
.form-checkbox { display: flex; align-items: center; }
.form-checkbox label { display: flex; align-items: center; gap: 0.4rem; font-weight: normal; }
.form-actions { display: flex; gap: 0.6rem; margin-top: 1rem; }

label { display: block; font-weight: 600; font-size: 0.88rem; margin-bottom: 0.3rem; color: var(--color-text); }
input[type=text], input[type=password], input[type=email], input[type=number],
input[type=date], input[type=file], select, textarea {
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    background: #fff;
    color: var(--color-text);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--orange); outline-offset: 1px; }

.search-form { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.search-form input[type=text] { flex: 2 1 220px; }
.search-form select { flex: 1 1 160px; }

/* --- Filter pills --- */
.filter-pills { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filter-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.85rem;
    border-radius: 999px;
    border: 1px solid var(--color-border);
    background: #fff;
    color: var(--color-text);
    font-size: 0.85rem;
}
.filter-pill:hover { border-color: var(--orange); text-decoration: none; }
.filter-pill.active { background: var(--navy-900); border-color: var(--navy-900); color: #fff; font-weight: 600; }

.list-toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 1rem; }
.list-toolbar .filter-pills { margin-bottom: 0; }
.view-toggle { display: inline-flex; border: 1px solid var(--color-border); border-radius: 8px; overflow: hidden; flex: 0 0 auto; }
.view-toggle a { padding: 0.42rem 0.85rem; font-size: 0.85rem; color: var(--color-text); background: #fff; }
.view-toggle a:hover { text-decoration: none; background: #f0f2f5; }
.view-toggle a.active { background: var(--navy-900); color: #fff; }
.view-toggle a.active:hover { background: var(--navy-900); }

/* --- Buttons --- */
.btn {
    display: inline-block;
    padding: 0.5rem 0.9rem;
    border-radius: 6px;
    border: 1px solid var(--color-border);
    background: #fff;
    color: var(--color-text);
    font-size: 0.9rem;
    cursor: pointer;
}
.btn:hover { background: #f0f2f5; text-decoration: none; }
.btn-primary { background: var(--orange); border-color: var(--orange); color: #1a1206; font-weight: 700; }
.btn-primary:hover { background: var(--orange-dark); border-color: var(--orange-dark); color: #1a1206; }
.btn-secondary { background: #fff; }
.btn-danger { color: var(--color-red); border-color: var(--color-red); }
.btn-sm { padding: 0.28rem 0.6rem; font-size: 0.82rem; }
.btn-block { width: 100%; text-align: center; }

/* --- Tables (historial, piezas, tablas auxiliares) --- */
.table-responsive { overflow-x: auto; margin-bottom: 1rem; }
.table { width: 100%; border-collapse: collapse; background: var(--color-card); font-size: 0.92rem; }
.table th, .table td { padding: 0.6rem 0.7rem; border-bottom: 1px solid var(--color-border); text-align: left; vertical-align: middle; }
.table th { color: var(--color-muted); font-weight: 600; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.02em; white-space: nowrap; }
.table td.nowrap, .table td.col-actions, .table td.col-badge { white-space: nowrap; }
.table td.col-actions { text-align: right; }
.table tbody tr:hover { background: #fafbfa; }
.empty-state { color: var(--color-muted); padding: 1rem 0; white-space: normal; }

/* --- Badges / semaforo (colores semanticos, independientes de la marca) --- */
.badge { display: inline-block; padding: 0.2rem 0.55rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; }
.badge-red { background: var(--color-red-bg); color: var(--color-red); }
.badge-orange { background: var(--color-amber-bg); color: var(--color-amber); }
.badge-green { background: var(--color-green-bg); color: var(--color-green); }
.badge-gray { background: var(--color-gray-bg); color: var(--color-gray); }

/* --- Progress bar (horas restantes hasta el proximo mantenimiento) --- */
.progress-track { background: var(--color-gray-bg); border-radius: 999px; height: 6px; overflow: hidden; margin-top: 0.3rem; }
.progress-fill { height: 100%; border-radius: 999px; }
.progress-fill.pf-red { background: var(--color-red); }
.progress-fill.pf-orange { background: var(--color-amber); }
.progress-fill.pf-green { background: var(--color-green); }
.progress-fill.pf-gray { background: var(--color-gray); }

/* --- Stat cards (dashboard) --- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0.9rem; margin-bottom: 1.5rem; }
.stat-card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    color: var(--color-text);
}
.stat-card:hover { text-decoration: none; box-shadow: 0 4px 14px rgba(15,27,43,0.08); }
.stat-card-top { display: flex; align-items: center; justify-content: space-between; }
.stat-icon { font-size: 1.3rem; }
.stat-red { border-left: 4px solid var(--color-red); }
.stat-orange { border-left: 4px solid var(--color-amber); }
.stat-green { border-left: 4px solid var(--color-green); }
.stat-gray { border-left: 4px solid var(--color-gray); }
.stat-red .stat-icon { color: var(--color-red); }
.stat-orange .stat-icon { color: var(--color-amber); }
.stat-green .stat-icon { color: var(--color-green); }
.stat-gray .stat-icon { color: var(--color-gray); }
.stat-number { font-size: 1.7rem; font-weight: 800; color: var(--navy-900); }
.stat-label { color: var(--color-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-sub { font-size: 0.78rem; color: var(--color-muted); }

/* --- Maquinaria: cuadricula de tarjetas --- */
.machine-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.machine-card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.machine-card-top { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.machine-code {
    background: var(--navy-900);
    color: #fff;
    font-weight: 700;
    font-size: 0.78rem;
    padding: 0.15rem 0.5rem;
    border-radius: 5px;
}
.machine-category { color: var(--color-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.02em; }
.machine-card-top .badge { margin-left: auto; }
.machine-title { font-weight: 700; font-size: 0.98rem; margin: 0; }
.machine-meta { font-size: 0.82rem; color: var(--color-muted); }
.machine-metrics {
    background: var(--navy-900);
    color: #fff;
    border-radius: 8px;
    padding: 0.6rem 0.7rem;
    font-size: 0.82rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.machine-metrics .metric-row { display: flex; justify-content: space-between; gap: 0.5rem; }
.machine-metrics .metric-label { color: #9fb0c9; }
.machine-metrics .metric-value { font-weight: 700; }
.machine-card-actions { display: flex; gap: 0.4rem; margin-top: auto; flex-wrap: wrap; }
.machine-card-actions .btn { flex: 1 1 auto; text-align: center; }

/* --- Definition lists (ficha de maquina) --- */
.def-list { display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 0.8rem; margin: 0; }
.def-list dt { color: var(--color-muted); font-size: 0.85rem; }
.def-list dd { margin: 0; }

.app-footer { text-align: center; color: var(--color-muted); font-size: 0.82rem; padding: 2rem 0 1rem; }

/* --- Responsive --- */
@media (max-width: 900px) {
    .sidebar-toggle { display: block; }
    .sidebar {
        position: fixed;
        z-index: 40;
        top: 0; bottom: 0; left: 0;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 4px 0 16px rgba(0,0,0,0.25);
    }
    .sidebar.open { transform: translateX(0); }
    .content { padding: 1rem; }
    .topbar { padding: 0.6rem 0.9rem; }
    .form-inline { flex-direction: column; align-items: stretch; }
}

/* --- Impresion / Descargar como PDF (usa el dialogo de impresion del navegador) --- */
.print-header { display: none; }

@media print {
    .sidebar, .topbar, .list-toolbar, .search-form, .page-actions,
    .machine-card-actions, .form-actions, .app-footer, .flash,
    .sidebar-toggle, .col-actions, .btn-print, .btn-cta, .no-print { display: none !important; }

    .print-header {
        display: block;
        margin-bottom: 1rem;
        padding-bottom: 0.5rem;
        border-bottom: 2px solid #000;
    }
    .print-header .print-company { font-weight: 700; font-size: 1.15rem; }
    .print-header .print-meta { font-size: 0.85rem; color: #333; }

    body, .content { background: #fff !important; margin: 0 !important; padding: 0 !important; }
    .app-shell, .app-main { display: block !important; }
    .content { padding: 0.5cm !important; }

    .card, .machine-card, .stat-card, .form-card, .hero-banner {
        border: 1px solid #999 !important;
        box-shadow: none !important;
        break-inside: avoid;
        background: #fff !important;
        color: #000 !important;
    }
    .hero-banner p, .hero-banner .eyebrow { color: #333 !important; }
    .machine-metrics {
        background: #fff !important;
        color: #000 !important;
        border: 1px solid #999;
    }
    .machine-metrics .metric-label { color: #444 !important; }
    .badge { border: 1px solid #999; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .table th, .table td, a { color: #000 !important; }
    a { text-decoration: none !important; }
    .table tr { break-inside: avoid; }
    .machine-grid { display: block !important; }
    .machine-grid .machine-card { margin-bottom: 0.6cm; }
    .stat-red, .stat-orange, .stat-green, .stat-gray { border-left-width: 4px !important; }
}
