@font-face {
    font-family: 'DM Sans';
    src: url('../fonts/dm-sans/dm-sans-variable.ttf') format('truetype');
    font-style: normal;
    font-weight: 100 1000;
    font-display: swap;
}

:root {
    --font-ui: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --text-title: clamp(1.75rem, 2.5vw, 2.125rem);
    --text-section: 1.25rem;
    --text-body: 1rem;
    --text-small: 0.875rem;
    --text-label: 0.8125rem;
    --text-caption: 0.75rem;
    /* Azul de marca para acciones; los colores semánticos indican estados. */
    --primary: #3569aa;
    --primary-light: #4a7db9;
    --primary-dark: #29568f;
    --primary-soft: #edf3fb;
    --primary-border: #cbdcf0;
    --focus-ring: rgba(53, 105, 170, 0.18);
    --background: #f4f6f8;
    --surface: #ffffff;
    --surface-elevated: #f8fafc;
    --surface-hover: #f1f5fa;
    --text-main: #243447;
    --text-secondary: #3f5063;
    --text-muted: #526275;
    --success: #28734e;
    --success-soft: #edf7f0;
    --success-text: #245f42;
    --warning: #906014;
    --warning-soft: #fff7e6;
    --warning-text: #80530b;
    --danger: #b8323b;
    --danger-soft: #fff0f1;
    --danger-text: #9a2832;
    --danger-border: #f0cbd0;
    --neutral-soft: #eef2f6;
    --neutral-text: #526478;
    --border: #dce3eb;
    --border-light: #eaf0f5;
    --border-strong: #b3c4d7;
    --shadow-sm: 0 1px 3px rgba(36,52,71,0.06);
    --shadow-md: 0 4px 12px rgba(36,52,71,0.08);
    --shadow-lg: 0 8px 30px rgba(36,52,71,0.12);
    --shadow-dialog: 0 24px 80px rgba(36,52,71,0.2);
    --backdrop: rgba(36,52,71,0.6);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: var(--font-ui);
    font-size: var(--text-body);
    font-optical-sizing: auto;
    background: var(--background);
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
}

button, input, select, textarea {
    font-family: inherit;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-ui);
    line-height: 1.25;
}

header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
}

.brand img {
    height: 42px;
    border-radius: var(--radius-sm);
}

.brand-text {
    font-family: var(--font-ui);
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--primary);
    letter-spacing: -0.02em;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.user-detail {
    text-align: right;
}

.user-name {
    font-weight: 600;
    color: var(--text-main);
    font-size: 0.95rem;
}

.user-role {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.logout-btn {
    background: transparent;
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.85rem;
    transition: var(--transition);
}

.logout-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

main {
    flex: 1;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

h1 {
    font-family: var(--font-ui);
    font-size: var(--text-title);
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 1rem;
}

.messages {
    margin-bottom: 1.5rem;
    list-style: none;
}

.messages li {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    margin-bottom: 0.75rem;
    font-weight: 500;
    font-size: 0.95rem;
    border-left: 4px solid;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-10px); }
    to { opacity: 1; transform: translateX(0); }
}

.msg-success { background: var(--success-soft); color: var(--success-text); border-color: var(--success); }
.msg-error { background: var(--danger-soft); color: var(--danger-text); border-color: var(--danger); }
.msg-warning { background: var(--warning-soft); color: var(--warning-text); border-color: var(--warning); }
.msg-info { background: var(--primary-soft); color: var(--primary-dark); border-color: var(--primary); }

.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 2rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-light);
    transition: var(--transition);
    width: fit-content;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-light);
}

.card-title {
    font-family: var(--font-ui);
    font-size: var(--text-section);
    font-weight: 600;
    color: var(--primary);
}

.table-container { 
    overflow-x: auto; 
    border-radius: var(--radius-md);
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-variant-numeric: tabular-nums;
}

th {
    padding: 1rem 1.25rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface-elevated);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.95rem;
}

tr:last-child td { border-bottom: none; }

tr:hover td {
    background: var(--surface-hover);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    font-size: 0.9rem;
    font-family: inherit;
}

.btn-primary { 
    background: var(--primary); 
    color: white; 
}
.btn-primary:hover { 
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-success { 
    background: var(--success); 
    color: white; 
}
.btn-success:hover { 
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.btn-outline { 
    background: transparent; 
    border: 1px solid var(--primary); 
    color: var(--primary); 
}
.btn-outline:hover { 
    background: var(--primary); 
    color: white;
}

.btn-sm {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
}

.btn:disabled, .btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.3rem 0.75rem;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-pending { background: var(--neutral-soft); color: var(--neutral-text); }
.badge-waiting { background: var(--primary-soft); color: var(--primary-dark); }
.badge-signed { background: var(--success-soft); color: var(--success-text); }
.badge-downloaded { background: var(--neutral-soft); color: var(--neutral-text); }

.status-completed {
    color: var(--success);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.status-progress {
    color: var(--warning);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

form { 
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

input[type="file"] {
    padding: 0.5rem;
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-elevated);
    transition: var(--transition);
}

input[type="file"]:hover {
    border-color: var(--primary);
}

.filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--surface-elevated);
    border-radius: var(--radius-md);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.filter-group label {
    font-weight: 600;
    font-size: var(--text-label);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.filter-group input,
.filter-group select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    background: var(--surface);
    transition: var(--transition);
}

.filter-group input:focus,
.filter-group select:focus {
    outline: none;
    border-color: var(--primary);
}

.btn-clear {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    transition: var(--transition);
    align-self: flex-end;
    height: fit-content;
}

.btn-clear:hover {
    background: var(--border-light);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
}

@media (max-width: 768px) {
    header { padding: 1rem; flex-wrap: wrap; gap: 12px; }
    .user-info { gap: 12px; margin-left: auto; flex-wrap: wrap; }
    main { padding: 1rem; }
    .page-header { flex-direction: column; gap: 1rem; }
    .user-detail { display: none; }
}
