/* =========================================================================
   Tema base — paleta inspirada en corpesca.cl
   ========================================================================= */
:root {
    --color-primary: #00224c;       /* azul marino */
    --color-primary-600: #0a3263;
    --color-primary-700: #001a3a;
    --color-accent: #c2212d;        /* rojo */
    --color-accent-600: #a51b26;
    --color-teal: #009bad;          /* turquesa */
    --color-blue: #0f76bb;
    --color-success: #1dae22;

    --color-bg: #f3f5f8;
    --color-surface: #ffffff;
    --color-border: #e0e4ea;
    --color-text: #1f2a37;
    --color-muted: #6b7280;

    --sidebar-width: 260px;
    --sidebar-collapsed-width: 76px;
    --topbar-height: 68px;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(0, 34, 76, .06);
    --shadow: 0 4px 16px rgba(0, 34, 76, .08);
    --shadow-lg: 0 12px 32px rgba(0, 34, 76, .16);
    --font: "Nunito Sans", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--color-teal); outline-offset: 2px; }

/* ---------- Marca ---------- */
.brand {
    display: inline-flex;
    align-items: center;
    gap: .65rem;
    font-weight: 800;
    font-size: 1.05rem;
    letter-spacing: .01em;
    color: var(--color-primary);
}
.brand-mark { display: inline-flex; width: 38px; height: 38px; flex-shrink: 0; }
.brand-mark svg { width: 100%; height: 100%; }
.brand-light, .sidebar .brand { color: #fff; }

/* ---------- Botones ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .7rem 1.2rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: .95rem;
    transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn-primary { background: var(--color-accent); color: #fff; }
.btn-primary:hover { background: var(--color-accent-600); }
.btn-secondary { background: var(--color-primary); color: #fff; }
.btn-secondary:hover { background: var(--color-primary-600); }
.btn-outline { background: #fff; border-color: var(--color-border); color: var(--color-primary); }
.btn-outline:hover { border-color: var(--color-teal); color: var(--color-teal); }
.btn-block { width: 100%; }

.icon-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--color-muted);
    font-size: 1.1rem;
    transition: background-color .15s, color .15s;
}
.icon-btn:hover { background: var(--color-bg); color: var(--color-primary); }
.badge-dot {
    position: absolute;
    top: 9px;
    right: 10px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-accent);
    box-shadow: 0 0 0 2px #fff;
}

/* ---------- Formularios ---------- */
.form { display: grid; gap: 1.15rem; }
.field { display: grid; gap: .4rem; }
.field label { font-weight: 700; font-size: .9rem; color: var(--color-primary); }
.field-label-row { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.input-icon { position: relative; }
.input-icon > i {
    position: absolute;
    left: .9rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-muted);
    pointer-events: none;
}
/* Más específico que la regla general de inputs (más abajo) para que no se pise el padding */
.field .input-icon > input { padding-left: 2.6rem; }
.field .input-icon > input:has(+ .input-action) { padding-right: 2.8rem; }
.input-action {
    position: absolute;
    right: .35rem;
    top: 50%;
    transform: translateY(-50%);
    border: 0;
    background: none;
    padding: .45rem .6rem;
    color: var(--color-muted);
}
.input-action:hover { color: var(--color-primary); }
input[type="email"], input[type="password"], input[type="text"], select, textarea {
    width: 100%;
    padding: .75rem .9rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: #fff;
    font: inherit;
    color: var(--color-text);
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-teal);
    box-shadow: 0 0 0 3px rgba(0, 155, 173, .18);
}
input.is-invalid { border-color: var(--color-accent); }
input.is-invalid:focus { box-shadow: 0 0 0 3px rgba(194, 33, 45, .15); }
.field-error { color: var(--color-accent); font-size: .85rem; }
.checkbox { display: inline-flex; align-items: center; gap: .55rem; font-size: .9rem; color: var(--color-muted); cursor: pointer; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--color-primary); }
.link { color: var(--color-blue); font-weight: 600; font-size: .88rem; }
.link:hover { color: var(--color-teal); text-decoration: underline; }
.link-back { justify-self: center; display: inline-flex; align-items: center; gap: .45rem; }

