/* ============================================================
   Protocolo Facil — "Architectural Blueprint" Design System
   Custom CSS — No framework dependencies
   ============================================================ */

/* --- CSS Custom Properties (Light Theme) --- */
:root,
[data-theme="light"] {
    /* Core palette — slate/teal foundation with amber accent */
    --pf-bg:              #f4f3f0;
    --pf-bg-subtle:       #eae8e4;
    --pf-surface:         #ffffff;
    --pf-surface-hover:   #fafaf8;
    --pf-surface-raised:  #ffffff;
    --pf-border:          #d6d3cc;
    --pf-border-subtle:   #e8e6e1;

    --pf-text:            #1a1916;
    --pf-text-secondary:  #6b6860;
    --pf-text-muted:      #9b978e;

    --pf-primary:         #2d7a6f;
    --pf-primary-hover:   #246b61;
    --pf-primary-subtle:  #e8f5f2;
    --pf-primary-text:    #ffffff;

    --pf-accent:          #c4841d;
    --pf-accent-subtle:   #fef6e8;

    --pf-sidebar-bg:      #1e2a2f;
    --pf-sidebar-text:    #c8cfd2;
    --pf-sidebar-muted:   #7a8a90;
    --pf-sidebar-hover:   rgba(255, 255, 255, 0.06);
    --pf-sidebar-active:  rgba(45, 122, 111, 0.35);
    --pf-sidebar-active-text: #6ee7c0;
    --pf-sidebar-border:  rgba(255, 255, 255, 0.08);

    --pf-success:         #2a9d5c;
    --pf-success-bg:      #e8f8ef;
    --pf-success-border:  #b2e5c8;
    --pf-warning:         #c4841d;
    --pf-warning-bg:      #fef6e8;
    --pf-warning-border:  #f0d9a8;
    --pf-danger:          #c0392b;
    --pf-danger-bg:       #fde8e6;
    --pf-danger-border:   #f0b3ad;
    --pf-info:            #2874a6;
    --pf-info-bg:         #e5f0fa;
    --pf-info-border:     #a8cde8;

    --pf-shadow-sm:       0 1px 2px rgba(0, 0, 0, 0.04);
    --pf-shadow:          0 1px 4px rgba(0, 0, 0, 0.06), 0 0 1px rgba(0, 0, 0, 0.06);
    --pf-shadow-lg:       0 8px 24px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.06);

    --pf-radius-sm:       4px;
    --pf-radius:          6px;
    --pf-radius-lg:       10px;

    --pf-sidebar-width:   260px;
    --pf-transition:      0.2s ease;

    /* Grid pattern for blueprint feel */
    --pf-grid-pattern:    url("data:image/svg+xml,%3Csvg width='40' height='40' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 40V0h40' fill='none' stroke='%23d6d3cc' stroke-width='0.3'/%3E%3C/svg%3E");
}

