:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #e0e7ff;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #d97706;
    --info: #0284c7;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
    --sidebar-active: #4f46e5;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

/* LAYOUT */
.app-container { display: flex; min-height: 100vh; }

/* SIDEBAR */
.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
}
.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid #334155;
}
.sidebar-header h1 {
    font-size: 18px;
    color: #fff;
    font-weight: 700;
}
.sidebar-header p {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 2px;
}
.sidebar-nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: #cbd5e1;
    text-decoration: none;
    font-size: 14px;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}
.sidebar-nav a:hover {
    background: var(--sidebar-hover);
    color: #fff;
}
.sidebar-nav a.active {
    background: rgba(79,70,229,0.15);
    color: #fff;
    border-left-color: var(--primary);
}
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid #334155;
    font-size: 12px;
}
.sidebar-footer a {
    color: #94a3b8;
    text-decoration: none;
}

/* MAIN */
.main-content {
    flex: 1;
    margin-left: 240px;
    padding: 24px;
}

/* PAGE HEADER */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
}

/* CARD */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 16px;
    overflow: hidden;
}
.card-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.card-header h2 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}
.card-body { padding: 20px; }

/* FORM GRID — MULTI-COLUNA RESPONSIVO */
.form-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px 16px;
}
.fg-col-1 { grid-column: span 1; }
.fg-col-2 { grid-column: span 2; }
.fg-col-3 { grid-column: span 3; }
.fg-col-4 { grid-column: span 4; }
.fg-checkbox {
    display: flex;
    align-items: center;
    padding-top: 22px;
}
.fg-btn-add {
    display: flex;
    align-items: flex-end;
}

@media (max-width: 1200px) {
    .form-grid { grid-template-columns: repeat(3, 1fr); }
    .fg-col-4 { grid-column: span 3; }
    .fg-col-3 { grid-column: span 3; }
}
@media (max-width: 900px) {
    .form-grid { grid-template-columns: repeat(2, 1fr); }
    .fg-col-4, .fg-col-3, .fg-col-2 { grid-column: span 2; }
}
@media (max-width: 600px) {
    .form-grid { grid-template-columns: 1fr; }
    .fg-col-1, .fg-col-2, .fg-col-3, .fg-col-4 { grid-column: span 1; }
}

/* FORM ELEMENTS */
.form-group {
    display: flex;
    flex-direction: column;
}
.form-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.form-group input,
.form-group select,
.form-group textarea {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    color: var(--text);
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
    width: 100%;
    font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}
.form-group input[readonly] {
    background: #f1f5f9;
    color: var(--text-muted);
}
.form-group textarea { resize: vertical; }

/* CHECKBOX / RADIO */
.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
}
.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
}
.radio-group {
    display: flex;
    gap: 16px;
    padding-top: 6px;
}
.radio-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    font-size: 14px;
}
.radio-label input[type="radio"] {
    accent-color: var(--primary);
}

