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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    background: #f0f2f5;
    color: #1a1a2e;
    line-height: 1.6;
}

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.login-card {
    background: #fff;
    border-radius: 12px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.login-card h1 {
    text-align: center;
    color: #1a1a2e;
    margin-bottom: 8px;
    font-size: 1.6rem;
}

.subtitle {
    text-align: center;
    color: #666;
    margin-bottom: 24px;
    font-size: 0.9rem;
}

.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    color: #333;
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: #4472C4;
}

header {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: white;
    padding: 16px 24px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.header-content h1 {
    font-size: 1.4rem;
}

.header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.85rem;
}

.btn-lg {
    padding: 12px 28px;
    font-size: 1.05rem;
}

.btn-full {
    width: 100%;
}

.btn-primary {
    background: #4472C4;
    color: white;
}

.btn-primary:hover {
    background: #3461b3;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-success {
    background: #28a745;
    color: white;
}

.btn-success:hover {
    background: #218838;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

.flash-messages {
    margin-bottom: 20px;
}

.flash {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.flash.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.flash.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.flash.info {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

.flash.warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
}

.warnings-section {
    margin-bottom: 20px;
}

.warnings-section h3 {
    margin-bottom: 10px;
    color: #856404;
}

.upload-section {
    margin-bottom: 30px;
}

.upload-section h2 {
    margin-bottom: 6px;
    color: #1a1a2e;
}

.help-text {
    color: #666;
    margin-bottom: 20px;
    font-size: 0.9rem;
}

.divisions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}

.division-card {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.division-card h3 {
    color: #1a1a2e;
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 2px solid #4472C4;
}

.bucket-section {
    margin-bottom: 14px;
}

.bucket-section h4 {
    color: #4472C4;
    margin-bottom: 8px;
    font-size: 0.95rem;
}

.upload-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}

.file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
}