/* --- Dark Theme --- */
[data-theme="dark"] {
    --pf-bg:              #111416;
    --pf-bg-subtle:       #1a1d20;
    --pf-surface:         #1e2124;
    --pf-surface-hover:   #252830;
    --pf-surface-raised:  #262a2e;
    --pf-border:          #2e3338;
    --pf-border-subtle:   #252930;

    --pf-text:            #e4e2de;
    --pf-text-secondary:  #9b978e;
    --pf-text-muted:      #6b6860;

    --pf-primary:         #3ecfb5;
    --pf-primary-hover:   #34b89f;
    --pf-primary-subtle:  rgba(62, 207, 181, 0.1);
    --pf-primary-text:    #111416;

    --pf-accent:          #e8a644;
    --pf-accent-subtle:   rgba(232, 166, 68, 0.1);

    --pf-sidebar-bg:      #0d1114;
    --pf-sidebar-text:    #c0c8cc;
    --pf-sidebar-muted:   #5a6a70;
    --pf-sidebar-hover:   rgba(255, 255, 255, 0.04);
    --pf-sidebar-active:  rgba(62, 207, 181, 0.15);
    --pf-sidebar-active-text: #3ecfb5;
    --pf-sidebar-border:  rgba(255, 255, 255, 0.06);

    --pf-success:         #3ecfb5;
    --pf-success-bg:      rgba(62, 207, 181, 0.1);
    --pf-success-border:  rgba(62, 207, 181, 0.25);
    --pf-warning:         #e8a644;
    --pf-warning-bg:      rgba(232, 166, 68, 0.1);
    --pf-warning-border:  rgba(232, 166, 68, 0.25);
    --pf-danger:          #e85d4a;
    --pf-danger-bg:       rgba(232, 93, 74, 0.1);
    --pf-danger-border:   rgba(232, 93, 74, 0.25);
    --pf-info:            #5ba3d9;
    --pf-info-bg:         rgba(91, 163, 217, 0.1);
    --pf-info-border:     rgba(91, 163, 217, 0.25);

    --pf-shadow-sm:       0 1px 2px rgba(0, 0, 0, 0.2);
    --pf-shadow:          0 1px 4px rgba(0, 0, 0, 0.3), 0 0 1px rgba(0, 0, 0, 0.2);
    --pf-shadow-lg:       0 8px 24px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);

    --pf-grid-pattern:    url("data:image/svg+xml,%3Csvg width='40' height='40' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 40V0h40' fill='none' stroke='%232e3338' stroke-width='0.3'/%3E%3C/svg%3E");
}

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    height: 100%;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--pf-text);
    background-color: var(--pf-bg);
    background-image: var(--pf-grid-pattern);
    display: grid;
    grid-template-columns: var(--pf-sidebar-width) 1fr;
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow: hidden;
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
    font-family: 'DM Sans', sans-serif;
    font-weight: 600;
    line-height: 1.25;
    color: var(--pf-text);
}

h1 { font-size: 1.75rem; letter-spacing: -0.02em; }
h2 { font-size: 1.35rem; letter-spacing: -0.01em; }
h3 { font-size: 1.1rem; }

p {
    color: var(--pf-text-secondary);
    line-height: 1.6;
}

a {
    color: var(--pf-primary);
    text-decoration: none;
    transition: color var(--pf-transition);
}

a:hover {
    color: var(--pf-primary-hover);
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--pf-border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--pf-text-muted);
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    display: flex;
    flex-direction: column;
    background: var(--pf-sidebar-bg);
    color: var(--pf-sidebar-text);
    height: 100vh;
    overflow-y: auto;
    position: sticky;
    top: 0;
    z-index: 100;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--pf-sidebar-border);
}

.brand-icon {
    color: var(--pf-sidebar-active-text);
    flex-shrink: 0;
}

.brand-name {
    display: block;
    font-weight: 700;
    font-size: 1.05rem;
    color: #ffffff;
    letter-spacing: -0.01em;
}

.brand-sub {
    display: block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    color: var(--pf-sidebar-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: 1px;
}

/* Nav Groups */
.sidebar-nav {
    flex: 1;
    padding: 8px 0;
    overflow-y: auto;
}

.nav-group {
    padding: 0 8px;
}

.nav-group + .nav-group {
    margin-top: 4px;
}

.nav-group-label {
    display: block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.62rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--pf-sidebar-muted);
    padding: 12px 12px 6px;
}

.nav-group ul {
    list-style: none;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--pf-radius);
    color: var(--pf-sidebar-text);
    font-size: 0.875rem;
    font-weight: 400;
    text-decoration: none;
    transition: all 0.15s ease;
    position: relative;
}

.nav-link:hover {
    background: var(--pf-sidebar-hover);
    color: #ffffff;
}

.nav-link.active {
    background: var(--pf-sidebar-active);
    color: var(--pf-sidebar-active-text);
    font-weight: 500;
}

.nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    background: var(--pf-sidebar-active-text);
    border-radius: 0 2px 2px 0;
}

.nav-icon {
    flex-shrink: 0;
    opacity: 0.6;
}

.nav-link:hover .nav-icon,
.nav-link.active .nav-icon {
    opacity: 1;
}

/* Sidebar Footer */
.sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px;
    border-top: 1px solid var(--pf-sidebar-border);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--pf-radius);
    background: var(--pf-sidebar-active);
    color: var(--pf-sidebar-active-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.user-name {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    color: #ffffff;
}

.user-settings-link {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    color: var(--pf-sidebar-muted) !important;
    text-decoration: none;
    letter-spacing: 0.03em;
    transition: color 0.15s;
}

.user-settings-link:hover {
    color: var(--pf-sidebar-active-text) !important;
}

.user-settings-link.active {
    color: var(--pf-sidebar-active-text) !important;
}

/* Theme Toggle Button */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--pf-sidebar-border);
    border-radius: var(--pf-radius);
    background: transparent;
    color: var(--pf-sidebar-muted);
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.theme-toggle:hover {
    background: var(--pf-sidebar-hover);
    color: #ffffff;
    border-color: var(--pf-sidebar-muted);
}

/* Sun/Moon visibility */
[data-theme="light"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun  { display: none; }

/* ============================================================
   MOBILE HEADER
   ============================================================ */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--pf-sidebar-bg);
    color: #ffffff;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 90;
    border-bottom: 1px solid var(--pf-sidebar-border);
}

.mobile-brand {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.01em;
}

.hamburger {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 8px;
    background: none;
    border: none;
    cursor: pointer;
}

.hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: #ffffff;
    border-radius: 1px;
    transition: all 0.25s ease;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 95;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.visible {
    opacity: 1;
}

.mobile-theme {
    border-color: rgba(255,255,255,0.15);
}

/* ============================================================
   MAIN CONTENT AREA
   ============================================================ */
.main-content {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
    padding: 24px 32px;
}

/* Status Bar */
.status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--pf-surface);
    border: 1px solid var(--pf-border-subtle);
    border-radius: var(--pf-radius);
    margin-bottom: 24px;
    box-shadow: var(--pf-shadow-sm);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--pf-text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--pf-success);
    border-radius: 50%;
    flex-shrink: 0;
    animation: pulse-dot 2.5s ease-in-out infinite;
    box-shadow: 0 0 0 3px var(--pf-success-bg);
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.85); }
}

.status-schedule {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    color: var(--pf-text-muted);
    letter-spacing: 0.04em;
    background: var(--pf-bg-subtle);
    padding: 3px 10px;
    border-radius: var(--pf-radius-sm);
}

/* Content Area */
.content-area {
    flex: 1;
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Welcome Screen */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 50vh;
    text-align: center;
    color: var(--pf-text-muted);
}

.welcome-icon {
    margin-bottom: 24px;
    opacity: 0.4;
    color: var(--pf-text-muted);
}

.welcome-screen h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--pf-text);
    margin-bottom: 8px;
}

.welcome-screen p {
    font-size: 0.95rem;
    color: var(--pf-text-muted);
}

/* ============================================================
   MODULE HEADER (used in fragments)
   ============================================================ */
.module-header {
    margin-bottom: 24px;
}

.module-header h2 {
    margin-bottom: 4px;
}

.module-header p {
    font-size: 0.88rem;
    color: var(--pf-text-muted);
    margin: 0;
}

.module-header .module-tag {
    display: inline-block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.62rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 2px 8px;
    border-radius: var(--pf-radius-sm);
    background: var(--pf-primary-subtle);
    color: var(--pf-primary);
    margin-bottom: 8px;
}

/* ============================================================
   CARDS / ARTICLES
   ============================================================ */