/* BUTTONS */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    font-family: inherit;
    white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: 0.9; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { background: #f1f5f9; }
.btn-info { background: var(--info); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-save {
    font-size: 15px;
    padding: 12px;
    margin-bottom: 20px;
}

/* TABLE */
.table {
    width: 100%;
    border-collapse: collapse;
}
.table th {
    text-align: left;
    padding: 10px 12px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    background: #f8fafc;
    letter-spacing: 0.5px;
}
.table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.table tr:hover td { background: #f8fafc; }
.table-compact th, .table-compact td {
    padding: 6px 10px;
    font-size: 13px;
}

/* ALERTS */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
}
.alert-success { background: #dcfce7; color: #166534; }
.alert-error { background: #fee2e2; color: #991b1b; }

/* BADGES */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-warning { background: #fef3c7; color: #92400e; }

.badge-M { background: #dbeafe; color: #1e40af; }
.badge-A { background: #dcfce7; color: #166534; }
.badge-C { background: #fef3c7; color: #92400e; }

.badge-status-aguardando { background: #fef3c7; color: #92400e; }
.badge-status-compareceu { background: #dcfce7; color: #166534; }
.badge-status-atestado { background: #e0f2fe; color: #075985; }
.badge-status-falta_consciente { background: #fee2e2; color: #991b1b; }
.badge-status-falta_justificada { background: #fef3c7; color: #92400e; }
.badge-status-cancelado { background: #fee2e2; color: #991b1b; }
.badge-status-realizado { background: #dcfce7; color: #166534; }
.badge-status-agendado { background: #e0f2fe; color: #075985; }

.badge-fin-pendente { background: #fef3c7; color: #92400e; }
.badge-fin-faturado { background: #dbeafe; color: #1e40af; }
.badge-fin-pago { background: #dcfce7; color: #166534; }
.badge-fin-cancelado { background: #fee2e2; color: #991b1b; }
.badge-reposicao {
    background: #f3e8ff;
    color: #6b21a8;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 8px;
}

/* EMPTY STATE */
.empty-state {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
    font-size: 14px;
}

/* SUB-SECTION */
.sub-section-title {
    color: var(--primary);
    font-size: 14px;
    font-weight: 700;
    margin: 16px 0 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

/* LIST CONTAINER */
.list-container {
    margin-top: 8px;
    min-height: 40px;
    border: 1px dashed var(--border);
    border-radius: 6px;
    padding: 8px;
}
.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    margin-bottom: 4px;
    background: #f0fdf4;
    border-radius: 4px;
    font-size: 13px;
}
.list-item span { flex: 1; }

/* RF INFO */
.rf-info {
    background: #fef3c7;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    color: #92400e;
    margin-bottom: 12px;
}

/* VIEW GRID */
.view-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}
@media (max-width: 768px) {
    .view-grid { grid-template-columns: 1fr; }
}
.view-field {
    display: flex;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid #f1f5f9;
    font-size: 14px;
}
.view-field label {
    min-width: 120px;
    font-weight: 600;
    color: var(--text-muted);
}
.view-field span { flex: 1; }

/* AGENDA */
.agenda-grade {
    width: 100%;
    border-collapse: collapse;
}
.agenda-grade th {
    padding: 10px 8px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    background: #f8fafc;
    letter-spacing: 0.5px;
}
.th-horario { width: 80px; text-align: center; }
.agenda-grade td {
    border: 1px solid var(--border);
    padding: 0;
    vertical-align: top;
}
.td-horario {
    text-align: center;
    font-weight: 700;
    font-size: 15px;
    padding: 12px 8px !important;
    background: #f1f5f9;
    color: var(--primary);
}
.td-slot { min-height: 90px; height: 90px; width: 25%; }
.slot-empty { background: #fafbfc; }
.slot-empty:hover { background: #eff6ff; }
.slot-occupied { background: #f0fdf4; }
.slot-occupied.status-cancelado { background: #fef2f2; opacity: 0.6; }
.slot-occupied.status-compareceu { background: #ecfdf5; }
.slot-occupied.status-atestado { background: #f0f9ff; }
.slot-occupied.status-falta_consciente { background: #fef2f2; }
.slot-occupied.status-falta_justificada { background: #fffbeb; }

.slot-content {
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    height: 100%;
}
.slot-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 4px;
    margin-bottom: 2px;
}
.slot-paciente {
    font-weight: 600;
    font-size: 13px;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.badge-tipo {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 8px;
    white-space: nowrap;
    flex-shrink: 0;
}

.status-select {
    width: 100%;
    padding: 6px 8px;
    font-size: 13px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    margin: 2px 0;
    min-height: 34px;
    font-family: inherit;
    color: var(--text);
}
.status-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(79,70,229,0.1);
}

.slot-actions {
    display: flex;
    gap: 4px;
    margin-top: auto;
}
.btn-slot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 5px 8px;
    font-size: 12px;
    font-weight: 600;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    text-decoration: none;
    min-height: 28px;
    flex: 1;
    transition: all 0.15s;
    font-family: inherit;
}
.btn-cancel { background: #fee2e2; color: #991b1b; }
.btn-cancel:hover { background: #fecaca; }
.btn-remove { background: #f1f5f9; color: #64748b; }
.btn-remove:hover { background: #e2e8f0; }
.btn-anotar { background: #e0f2fe; color: #075985; width: 100%; margin-top: 4px; }
.btn-anotar:hover { background: #bae6fd; }

.slot-add {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 90px;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.15s;
}
.slot-add:hover { background: #eff6ff; color: var(--primary); }
.add-icon { font-size: 20px; font-weight: 300; }
.add-text { font-size: 11px; }
.slot-empty-display {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 90px;
    color: var(--border);
}

/* MODAL */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-card {
    background: #fff;
    border-radius: 10px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; }
.modal-close {
    border: none;
    background: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-muted);
}
.modal-card form { padding: 20px; }

/* DATE NAV */
.date-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}
.date-nav input[type="date"] {
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
}

/* RICH TEXT EDITOR */
.rte-toolbar {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    padding: 6px;
    background: #f1f5f9;
    border: 1px solid var(--border);
    border-radius: 6px 6px 0 0;
    border-bottom: none;
}
.rte-toolbar button {
    padding: 4px 10px;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    min-width: 32px;
}
.rte-toolbar button:hover { background: var(--primary); color: #fff; }
.rte-toolbar input[type="color"] {
    width: 32px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
}
.rte-editor {
    min-height: 150px;
    max-height: 400px;
    overflow-y: auto;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 0 0 6px 6px;
    outline: none;
    font-size: 14px;
    line-height: 1.6;
}
.rte-editor:empty::before {
    content: attr(placeholder);
    color: var(--text-muted);
    pointer-events: none;
}
.rte-editor:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

/* OBS HISTÓRICO */
.obs-historico { max-height: 400px; overflow-y: auto; }
.obs-item {
    padding: 10px;
    margin-bottom: 8px;
    background: #f8fafc;
    border-left: 3px solid var(--primary);
    border-radius: 4px;
}
.obs-meta {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 12px;
    color: var(--text-muted);
}
.obs-content { font-size: 14px; line-height: 1.5; }

/* LOGIN */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e293b 0%, #4f46e5 100%);
}
.login-card {
    background: #fff;
    border-radius: 12px;
    padding: 40px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-header {
    text-align: center;
    margin-bottom: 24px;
}
.login-header h1 {
    font-size: 24px;
    color: var(--primary);
    margin-bottom: 4px;
}
.login-header p {
    color: var(--text-muted);
    font-size: 14px;
}

/* FOTO */
.foto-preview {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
    margin-top: 6px;
}
.foto-placeholder {
    width: 80px;
    height: 80px;
    border: 2px dashed var(--border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 11px;
    margin-top: 6px;
}