/* ============================================================
   PETICIONES DE COMPRA — A LA PAR
   Hoja de estilos principal
   ============================================================ */

/* --- Variables ------------------------------------------------ */
:root {
    --color-primary:    #1a5276;
    --color-primary-d:  #154360;
    --color-secondary:  #2e86c1;
    --color-success:    #1e8449;
    --color-danger:     #c0392b;
    --color-warning:    #d68910;
    --color-info:       #2874a6;
    --color-text:       #1c2833;
    --color-text-soft:  #5d6d7e;
    --color-border:     #d5d8dc;
    --color-bg:         #f4f6f8;
    --color-white:      #ffffff;
    --color-card:       #ffffff;
    --color-header-bg:  #1a5276;
    --color-header-fg:  #ffffff;
    --font-body:        'Segoe UI', system-ui, -apple-system, sans-serif;
    --radius:           6px;
    --shadow-card:      0 1px 4px rgba(0,0,0,.1);
    --transition:       .15s ease;
}

/* --- Reset & Base -------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: var(--font-body);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--color-secondary); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--color-primary-d); }

/* --- Header -------------------------------------------------- */
.app-header {
    background: var(--color-header-bg);
    color: var(--color-header-fg);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 6px rgba(0,0,0,.25);
}

.header-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: .75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.header-logo {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
    color: var(--color-header-fg);
    text-decoration: none;
    flex-shrink: 0;
}
.header-logo:hover { text-decoration: none; }
.logo-text { font-size: 1.2rem; font-weight: 700; letter-spacing: .03em; }
.logo-sub  { font-size: .7rem; opacity: .75; letter-spacing: .05em; text-transform: uppercase; }

.header-nav {
    display: flex;
    gap: 1.25rem;
    flex: 1;
}
.header-nav a {
    color: rgba(255,255,255,.85);
    font-size: .9rem;
    padding: .25rem 0;
    border-bottom: 2px solid transparent;
    transition: var(--transition);
}
.header-nav a:hover {
    color: var(--color-white);
    border-bottom-color: rgba(255,255,255,.6);
    text-decoration: none;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: .85rem;
}
.user-name { color: rgba(255,255,255,.85); }
.btn-logout {
    background: rgba(255,255,255,.15);
    color: var(--color-white);
    padding: .3rem .75rem;
    border-radius: var(--radius);
    transition: var(--transition);
}
.btn-logout:hover {
    background: rgba(255,255,255,.25);
    text-decoration: none;
    color: var(--color-white);
}

.notif-btn {
    position: relative;
    color: rgba(255,255,255,.85);
    font-size: 1.1rem;
    cursor: pointer;
}
.notif-btn:hover { color: var(--color-white); text-decoration: none; }
.notif-badge {
    position: absolute;
    top: -6px;
    right: -8px;
    background: #e74c3c;
    color: white;
    font-size: .65rem;
    font-weight: 700;
    border-radius: 99px;
    padding: 1px 5px;
    min-width: 18px;
    text-align: center;
}

/* --- Main ---------------------------------------------------- */
.app-main {
    flex: 1;
    max-width: 1280px;
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem;
}

/* --- Footer -------------------------------------------------- */
.app-footer {
    background: var(--color-primary-d);
    color: rgba(255,255,255,.6);
    text-align: center;
    padding: .75rem;
    font-size: .8rem;
    margin-top: auto;
}