.card {
    background: var(--pf-surface);
    border: 1px solid var(--pf-border-subtle);
    border-radius: var(--pf-radius-lg);
    box-shadow: var(--pf-shadow-sm);
    padding: 20px;
    margin-bottom: 16px;
    transition: box-shadow var(--pf-transition);
}

.card:hover {
    box-shadow: var(--pf-shadow);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--pf-border-subtle);
}

.card-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
}

/* ============================================================
   FORMS
   ============================================================ */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--pf-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-family: 'JetBrains Mono', monospace;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 9px 12px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.88rem;
    color: var(--pf-text);
    background: var(--pf-bg);
    border: 1px solid var(--pf-border);
    border-radius: var(--pf-radius);
    outline: none;
    transition: border-color var(--pf-transition), box-shadow var(--pf-transition);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--pf-primary);
    box-shadow: 0 0 0 3px var(--pf-primary-subtle);
}

.form-input::placeholder {
    color: var(--pf-text-muted);
}

.form-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%236b6860' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-textarea {
    resize: vertical;
    min-height: 100px;
}

.field-disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid transparent;
    border-radius: var(--pf-radius);
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
}

.btn-primary {
    background: var(--pf-primary);
    color: var(--pf-primary-text);
    border-color: var(--pf-primary);
}

.btn-primary:hover {
    background: var(--pf-primary-hover);
    border-color: var(--pf-primary-hover);
    box-shadow: var(--pf-shadow-sm);
}

.btn-outline {
    background: transparent;
    color: var(--pf-text-secondary);
    border-color: var(--pf-border);
}

.btn-outline:hover {
    background: var(--pf-bg-subtle);
    border-color: var(--pf-text-muted);
    color: var(--pf-text);
}

.btn-danger-outline {
    background: transparent;
    color: var(--pf-danger);
    border-color: var(--pf-danger-border);
}

.btn-danger-outline:hover {
    background: var(--pf-danger-bg);
    border-color: var(--pf-danger);
}

.btn-secondary {
    background: var(--pf-bg-subtle);
    color: var(--pf-text-secondary);
    border-color: var(--pf-border);
}

.btn-secondary:hover {
    background: var(--pf-border-subtle);
    color: var(--pf-text);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.75rem;
}

.btn.is-loading {
    opacity: 0.7;
    pointer-events: none;
}

/* --- Icon Buttons (Action Column) --- */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--pf-border-subtle);
    border-radius: var(--pf-radius-sm);
    cursor: pointer;
    transition: all 0.18s ease;
    position: relative;
    flex-shrink: 0;
}

.btn-icon svg {
    width: 15px;
    height: 15px;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
    transition: stroke 0.18s ease;
}

.btn-icon:active {
    transform: scale(0.92);
}

/* View — teal/primary */
.btn-icon-view {
    color: var(--pf-text-muted);
}
.btn-icon-view svg {
    stroke: var(--pf-text-muted);
}
.btn-icon-view:hover {
    background: var(--pf-primary-subtle);
    border-color: var(--pf-primary);
    box-shadow: 0 0 0 2px var(--pf-primary-subtle);
}
.btn-icon-view:hover svg {
    stroke: var(--pf-primary);
}

/* Edit — blue/info */
.btn-icon-edit {
    color: var(--pf-text-muted);
}
.btn-icon-edit svg {
    stroke: var(--pf-text-muted);
}
.btn-icon-edit:hover {
    background: var(--pf-info-bg);
    border-color: var(--pf-info);
    box-shadow: 0 0 0 2px var(--pf-info-bg);
}
.btn-icon-edit:hover svg {
    stroke: var(--pf-info);
}

/* Done — green/success */
.btn-icon-done {
    color: var(--pf-text-muted);
}
.btn-icon-done svg {
    stroke: var(--pf-text-muted);
}
.btn-icon-done:hover {
    background: var(--pf-success-bg);
    border-color: var(--pf-success);
    box-shadow: 0 0 0 2px var(--pf-success-bg);
}
.btn-icon-done:hover svg {
    stroke: var(--pf-success);
}

