:root {
    --primary: #0f766e;
    --primary-dark: #0b5a54;
    --primary-light: #e6f5f2;
    --accent: #2563eb;
    --bg: #f4f6f7;
    --card-bg: #ffffff;
    --border: #e4e9e8;
    --text: #1c2624;
    --text-muted: #6b7b78;
    --error: #b3261e;
    --error-bg: #fbeaea;
    --success: #0f766e;
    --success-bg: #e6f5f2;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(15, 23, 22, 0.04), 0 2px 8px rgba(15, 23, 22, 0.04);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); }

h1, h2, h3 {
    font-weight: 700;
    letter-spacing: -0.01em;
    color: #10201c;
}

h1 { font-size: 1.55rem; margin: 0 0 20px; }
h2 { font-size: 1.15rem; margin: 0 0 14px; }

.container {
    max-width: 1040px;
    margin: 0 auto;
    padding: 28px 20px 72px;
}

/* Topbar */
.topbar {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-inner {
    max-width: 1040px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 20px;
    padding-top: env(safe-area-inset-top);
    height: calc(60px + env(safe-area-inset-top));
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #fff;
    font-weight: 800;
    font-size: 1.05rem;
    text-decoration: none;
    white-space: nowrap;
}

.brand-mark {
    font-size: 1.3rem;
    line-height: 1;
}

.topbar nav {
    display: flex;
    gap: 4px;
    flex: 1;
    overflow-x: auto;
}

.topbar nav a {
    color: rgba(255, 255, 255, 0.82);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 999px;
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease;
}

.topbar nav a:hover { color: #fff; background: rgba(255, 255, 255, 0.12); }
.topbar nav a.active { color: var(--primary-dark); background: #fff; }

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.user-meta {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.user-name { color: #fff; font-size: 0.85rem; font-weight: 600; }
.user-role { color: rgba(255, 255, 255, 0.7); font-size: 0.72rem; }

.logout-link {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    font-size: 1.1rem;
    padding: 6px;
    border-radius: 50%;
    transition: background 0.15s ease, color 0.15s ease;
}

.logout-link:hover { background: rgba(255, 255, 255, 0.15); color: #fff; }

/* Login */
.login-box {
    max-width: 380px;
    margin: 10vh auto 0;
    background: var(--card-bg);
    padding: 36px 32px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    text-align: center;
}

.login-box h1 {
    margin: 0 0 4px;
    font-size: 1.4rem;
    color: var(--primary-dark);
}

.login-box h2 {
    margin: 0 0 24px;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-muted);
}

.login-box form { text-align: left; }

.login-box button { width: 100%; margin-top: 4px; }

/* Forms */
form label {
    display: block;
    margin-bottom: 14px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}

form input, form select, form textarea {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    background: #fbfcfc;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

form input:focus, form select:focus, form textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
    background: #fff;
}

form textarea { resize: vertical; min-height: 80px; }

button, input[type="submit"] {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    transition: background 0.15s ease, transform 0.05s ease;
}

button:hover { background: var(--primary-dark); }
button:active { transform: translateY(1px); }

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.9rem;
    font-weight: 500;
}

.alert-error { background: var(--error-bg); color: var(--error); border: 1px solid #f2c9c6; }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #b9e2da; }

/* Cards */
.form-card, .job-summary {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
}

.form-card + .form-card { margin-top: -8px; }

.job-summary p { margin: 0 0 10px; font-size: 0.92rem; }
.job-summary p:last-child { margin-bottom: 0; }
.job-summary strong { color: var(--text-muted); font-weight: 600; margin-right: 4px; }

/* Table */
.jobs-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.jobs-table th {
    text-align: left;
    padding: 12px 14px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    background: #fafbfb;
    border-bottom: 1px solid var(--border);
}

.jobs-table td {
    text-align: left;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.jobs-table tbody tr:last-child td { border-bottom: none; }
.jobs-table tbody tr:hover { background: #fafcfb; }

.jobs-table a { text-decoration: none; font-weight: 600; }
.jobs-table a:hover { text-decoration: underline; }

.filter-bar {
    margin-bottom: 16px;
    max-width: 240px;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    color: white;
    background: #999;
}

.badge-recibido { background: #64748b; }
.badge-en_proceso { background: #d97706; }
.badge-control_calidad { background: var(--accent); }
.badge-terminado { background: #16a34a; }
.badge-enviado { background: var(--primary); }

/* Lists */
.file-list, .history-list {
    list-style: none;
    padding: 0;
    margin: 0 0 24px;
}

.file-list li, .history-list li {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 8px;
    font-size: 0.88rem;
}

.file-list a { font-weight: 600; text-decoration: none; }
.file-list a:hover { text-decoration: underline; }

.history-list li em { color: var(--text-muted); font-style: normal; }

/* Botón de instalación PWA */
.pwa-install-btn {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 12px 18px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.9rem;
    font-family: inherit;
    box-shadow: 0 4px 14px rgba(15, 118, 110, 0.35);
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}

.pwa-install-btn:hover { background: var(--primary-dark); }
.pwa-install-btn:active { transform: translateY(1px); }

/* Responsive */
@media (max-width: 640px) {
    .topbar-inner { flex-wrap: wrap; height: auto; padding: 12px 16px; gap: 10px; }
    .topbar nav { order: 3; width: 100%; }
    .user-meta { display: none; }
    .container { padding: 20px 14px 48px; }
    .jobs-table { display: block; overflow-x: auto; }
    .pwa-install-btn { right: 14px; bottom: 14px; padding: 10px 16px; font-size: 0.85rem; }
}