/* ---------- Alertas ---------- */
.alert {
    display: flex;
    gap: .6rem;
    align-items: flex-start;
    padding: .8rem 1rem;
    margin-bottom: 1.25rem;
    border-radius: var(--radius-sm);
    font-size: .9rem;
    border-left: 4px solid;
}
.alert i { margin-top: .2rem; }
.alert-success { background: #ecfbef; border-color: var(--color-success); color: #146b18; }
.alert-danger { background: #fdecee; border-color: var(--color-accent); color: #8b1720; }

/* =========================================================================
   Layout de acceso
   ========================================================================= */
.auth-shell { display: grid; grid-template-columns: 1.1fr 1fr; min-height: 100vh; }
.auth-hero {
    position: relative;
    overflow: hidden;
    color: #fff;
    background:
        radial-gradient(circle at 20% 15%, rgba(0, 155, 173, .35), transparent 45%),
        linear-gradient(160deg, var(--color-primary) 0%, var(--color-primary-700) 100%);
}
.auth-hero-inner {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    padding: 3rem 3.5rem 12rem;
}
.brand-hero { gap: 1rem; font-size: 2.2rem; }
.brand-hero .brand-mark { width: 72px; height: 72px; }
.auth-waves { position: absolute; left: 0; bottom: 0; width: 100%; height: 45%; }

.auth-panel { display: flex; align-items: center; justify-content: center; padding: 2rem 1.5rem; background: var(--color-surface); }
.auth-card { width: 100%; max-width: 400px; }
.auth-brand-mobile { display: none; margin-bottom: 2rem; }
.auth-title { font-size: 1.75rem; font-weight: 800; color: var(--color-primary); }
.auth-subtitle { color: var(--color-muted); margin: .4rem 0 1.75rem; }

@media (max-width: 900px) {
    .auth-shell { grid-template-columns: 1fr; }
    .auth-hero { display: none; }
    .auth-brand-mobile { display: inline-flex; }
    .auth-panel { align-items: flex-start; padding-top: 3rem; border-top: 4px solid var(--color-accent); }
}

/* =========================================================================
   Layout principal
   ========================================================================= */
.app-shell { display: flex; min-height: 100vh; }

/* ---------- Menú lateral ---------- */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    display: flex;
    flex-direction: column;
    width: var(--sidebar-width);
    background: var(--color-primary);
    color: rgba(255, 255, 255, .8);
    border-right: 3px solid var(--color-accent);
    transition: transform .25s ease, width .25s ease;
}
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topbar-height);
    padding: 0 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.sidebar .brand { min-width: 0; overflow: hidden; }