/* Delete — red/danger */
.btn-icon-delete {
    color: var(--pf-text-muted);
}
.btn-icon-delete svg {
    stroke: var(--pf-text-muted);
}
.btn-icon-delete:hover {
    background: var(--pf-danger-bg);
    border-color: var(--pf-danger);
    box-shadow: 0 0 0 2px var(--pf-danger-bg);
}
.btn-icon-delete:hover svg {
    stroke: var(--pf-danger);
}

/* Active/completed state — already done */
.btn-icon-done.is-done {
    background: var(--pf-success-bg);
    border-color: var(--pf-success-border);
}
.btn-icon-done.is-done svg {
    stroke: var(--pf-success);
}

/* ============================================================
   TABLE CONTROLS (search + filter)
   ============================================================ */
.table-controls {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 16px;
}

.table-search {
    flex: 1;
    padding: 8px 12px 8px 36px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.85rem;
    color: var(--pf-text);
    background: var(--pf-surface);
    border: 1px solid var(--pf-border);
    border-radius: var(--pf-radius);
    outline: none;
    transition: border-color var(--pf-transition), box-shadow var(--pf-transition);
    background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239b978e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 10px center;
}

.table-search:focus {
    border-color: var(--pf-primary);
    box-shadow: 0 0 0 3px var(--pf-primary-subtle);
}

.table-search::placeholder {
    color: var(--pf-text-muted);
}

.table-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--pf-text-secondary);
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}

.table-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--pf-primary);
    cursor: pointer;
}

/* ============================================================
   DATA TABLES
   ============================================================ */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--pf-border-subtle);
    border-radius: var(--pf-radius-lg);
    background: var(--pf-surface);
    box-shadow: var(--pf-shadow-sm);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

thead th {
    background: var(--pf-bg-subtle);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--pf-text-muted);
    padding: 10px 14px;
    text-align: left;
    white-space: nowrap;
    border-bottom: 2px solid var(--pf-border);
    position: sticky;
    top: 0;
    z-index: 1;
}

tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--pf-border-subtle);
    vertical-align: middle;
    color: var(--pf-text);
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr {
    transition: background-color 0.1s ease;
}

tbody tr:hover {
    background: var(--pf-surface-hover);
}

/* Sortable Columns */
th.sortable {
    cursor: pointer;
    user-select: none;
    transition: color 0.15s ease;
}

th.sortable:hover {
    color: var(--pf-primary);
}

th.sortable::after {
    content: ' \21C5';
    font-size: 0.7em;
    opacity: 0.3;
}

th.sort-asc::after {
    content: ' \25B2';
    font-size: 0.6em;
    opacity: 1;
    color: var(--pf-primary);
}

th.sort-desc::after {
    content: ' \25BC';
    font-size: 0.6em;
    opacity: 1;
    color: var(--pf-primary);
}

/* Actions Column */
td .actions {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
}

/* ============================================================
   STATUS BADGES
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.68rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    white-space: nowrap;
    border: 1px solid transparent;
}

.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.badge-success {
    background: var(--pf-success-bg);
    color: var(--pf-success);
    border-color: var(--pf-success-border);
}

.badge-success::before {
    background: var(--pf-success);
}

.badge-warning {
    background: var(--pf-warning-bg);
    color: var(--pf-warning);
    border-color: var(--pf-warning-border);
}

.badge-warning::before {
    background: var(--pf-warning);
}

.badge-danger {
    background: var(--pf-danger-bg);
    color: var(--pf-danger);
    border-color: var(--pf-danger-border);
}

.badge-danger::before {
    background: var(--pf-danger);
}

.badge-info {
    background: var(--pf-info-bg);
    color: var(--pf-info);
    border-color: var(--pf-info-border);
}

.badge-info::before {
    background: var(--pf-info);
}

.badge-neutral {
    background: var(--pf-bg-subtle);
    color: var(--pf-text-secondary);
    border-color: var(--pf-border);
}

.badge-neutral::before {
    background: var(--pf-text-muted);
}

/* ============================================================
   EXTERNAL LINKS
   ============================================================ */