/* --- Page header --------------------------------------------- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1rem;
    flex-wrap: wrap;
}
.page-header h1 { font-size: 1.6rem; font-weight: 700; color: var(--color-primary); }
.page-subtitle   { color: var(--color-text-soft); font-size: .95rem; }
.page-header-left { display: flex; flex-direction: column; gap: .25rem; }
.page-header-right { display: flex; align-items: center; gap: .75rem; }
.back-link { color: var(--color-text-soft); font-size: .85rem; }

/* --- Alerts / Flash ------------------------------------------ */
.flash-messages { margin-bottom: 1rem; }
.alert {
    padding: .85rem 1rem;
    border-radius: var(--radius);
    margin-bottom: .75rem;
    font-size: .9rem;
    border-left: 4px solid;
}
.alert-success { background: #eafaf1; border-color: var(--color-success); color: #145a32; }
.alert-error   { background: #fdedec; border-color: var(--color-danger);  color: #922b21; }
.alert-warning { background: #fef9e7; border-color: var(--color-warning); color: #7d6608; }
.alert-info    { background: #eaf2f8; border-color: var(--color-info);    color: #154360; }

/* --- Status badges ------------------------------------------- */
.status-badge {
    display: inline-block;
    padding: .2rem .65rem;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 600;
    letter-spacing: .03em;
    text-transform: uppercase;
}
.status-borrador             { background: #eaecee; color: #566573; }
.status-enviado              { background: #d6eaf8; color: #1a5276; }
.status-en_revision          { background: #d6eaf8; color: #1a5276; }
.status-pendiente_aprobacion { background: #fdebd0; color: #784212; }
.status-auto_autorizado      { background: #d5f5e3; color: #145a32; }
.status-aprobado             { background: #d5f5e3; color: #145a32; }
.status-rechazado            { background: #fadbd8; color: #922b21; }
.status-cancelado            { background: #eaecee; color: #566573; }

/* --- Buttons ------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem 1rem;
    border: none;
    border-radius: var(--radius);
    font-size: .9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(.92); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary   { background: var(--color-primary);   color: #fff; }
.btn-secondary { background: var(--color-secondary);  color: #fff; }
.btn-success   { background: var(--color-success);    color: #fff; }
.btn-danger    { background: var(--color-danger);     color: #fff; }
.btn-ghost     { background: transparent; color: var(--color-primary); border: 1px solid var(--color-border); }
.btn-full      { width: 100%; justify-content: center; }
.btn-sm        { padding: .3rem .7rem; font-size: .82rem; }
.btn-large     { padding: .75rem 1.5rem; font-size: 1rem; }

/* --- Cards --------------------------------------------------- */
.form-card, .detail-card, .action-card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-card);
}
.form-card h2, .detail-card h2, .action-card h3 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--color-primary);
    margin-bottom: 1rem;
    padding-bottom: .5rem;
    border-bottom: 1px solid var(--color-border);
}
.action-card-danger { border-color: #f5b7b1; }
.action-card-danger h3 { color: var(--color-danger); border-bottom-color: #f5b7b1; }

/* --- Forms --------------------------------------------------- */
.form-group {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    margin-bottom: .85rem;
}
.form-group label {
    font-size: .88rem;
    font-weight: 500;
    color: var(--color-text);
}
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}
.form-group-btn {
    justify-content: flex-end;
    align-self: flex-end;
    margin-bottom: .85rem;
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="password"],
input[type="url"],
select,
textarea {
    padding: .5rem .75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: .9rem;
    font-family: inherit;
    color: var(--color-text);
    background: var(--color-white);
    transition: border-color var(--transition);
    width: 100%;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-secondary);
    box-shadow: 0 0 0 2px rgba(46,134,193,.15);
}
input.field-invalid, select.field-invalid, textarea.field-invalid {
    border-color: var(--color-danger);
}

.field-error { color: var(--color-danger); font-size: .82rem; }
.field-hint  { color: var(--color-text-soft); font-size: .8rem; }
.required    { color: var(--color-danger); }

.form-hint {
    color: var(--color-text-soft);
    font-size: .85rem;
    margin-bottom: .75rem;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: .75rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border);
}

.radio-group, .checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}
.radio-group label, .checkbox-group label {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-weight: 400;
    cursor: pointer;
}

/* --- Tables -------------------------------------------------- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-card);
    font-size: .9rem;
}
.data-table thead th {
    background: var(--color-primary);
    color: #fff;
    padding: .65rem 1rem;
    text-align: left;
    font-weight: 500;
    font-size: .83rem;
    letter-spacing: .03em;
    white-space: nowrap;
}
.data-table tbody td {
    padding: .6rem 1rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #f8f9fa; }
.data-table-sm td, .data-table-sm th { padding: .45rem .75rem; font-size: .82rem; }
.text-right { text-align: right; }
.table-count { color: var(--color-text-soft); font-size: .85rem; margin-top: .5rem; }
.row-inactive { opacity: .55; }

/* --- Stats grid ---------------------------------------------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem 1rem;
    text-align: center;
    box-shadow: var(--shadow-card);
}
.stat-card .stat-value { display: block; font-size: 2.2rem; font-weight: 700; color: var(--color-primary); }
.stat-card .stat-label { display: block; font-size: .82rem; color: var(--color-text-soft); margin-top: .25rem; }
.stat-warning .stat-value { color: var(--color-warning); }
.stat-success .stat-value { color: var(--color-success); }
.stat-danger  .stat-value { color: var(--color-danger);  }

/* --- Dashboard actions --------------------------------------- */
.dashboard-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

/* --- Admin grid --------------------------------------------- */
.admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}
.admin-card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
    transition: var(--transition);
    box-shadow: var(--shadow-card);
    color: var(--color-text);
    text-decoration: none;
}
.admin-card:hover {
    border-color: var(--color-secondary);
    box-shadow: 0 3px 10px rgba(0,0,0,.12);
    text-decoration: none;
    transform: translateY(-2px);
}
.admin-card-icon { font-size: 2.2rem; margin-bottom: .5rem; }
.admin-card h3   { font-size: 1rem; color: var(--color-primary); margin-bottom: .4rem; }
.admin-card p    { font-size: .83rem; color: var(--color-text-soft); }

/* --- Detail view -------------------------------------------- */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}
.full-width { grid-column: 1 / -1; }

.detail-list {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: .4rem .75rem;
    font-size: .9rem;
}
.detail-list dt { font-weight: 500; color: var(--color-text-soft); align-self: start; }
.detail-list dd { color: var(--color-text); }
.importe-highlight { font-size: 1.2rem; font-weight: 700; color: var(--color-primary); }

/* --- Adjuntos ----------------------------------------------- */
.adjuntos-list { list-style: none; }
.adjuntos-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .4rem 0;
    border-bottom: 1px solid var(--color-border);
    font-size: .88rem;
}
.adjunto-meta { color: var(--color-text-soft); font-size: .78rem; }

/* --- Approval timeline -------------------------------------- */
.approval-timeline {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-card);
}
.approval-timeline h2 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--color-primary);
    margin-bottom: 1rem;
}
.timeline { list-style: none; padding-left: 0; }
.timeline-step {
    padding: .75rem 1rem .75rem 2rem;
    position: relative;
    border-left: 3px solid var(--color-border);
    margin-left: 1rem;
    margin-bottom: .5rem;
}
.timeline-step::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 1rem;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--color-border);
    border: 2px solid white;
}
.step-aprobado::before      { background: var(--color-success); }
.step-rechazado::before     { background: var(--color-danger); }
.step-auto_autorizado::before { background: var(--color-success); }
.step-pendiente::before     { background: var(--color-warning); }
.step-omitido::before       { background: #aab7b8; }

.step-header { display: flex; align-items: center; justify-content: space-between; }
.step-label  { font-weight: 600; font-size: .92rem; }
.step-status { font-size: .78rem; color: var(--color-text-soft); text-transform: uppercase; letter-spacing: .04em; }
.step-meta   { font-size: .82rem; color: var(--color-text-soft); margin-top: .2rem; }
.step-comment {
    margin-top: .4rem;
    padding: .5rem .75rem;
    background: #f8f9fa;
    border-radius: 4px;
    font-size: .85rem;
    border-left: 3px solid var(--color-border);
}

/* --- Action zone -------------------------------------------- */
.action-zone { display: flex; flex-direction: column; gap: 1rem; }

/* --- Filters ----------------------------------------------- */
.filter-form { margin-bottom: 1.25rem; }
.filter-row  { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.filter-row .form-group { margin-bottom: 0; min-width: 140px; }

/* --- Pagination -------------------------------------------- */
.pagination { display: flex; gap: .4rem; margin-top: 1rem; flex-wrap: wrap; }
.page-link {
    padding: .35rem .7rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: .85rem;
    color: var(--color-secondary);
    text-decoration: none;
}
.page-link.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.page-link:hover  { text-decoration: none; background: var(--color-bg); }

/* --- Notifications ------------------------------------------ */
.notification-list { list-style: none; }
.notif-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: .85rem 1rem;
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: .5rem;
}
.notif-unread { border-left: 4px solid var(--color-secondary); }
.notif-content p { font-size: .9rem; }
.notif-content a { font-size: .83rem; }
.notif-date { font-size: .78rem; color: var(--color-text-soft); white-space: nowrap; }
.badge-large {
    background: var(--color-warning);
    color: white;
    padding: .25rem .75rem;
    border-radius: 999px;
    font-weight: 600;
    font-size: .9rem;
}

/* --- Login page --------------------------------------------- */
.login-page {
    background: linear-gradient(135deg, var(--color-primary-d) 0%, var(--color-secondary) 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-container {
    background: var(--color-card);
    border-radius: 10px;
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.login-logo { text-align: center; margin-bottom: 1.5rem; }
.login-logo .logo-text { font-size: 1.6rem; color: var(--color-primary); font-weight: 700; display: block; }
.login-logo .logo-sub  { font-size: .8rem; color: var(--color-text-soft); text-transform: uppercase; letter-spacing: .07em; }
.login-title { text-align: center; font-size: 1.2rem; color: var(--color-text); margin-bottom: 1.5rem; }

/* --- Token page -------------------------------------------- */
.token-page {
    background: var(--color-bg);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.token-container {
    background: var(--color-card);
    border-radius: 10px;
    padding: 2rem;
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-card);
}
.token-header { text-align: center; margin-bottom: 1.25rem; }
.token-header .logo-text { font-size: 1.4rem; color: var(--color-primary); font-weight: 700; display: block; }
.token-details {
    background: var(--color-bg);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.25rem;
    font-size: .9rem;
}
.token-details p { margin-bottom: .4rem; }
.token-footer { text-align: center; margin-top: 1rem; font-size: .82rem; color: var(--color-text-soft); }

/* --- Error page -------------------------------------------- */
.error-page {
    max-width: 500px;
    margin: 5rem auto;
    text-align: center;
}
.error-page h1 { font-size: 2rem; color: var(--color-danger); margin-bottom: 1rem; }

/* --- Empty state ------------------------------------------- */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--color-text-soft);
}

/* --- Misc --------------------------------------------------- */
.badge {
    background: var(--color-danger);
    color: white;
    border-radius: 999px;
    padding: .1rem .45rem;
    font-size: .72rem;
    font-weight: 700;
    margin-left: .3rem;
}
.recent-requests { margin-top: 1.5rem; }
.recent-requests h2 { font-size: 1.1rem; color: var(--color-primary); margin-bottom: .75rem; }
.recent-requests a  { display: inline-block; margin-top: .5rem; font-size: .9rem; }

/* --- Responsive -------------------------------------------- */
@media (max-width: 768px) {
    .header-inner { flex-wrap: wrap; gap: .75rem; }
    .header-nav   { order: 3; width: 100%; flex-wrap: wrap; gap: .75rem; }
    .detail-grid  { grid-template-columns: 1fr; }
    .detail-list  { grid-template-columns: 1fr; }
    .detail-list dt { border-top: 1px solid var(--color-border); padding-top: .3rem; margin-top: .3rem; }
    .app-main { padding: 1rem; }
    .form-row { grid-template-columns: 1fr; }
}