.file-label {
    flex: 1;
    padding: 6px 12px;
    background: #f8f9fa;
    border: 2px dashed #ccc;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    color: #666;
    text-align: center;
    transition: all 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-label:hover {
    border-color: #4472C4;
    color: #4472C4;
}

.file-label.has-files {
    border-color: #28a745;
    color: #28a745;
    background: #f0fff0;
}

.file-list {
    margin-top: 6px;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    background: #f8f9fa;
    border-radius: 4px;
    margin-bottom: 4px;
    font-size: 0.82rem;
}

.file-name {
    font-weight: 600;
    flex-shrink: 0;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-meta {
    color: #888;
    flex: 1;
    font-size: 0.78rem;
}

.btn-delete {
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
    font-size: 1rem;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.2s;
}

.btn-delete:hover {
    background: #f8d7da;
}

.no-files {
    color: #aaa;
    font-size: 0.82rem;
    font-style: italic;
}

.inline-form {
    display: inline;
}

.actions-section {
    display: flex;
    gap: 14px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid #e0e0e0;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.tab-btn {
    background: none;
    border: none;
    padding: 12px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    color: #666;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: #4472C4;
}

.tab-btn.active {
    color: #1a1a2e;
    border-bottom-color: #4472C4;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 6px;
}

.nomenclatura-uploads {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
    max-width: 1000px;
}

.general-upload-card {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.general-upload-card h3 {
    margin-bottom: 12px;
    font-size: 1rem;
    color: #1a1a2e;
}

.automation-hero {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    padding: 28px;
    margin-bottom: 24px;
    color: white;
    border-radius: 14px;
    background: linear-gradient(135deg, #16213e, #0f5ca8);
    box-shadow: 0 12px 30px rgba(15, 52, 96, 0.2);
}

.automation-hero h2 {
    margin: 4px 0 8px;
    font-size: 1.6rem;
}

.automation-hero p {
    max-width: 780px;
    color: #dbeafe;
}

.automation-hero .last-run {
    margin-top: 10px;
    font-size: 0.85rem;
}

.vm-exception-form {
    width: min(100%, 470px);
    flex: 0 0 470px;
}

.vm-exception-form label {
    display: block;
    margin-bottom: 4px;
    font-weight: 700;
}

.automation-hero .vm-exception-form p {
    margin-bottom: 8px;
    font-size: 0.82rem;
}

.vm-exception-form textarea {
    display: block;
    width: 100%;
    margin-bottom: 10px;
    padding: 10px 12px;
    border: 1px solid #93c5fd;
    border-radius: 8px;
    background: #fff;
    color: #172033;
    font: inherit;
    resize: vertical;
}

.vm-exception-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.eyebrow {
    color: #93c5fd;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.config-card,
.explorer-card,
.empty-state {
    padding: 22px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.07);
}

.license-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.license-grid label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    color: #334155;
    font-size: 0.82rem;
    font-weight: 600;
}

.license-grid input,
.search-form input {
    padding: 9px 11px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    font: inherit;
}

.assignment-form {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 430px;
}

.assignment-form select {
    min-width: 175px;
    padding: 7px 9px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    background: white;
    font: inherit;
}

.bulk-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 1rem;
}

.collapsible-section > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.collapsible-section > summary::-webkit-details-marker {
    display: none;
}

.collapsible-section > summary::after {
    content: "−";
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #e8eef7;
    color: #1f4f8a;
    font-size: 1.25rem;
    line-height: 27px;
    text-align: center;
}

.collapsible-section:not([open]) > summary::after {
    content: "+";
}

.collapsible-section > summary h2 {
    margin-bottom: 0;
}

.collapsible-section[open] > summary {
    margin-bottom: 16px;
}

.collapsible-actions {
    display: flex;
    justify-content: flex-end;
    margin: -8px 0 12px;
}

.progress-grid,
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.progress-card,
.stat-card {
    display: flex;
    flex-direction: column;
    padding: 16px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
}

.progress-card h3 {
    margin-bottom: 8px;
    font-size: 0.95rem;
}

.progress-card span {
    color: #166534;
    font-size: 0.8rem;
}

.stat-card strong {
    color: #0f3460;
    font-size: 1.8rem;
}

.stat-card span {
    color: #64748b;
    font-size: 0.82rem;
}

.warning-stat strong {
    color: #b45309;
}

.export-bar {
    margin-top: 24px;
}

.search-form {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.search-form input {
    flex: 1;
}

.compact-table {
    font-size: 0.8rem;
}

.compact-table th,
.compact-table td {
    padding: 8px 10px;
    white-space: nowrap;
}

.empty-state {
    margin-top: 24px;
    text-align: center;
}

.empty-state p {
    color: #64748b;
}

.assign-form {
    display: flex;
    gap: 6px;
    align-items: center;
}

.group-select {
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 0.85rem;
    background: white;
}

.count-badge {
    display: inline-block;
    background: #4472C4;
    color: white;
    font-size: 0.75rem;
    padding: 2px 10px;
    border-radius: 12px;
    margin-left: 8px;
    vertical-align: middle;
    font-weight: 600;
}

.summary-section {
    margin-bottom: 24px;
}

.summary-section h2 {
    margin-bottom: 14px;
}

.summary-table {
    max-width: 700px;
}

.adjusted-row td {
    background: #fff8e1;
}

.badge-adjusted {
    display: inline-block;
    background: #ff9800;
    color: white;
    font-size: 0.7rem;
    padding: 1px 8px;
    border-radius: 10px;
    margin-left: 6px;
    font-weight: 600;
    vertical-align: middle;
}

.results-section {
    margin-top: 20px;
}

.results-section h2 {
    margin-bottom: 14px;
}

.table-wrapper {
    overflow-x: auto;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    font-size: 0.9rem;
}

.results-table th {
    background: #1a1a2e;
    color: white;
    padding: 12px 14px;
    text-align: left;
    font-weight: 600;
    position: sticky;
    top: 0;
}

.results-table td {
    padding: 10px 14px;
    border-bottom: 1px solid #eee;
}

.results-table .num {
    text-align: center;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.results-table tr.main-group td {
    background: #fff;
}

.results-table tr.alt-group td {
    background: #f7f9fc;
}

.results-table tr.global-row td {
    background: #e8f0fe;
    font-weight: 600;
    border-top: 2px solid #4472C4;
}

.results-table tr:hover td {
    background: #eef3fb;
}

@media (max-width: 768px) {
    .divisions-grid {
        grid-template-columns: 1fr;
    }

    .header-content {
        flex-direction: column;
        align-items: flex-start;
    }

    .actions-section {
        flex-direction: column;
    }

    .btn-lg {
        width: 100%;
        text-align: center;
    }

    .automation-hero {
        align-items: stretch;
        flex-direction: column;
    }

    .search-form {
        flex-direction: column;
    }
}