a.external-link {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--pf-primary);
    text-decoration: none;
}

a.external-link::after {
    content: '\2197';
    font-size: 0.85em;
}

a.external-link:hover {
    text-decoration: underline;
}

/* ============================================================
   MODAL
   ============================================================ */
.modal {
    border: none;
    background: transparent;
    padding: 0;
    max-width: none;
    max-height: none;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.modal::backdrop {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
}

.modal-content {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 640px;
    max-height: 80vh;
    background: var(--pf-surface);
    border: 1px solid var(--pf-border);
    border-radius: var(--pf-radius-lg);
    box-shadow: var(--pf-shadow-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: translate(-50%, -48%); }
    to   { opacity: 1; transform: translate(-50%, -50%); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--pf-border-subtle);
    background: var(--pf-bg-subtle);
}

.modal-header h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--pf-text-muted);
    cursor: pointer;
    border-radius: var(--pf-radius-sm);
    transition: all 0.15s;
}

.modal-close:hover {
    background: var(--pf-border-subtle);
    color: var(--pf-text);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

/* Loading Spinner */
.loading-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--pf-border);
    border-top-color: var(--pf-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 16px auto;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================================
   DAYS CELL (Dias)
   ============================================================ */
.dias-cell {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--pf-text-muted);
}

/* ============================================================
   CONFIG PAGE SPECIFIC
   ============================================================ */
.config-section + .config-section {
    margin-top: 16px;
}

.avisos-list p {
    padding: 8px 0;
    border-bottom: 1px solid var(--pf-border-subtle);
    font-size: 0.85rem;
}

.avisos-list p:last-child {
    border-bottom: none;
}

.avisos-date {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--pf-primary);
    margin-right: 6px;
}

/* ============================================================
   RESPONSIVE — MOBILE
   ============================================================ */
@media (max-width: 768px) {
    body {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: var(--pf-sidebar-width);
        transform: translateX(-100%);
        z-index: 200;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .mobile-header {
        display: flex;
    }

    .sidebar-overlay {
        display: block;
        pointer-events: none;
    }

    .sidebar-overlay.visible {
        pointer-events: auto;
    }

    .main-content {
        padding: 72px 16px 16px;
        height: auto;
        min-height: 100vh;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .table-controls {
        flex-direction: column;
        align-items: stretch;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 64px 12px 12px;
    }

    .table-wrap {
        border-radius: var(--pf-radius);
    }

    td .actions {
        flex-direction: row;
        gap: 2px;
    }
}

/* ============================================================
   LOADING STATE (HTMX integration)
   ============================================================ */
.is-loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

/* Fragment content fade-in */
.content-area > section {
    animation: fadeIn 0.3s ease;
}

/* ============================================================
   DETAIL GRID (Modal Detalhes)
   ============================================================ */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.detail-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--pf-text-muted);
}

.detail-value {
    font-size: 0.88rem;
    color: var(--pf-text);
}

/* ============================================================
   TRAMITES LIST (Modal Detalhes)
   ============================================================ */
.tramites-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 360px;
    overflow-y: auto;
}

.tramite-item {
    display: flex;
    gap: 12px;
    padding: 10px 12px;
    background: var(--pf-bg-subtle);
    border-radius: 6px;
    font-size: 0.85rem;
}

.tramite-seq {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--pf-primary);
    min-width: 28px;
    padding-top: 2px;
}

.tramite-body {
    flex: 1;
    line-height: 1.45;
}

.tramite-body small {
    color: var(--pf-text-muted);
}

.tramite-parecer {
    margin: 4px 0 2px;
    color: var(--pf-text-secondary);
    font-style: italic;
}