.sidebar .brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-close { display: none; color: rgba(255, 255, 255, .7); }
.sidebar-collapse { width: 32px; height: 32px; flex-shrink: 0; font-size: .9rem; color: rgba(255, 255, 255, .6); }
.sidebar-close:hover, .sidebar-collapse:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.sidebar-nav { flex: 1; overflow-x: hidden; overflow-y: auto; padding: 1rem .75rem; }
.nav-section {
    margin: 1.25rem .75rem .5rem;
    font-size: .7rem;
    font-weight: 800;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, .45);
}
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: .8rem;
    padding: .65rem .9rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: .93rem;
    transition: background-color .15s, color .15s;
}
.nav-link span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-link i { width: 18px; flex-shrink: 0; color: rgba(255, 255, 255, .55); transition: color .15s; }
.nav-link:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav-link:hover i { color: #fff; }
.nav-link.is-active { background: rgba(0, 155, 173, .18); color: #fff; }
.nav-link.is-active i { color: var(--color-teal); }
.nav-link.is-active::before {
    content: "";
    position: absolute;
    left: -.75rem;
    top: 8px;
    bottom: 8px;
    width: 4px;
    border-radius: 0 3px 3px 0;
    background: var(--color-teal);
}
.sidebar-footer { padding: 1rem 1.5rem; font-size: .75rem; white-space: nowrap; overflow: hidden; color: rgba(255, 255, 255, .4); border-top: 1px solid rgba(255, 255, 255, .08); }
.sidebar-backdrop { display: none; }

/* ---------- Área principal ---------- */
.app-main { flex: 1; min-width: 0; margin-left: var(--sidebar-width); display: flex; flex-direction: column; transition: margin-left .25s ease; }

/* ---------- Menú lateral colapsado (escritorio) ---------- */
@media (min-width: 993px) {
    .sidebar-collapsed .sidebar { width: var(--sidebar-collapsed-width); }
    .sidebar-collapsed .app-main { margin-left: var(--sidebar-collapsed-width); }
    .sidebar-collapsed .sidebar-header { justify-content: center; padding: 0; }
    .sidebar-collapsed .sidebar .brand-name,
    .sidebar-collapsed .sidebar-collapse,
    .sidebar-collapsed .nav-link span,
    .sidebar-collapsed .sidebar-footer-text { display: none; }
    .sidebar-collapsed .nav-section { height: 1px; margin: 1rem .5rem; overflow: hidden; color: transparent; background: rgba(255, 255, 255, .12); }
    .sidebar-collapsed .nav-link { justify-content: center; padding: .7rem 0; }
    .sidebar-collapsed .sidebar-footer { padding: 1rem 0; }
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    height: var(--topbar-height);
    padding: 0 1.75rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.page-title { font-size: 1.2rem; font-weight: 800; color: var(--color-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-subtitle { font-size: .82rem; color: var(--color-muted); }

/* ---------- Usuario ---------- */
.dropdown { position: relative; }
.user-trigger {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .3rem .6rem .3rem .3rem;
    border: 1px solid transparent;
    border-radius: 999px;
    background: none;
    transition: background-color .15s, border-color .15s;
}
.user-trigger:hover, .dropdown.is-open .user-trigger { background: var(--color-bg); border-color: var(--color-border); }
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-teal), var(--color-blue));
    color: #fff;
    font-weight: 800;
    font-size: .85rem;
}
.user-meta { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; text-align: left; }
.user-name { font-weight: 700; font-size: .9rem; color: var(--color-primary); }
.user-role { font-size: .75rem; color: var(--color-muted); }
.user-caret { font-size: .7rem; color: var(--color-muted); transition: transform .15s; }
.dropdown.is-open .user-caret { transform: rotate(180deg); }

.dropdown-menu {
    position: absolute;
    right: 0;
    top: calc(100% + .5rem);
    min-width: 230px;
    padding: .4rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity .15s, transform .15s, visibility .15s;
}
.dropdown.is-open .dropdown-menu { opacity: 1; visibility: visible; transform: none; }
.dropdown-header { display: grid; padding: .6rem .75rem .7rem; font-size: .85rem; }
.dropdown-header strong { color: var(--color-primary); }
.dropdown-header span { color: var(--color-muted); overflow: hidden; text-overflow: ellipsis; }
.dropdown-item {
    display: flex;
    align-items: center;
    gap: .65rem;
    width: 100%;
    padding: .55rem .75rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    font-size: .9rem;
    text-align: left;
    color: var(--color-text);
}
.dropdown-item i { color: var(--color-muted); }
.dropdown-item:hover { background: var(--color-bg); }
.dropdown-item.is-danger, .dropdown-item.is-danger i { color: var(--color-accent); }
.dropdown-divider { margin: .35rem 0; border: 0; border-top: 1px solid var(--color-border); }

/* ---------- Contenido ---------- */
.content { flex: 1; padding: 1.75rem; display: grid; gap: 1.5rem; align-content: start; }
.content > .alert { margin-bottom: 0; }

.grid { display: grid; gap: 1.25rem; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2-1 { grid-template-columns: 2fr 1fr; }

.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; border-bottom: 1px solid var(--color-border); }
.card-title { font-size: 1rem; font-weight: 800; color: var(--color-primary); }
.card-body { padding: 1.25rem; }

.stat { display: flex; align-items: center; gap: 1rem; padding: 1.25rem; }
.stat-icon { display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; border-radius: 12px; font-size: 1.2rem; flex-shrink: 0; }
.stat-label { font-size: .82rem; color: var(--color-muted); }
.stat-value { font-size: 1.5rem; font-weight: 800; color: var(--color-primary); }
.tone-navy { background: rgba(0, 34, 76, .08); color: var(--color-primary); }
.tone-teal { background: rgba(0, 155, 173, .12); color: var(--color-teal); }
.tone-blue { background: rgba(15, 118, 187, .12); color: var(--color-blue); }
.tone-red  { background: rgba(194, 33, 45, .1); color: var(--color-accent); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th, .table td { padding: .35rem .75rem; text-align: left; border-bottom: 1px solid var(--color-border); white-space: nowrap; }
.table th { font-size: .75rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--color-muted); background: var(--color-bg); }
.table tbody tr:last-child td { border-bottom: 0; }
.text-muted { color: var(--color-muted); }

.empty-state { display: grid; justify-items: center; gap: .5rem; padding: 3rem 1rem; color: var(--color-muted); text-align: center; }
.empty-state i { font-size: 2rem; color: var(--color-border); }
.quick-links { display: grid; gap: .6rem; }
.quick-links .btn { justify-content: flex-start; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 992px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar-close { display: inline-flex; }
    .sidebar-collapse { display: none; }
    .app-main { margin-left: 0; }
    body.sidebar-open { overflow: hidden; }
    body.sidebar-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
    body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(0, 26, 58, .45); }
    .grid-2-1 { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
    .topbar { padding: 0 1rem; }
    .content { padding: 1rem; }
    .user-meta, .user-caret { display: none; }
    .user-trigger { padding: .2rem; }
    .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
