/* =====================================================================
   WHours - hoja de estilos (tema oscuro, estética KH Sentinel)
   ===================================================================== */

:root {
    --bg:         #131318;
    --sidebar:    #1a1a21;
    --surface:    #1f1f28;
    --surface-2:  #292933;
    --border:     #32323f;
    --ink:        #e9e9ef;
    --muted:      #8c8c9c;
    --accent:     #e8552d;
    --accent-h:   #cf4720;
    --ok:         #45c463;
    --warn:       #e0a23a;
    --danger:     #ef6a52;
    --radius:     12px;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

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

h1 { font-size: 1.35rem; margin: 0 0 1rem; }

/* --- Marca ----------------------------------------------------------- */

.brand-mark {
    font-size: .72rem;
    letter-spacing: .28em;
    font-weight: 600;
    color: var(--accent);
}

.brand-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--ink);
}

.brand-logo {
    display: block;
    height: 17px;
    width: auto;
}

/* --- Disposición con barra lateral ---------------------------------- */

body.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 234px;
    flex-shrink: 0;
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: .45rem;
    padding: 1.35rem 1.4rem;
}
.brand:hover { text-decoration: none; }

.nav {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    padding: .5rem .7rem;
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .6rem .7rem;
    border-radius: 8px;
    color: var(--muted);
    font-size: .95rem;
    font-weight: 500;
}
.nav-link:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav-link.active { background: rgba(232, 85, 45, .13); color: var(--accent); }
.nav-link svg { flex-shrink: 0; }

.sidebar-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .9rem 1rem;
    border-top: 1px solid var(--border);
}

.sidebar-user {
    font-size: .9rem;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .4rem .7rem;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: .88rem;
    cursor: pointer;
}
.logout-btn:hover { background: var(--surface-2); color: var(--ink); }

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

.content {
    flex: 1;
    width: 100%;
    max-width: 1080px;
    padding: 2rem 2.25rem;
}

.footer {
    padding: 1.2rem 2.25rem;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: .82rem;
}

/* --- Pantalla de login ---------------------------------------------- */

body.auth {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.auth-wrap { width: 100%; max-width: 380px; }

.auth-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
    margin-bottom: 1.5rem;
}
.auth-brand .brand-mark { font-size: .8rem; }
.auth-brand .brand-name { font-size: 1.6rem; }
.auth-brand .brand-logo { height: 26px; }

/* --- Tarjetas -------------------------------------------------------- */

.card,
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.6rem;
}

.muted,
.empty { color: var(--muted); }

/* --- Cabecera de página --------------------------------------------- */

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.4rem;
}
.page-head h1 { margin: 0; }

/* --- Tablas ---------------------------------------------------------- */

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

.table th,
.table td {
    padding: .7rem .65rem;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border);
}

/* Celda de descripción del listado de horas: limita el ancho y ajusta. */
.table td.desc-cell { max-width: 26rem; }

.table thead th {
    font-size: .76rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    font-weight: 600;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }

.table .num { text-align: right; }

.table td.actions,
.table th.actions { white-space: nowrap; }
.table td.actions > * { margin-right: .8rem; }
.table td.actions > *:last-child { margin-right: 0; }
.table td.actions form { display: inline-block; }

.table tfoot td {
    border-top: 2px solid var(--border);
    border-bottom: none;
}

/* --- Distintivos de estado ------------------------------------------ */

.badge {
    display: inline-block;
    padding: .15rem .6rem;
    border-radius: 999px;
    font-size: .76rem;
    font-weight: 600;
}
.badge-active   { background: rgba(69, 196, 99, .16); color: var(--ok); }
.badge-archived { background: var(--surface-2); color: var(--muted); }
.badge-finalizada { background: rgba(69, 196, 99, .16); color: var(--ok); }
.badge-pendiente  { background: rgba(224, 162, 58, .18); color: var(--warn); }

/* --- Botones --------------------------------------------------------- */

.btn {
    display: inline-block;
    padding: .55rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--ink);
    font-size: .95rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
}
.btn:hover { background: var(--border); text-decoration: none; }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.btn-primary:hover { background: var(--accent-h); border-color: var(--accent-h); }

/* Botones con aspecto de enlace (acciones de tabla). */
.btn-link {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    color: var(--accent);
    cursor: pointer;
    text-decoration: none;
}
.btn-link:hover { text-decoration: underline; }
.btn-link.danger,
.link-danger { color: var(--danger); }

/* --- Formularios ----------------------------------------------------- */

.form { display: flex; flex-direction: column; gap: 1.1rem; }

.field { display: flex; flex-direction: column; gap: .35rem; }
.field > span { font-size: .88rem; font-weight: 600; color: var(--ink); }
.field.inline { min-width: 200px; }

.req { color: var(--accent); }

.field-hint { font-size: .8rem; color: var(--muted); }

input[type="text"],
input[type="password"],
input[type="date"],
input[type="number"],
select,
textarea {
    padding: .6rem .7rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--ink);
    font: inherit;
    font-size: .95rem;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(232, 85, 45, .22);
}

textarea { resize: vertical; }
::placeholder { color: var(--muted); }

/* Autocompletado del navegador en tema oscuro. */
input:-webkit-autofill {
    -webkit-text-fill-color: var(--ink);
    -webkit-box-shadow: 0 0 0 40px var(--surface-2) inset;
}

.form-actions {
    display: flex;
    gap: .7rem;
    align-items: center;
    margin-top: .3rem;
}

/* --- Filtros --------------------------------------------------------- */

.filters {
    display: flex;
    align-items: flex-end;
    gap: 1.25rem;
    flex-wrap: wrap;
    margin-bottom: 1.3rem;
    padding-bottom: 1.3rem;
    border-bottom: 1px solid var(--border);
}

.filter-form {
    display: flex;
    align-items: flex-end;
    gap: .6rem;
}

.filter-grid {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 1rem;
    margin-bottom: 1.3rem;
    padding-bottom: 1.3rem;
    border-bottom: 1px solid var(--border);
}
.filter-grid .field { min-width: 150px; }

.filter-actions { display: flex; gap: .5rem; }

/* --- Paginación ------------------------------------------------------ */

.pagination {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1.3rem;
}

/* --- Avisos ---------------------------------------------------------- */

.alert {
    margin: 0 0 1.1rem;
    padding: .7rem .9rem;
    border: 1px solid transparent;
    border-radius: 8px;
    font-size: .92rem;
}
.alert ul { margin: .15rem 0 0; padding-left: 1.2rem; }

.alert-error {
    background: rgba(239, 106, 82, .12);
    border-color: rgba(239, 106, 82, .35);
    color: var(--danger);
}

.alert-success {
    background: rgba(69, 196, 99, .12);
    border-color: rgba(69, 196, 99, .32);
    color: var(--ok);
}

/* --- Responsive ------------------------------------------------------ */

@media (max-width: 760px) {
    body.app { flex-direction: column; }

    .sidebar {
        width: auto;
        height: auto;
        position: static;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .brand { padding: 1rem 1.2rem .6rem; }

    .nav {
        flex: none;
        flex-direction: row;
        flex-wrap: wrap;
        padding: 0 .7rem .6rem;
    }
    .nav-link { padding: .45rem .65rem; }

    .content { padding: 1.4rem 1.25rem; }

    .page-head { flex-direction: column; align-items: flex-start; }
}

/* --- Informe mensual ------------------------------------------------- */

.report-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: .8rem;
    margin-bottom: 1.3rem;
    padding-bottom: 1.3rem;
    border-bottom: 1px solid var(--border);
}

.report-summary {
    font-size: 1.02rem;
    margin: 0 0 1.2rem;
}

.report-client td {
    background: var(--surface-2);
    font-weight: 600;
}

.report-project td.indent { padding-left: 1.9rem; }

.report-entry td { font-size: .9rem; }
.report-entry td.report-entry-cell { padding-left: 3.1rem; }
.entry-date { color: var(--muted); margin-right: .45rem; white-space: nowrap; }

.entry-desc { display: block; margin-top: .15rem; }
.entry-desc ul,
.entry-desc ol { margin: .25rem 0; padding-left: 1.35rem; }
.entry-desc li { margin: .1rem 0; }
.entry-desc p,
.entry-desc div { margin: .1rem 0; }
.entry-desc strong,
.entry-desc b { font-weight: 700; }
.entry-desc em,
.entry-desc i { font-style: italic; }

/* --- Editor enriquecido del campo Descripción ----------------------- */

.rte {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    overflow: hidden;
}
.rte:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(232, 85, 45, .22);
}

.rte-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    padding: .4rem;
    border-bottom: 1px solid var(--border);
}

.md-btn {
    padding: .25rem .65rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--ink);
    font-size: .85rem;
    line-height: 1.5;
    cursor: pointer;
}
.md-btn:hover { background: var(--border); }
.md-btn em { font-style: italic; }

.rte-editor {
    min-height: 6.5rem;
    padding: .6rem .7rem;
    font: inherit;
    color: var(--ink);
    outline: none;
}
.rte-editor ul,
.rte-editor ol { margin: .3rem 0; padding-left: 1.4rem; }
.rte-editor p,
.rte-editor div { margin: .15rem 0; }

/* --- Impresión ------------------------------------------------------- */

@media print {
    .sidebar,
    .footer,
    .no-print { display: none !important; }

    body,
    body.app { display: block; background: #fff; color: #000; }

    .content { max-width: none; padding: 0; }

    .card {
        background: #fff;
        border: none;
        padding: 0;
    }

    a { color: #000; }

    .table th,
    .table td { border-color: #ccc; }

    .table thead th { color: #000; }

    .report-client td { background: #f0f0f0; }

    .badge { border: 1px solid #bbb; }
}

/* --- Dashboard: títulos y gráficas ---------------------------------- */

.card-title {
    font-size: 1.1rem;
    margin: 0 0 .4rem;
}

.dashboard-charts {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
    margin-top: 1.25rem;
}

.chart-title {
    font-size: 1.05rem;
    margin: 0 0 .15rem;
}

.chart-period {
    margin: 0 0 1.1rem;
    font-size: .82rem;
    color: var(--muted);
}

.chart {
    display: flex;
    flex-direction: column;
    gap: .65rem;
}

.chart-row {
    display: grid;
    grid-template-columns: minmax(0, max-content) minmax(0, 1fr) auto;
    align-items: center;
    gap: .9rem;
}

.chart-label {
    font-size: .88rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chart-label small { color: var(--muted); margin-left: .15rem; }

.chart-track {
    height: 15px;
    background: var(--surface-2);
    border-radius: 5px;
    overflow: hidden;
}

.chart-bar {
    display: block;
    height: 100%;
    min-width: 3px;
    background: var(--accent);
    border-radius: 5px;
}

.chart-value {
    font-size: .85rem;
    color: var(--muted);
    white-space: nowrap;
    text-align: right;
}

.chart-filter { margin-bottom: 1.1rem; }

.chart-total {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-top: 1rem;
    padding-top: .85rem;
    border-top: 1px solid var(--border);
    font-size: .95rem;
}
.chart-total strong { font-size: 1.05rem; }

@media (max-width: 860px) {
    .dashboard-charts { grid-template-columns: 1fr; }
}

/* --- Vista calendario de tareas ------------------------------------- */

.view-toggle {
    display: flex;
    gap: .4rem;
    margin-bottom: 1.1rem;
}

.cal-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}
.cal-head .view-toggle { margin-bottom: 0; }

.cal-nav {
    display: flex;
    align-items: center;
    gap: .5rem;
}
.cal-month {
    font-weight: 600;
    min-width: 9.5rem;
    text-align: center;
}

.calendar {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.cal-weekday {
    background: var(--surface-2);
    padding: .4rem;
    text-align: center;
    font-size: .76rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    font-weight: 600;
}

.cal-cell {
    background: var(--surface);
    height: 7rem;
    padding: .35rem;
    display: flex;
    flex-direction: column;
    gap: .2rem;
    overflow: hidden;
}
.cal-empty { background: var(--bg); }
.cal-today { box-shadow: inset 0 0 0 2px var(--accent); }

.cal-day {
    align-self: flex-start;
    font-size: .82rem;
    color: var(--muted);
    text-decoration: none;
    padding: .05rem .3rem;
    border-radius: 4px;
}
.cal-day:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.cal-today .cal-day { color: var(--accent); font-weight: 700; }

.cal-task {
    display: block;
    font-size: .78rem;
    padding: .14rem .4rem;
    border-radius: 4px;
    border-left: 3px solid transparent;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
}
.cal-task:hover { text-decoration: none; opacity: .85; }

/* Punto rojo = tarea pendiente. */
.task-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: .35rem;
    border-radius: 50%;
    background: var(--danger);
    vertical-align: middle;
}

/* Muestra del color de un cliente. */
.color-swatch {
    display: inline-block;
    width: .72rem;
    height: .72rem;
    border-radius: 3px;
    margin-right: .4rem;
    vertical-align: middle;
}

/* Selector de color en el formulario de cliente. */
.color-input {
    width: 4rem;
    height: 2.3rem;
    padding: .15rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    cursor: pointer;
}

.cal-legend {
    display: flex;
    gap: .6rem;
    margin: 1rem 0 0;
}

/* Vista semanal: una fila de 7 celdas más altas (todas igual de grandes). */
.cal-week-cell {
    height: 32rem;
    overflow: hidden;
}

.calendar-week .cal-weekday {
    font-size: .92rem;
    padding: .55rem;
    text-transform: none;
    letter-spacing: 0;
}
.cal-weekday-today {
    color: var(--accent);
    font-weight: 700;
}

@media (max-width: 760px) {
    .cal-cell      { height: 5rem; }
    .cal-week-cell { height: 18rem; }
}
