/* ============================================================
   Sistema de Atestado Médico — Gera Medicina
   Design System — Tema Claro (Light Mode)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* --- Tokens --- */
:root {
    --primary:       #0f766e;
    --primary-dark:  #0d5f58;
    --primary-light: #14b8a6;
    --primary-bg:    #f0fdfa;
    --accent:        #ccfbf1;
    --danger:        #ef4444;
    --warning:       #f59e0b;
    --success:       #10b981;
    --info:          #3b82f6;

    --bg:            #f4f6f9;
    --bg-surface:    #ffffff;
    --bg-card:       #ffffff;
    --bg-hover:      #f8fafc;
    --border:        #e2e8f0;
    --border-focus:  #14b8a6;

    --text-primary:  #1e293b;
    --text-secondary:#475569;
    --text-muted:    #94a3b8;

    --sidebar-w:     260px;
    --radius:        12px;
    --radius-sm:     8px;
    --shadow:        0 1px 6px rgba(0,0,0,.08), 0 2px 16px rgba(0,0,0,.06);
    --shadow-lg:     0 4px 24px rgba(0,0,0,.12);
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #f0fdfa 0%, #e0f2fe 50%, #f8fafc 100%);
}

.login-wrapper {
    width: 100%;
    max-width: 420px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.login-card {
    width: 100%;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow-lg);
}

.login-logo { text-align: center; margin-bottom: 1.5rem; }
.login-logo img { max-height: 70px; margin: 0 auto; }

.login-title {
    font-size: 1.4rem;
    font-weight: 700;
    text-align: center;
    color: var(--text-primary);
}

.login-subtitle {
    font-size: .875rem;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 1.5rem;
}

.login-form { display: flex; flex-direction: column; gap: 1rem; }

.login-footer {
    font-size: .75rem;
    color: var(--text-muted);
    text-align: center;
}

/* ============================================================
   APP LAYOUT
   ============================================================ */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: #ffffff;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
    box-shadow: 2px 0 8px rgba(0,0,0,.04);
}

.sidebar-logo {
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
}
.sidebar-logo img { max-height: 52px; }

.sidebar-user {
    padding: .875rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--primary-bg);
}
.sidebar-user-name {
    font-size: .875rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-role {
    font-size: .75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.role-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: .65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-top: 4px;
}
.role-badge.administrador { background: #ede9fe; color: #7c3aed; }
.role-badge.medico        { background: #d1fae5; color: #065f46; }
.role-badge.auditor       { background: #fef3c7; color: #92400e; }

.sidebar-nav { flex: 1; padding: .5rem 0; }

.nav-label {
    font-size: .65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    padding: .75rem 1.25rem .25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .65rem 1.25rem;
    color: var(--text-secondary);
    font-size: .875rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all .15s ease;
    cursor: pointer;
    text-decoration: none;
}
.nav-link:hover {
    background: var(--bg);
    color: var(--text-primary);
    text-decoration: none;
}
.nav-link.active {
    background: var(--primary-bg);
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 600;
}
.nav-link svg { flex-shrink: 0; }

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
}
.sidebar-footer .nav-link { color: var(--danger); border-radius: var(--radius-sm); }
.sidebar-footer .nav-link:hover { background: #fef2f2; }

/* Main content */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.page-header {
    padding: 1.25rem 2rem;
    border-bottom: 1px solid var(--border);
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 1px 4px rgba(0,0,0,.05);
}

.page-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
}

.page-body {
    padding: 2rem;
    flex: 1;
}

/* ============================================================
   COMPONENTS
   ============================================================ */

/* Cards */
.card {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

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

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    box-shadow: var(--shadow);
    transition: box-shadow .2s, transform .2s;
}
.stat-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.stat-icon {
    width: 42px; height: 42px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
}
.stat-icon.green  { background: #d1fae5; color: #059669; }
.stat-icon.blue   { background: #dbeafe; color: #2563eb; }
.stat-icon.amber  { background: #fef3c7; color: #d97706; }
.stat-icon.violet { background: #ede9fe; color: #7c3aed; }

.stat-value { font-size: 1.9rem; font-weight: 800; color: var(--text-primary); }
.stat-label { font-size: .8rem; color: var(--text-muted); font-weight: 500; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .55rem 1.1rem;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all .15s ease;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.btn:active { transform: translateY(0); box-shadow: none; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; text-decoration: none; }

.btn-secondary {
    background: #f8fafc;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: #f1f5f9; color: var(--text-primary); text-decoration: none; }

.btn-danger  { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; text-decoration: none; }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; color: #fff; text-decoration: none; }

.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #d97706; color: #fff; text-decoration: none; }

.btn-sm { padding: .35rem .75rem; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; padding: .75rem; }
.btn-icon {
    width: 36px; height: 36px; padding: 0;
    justify-content: center; align-items: center;
    border-radius: var(--radius-sm);
}

/* Forms */
.form-group { display: flex; flex-direction: column; gap: .4rem; }
.form-group label {
    font-size: .82rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .4px;
}

.form-input, .form-select, .form-textarea {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .6rem .9rem;
    color: var(--text-primary);
    font-size: .9rem;
    font-family: 'Inter', sans-serif;
    width: 100%;
    transition: border-color .15s, box-shadow .15s;
    outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(20,184,166,.12);
}
.form-select { cursor: pointer; background-color: #ffffff; }
.form-textarea { resize: vertical; min-height: 120px; }

.form-grid { display: grid; gap: 1rem; }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }

.input-eye-wrap { position: relative; }
.input-eye-wrap .form-input { padding-right: 2.75rem; }
.eye-btn {
    position: absolute; right: .75rem; top: 50%; transform: translateY(-50%);
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); display: flex; align-items: center; padding: 0;
}
.eye-btn:hover { color: var(--text-primary); }

/* Alerts */
.alert {
    padding: .75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 500;
    margin-bottom: 1rem;
    display: flex; align-items: center; gap: .5rem;
    border-left: 4px solid;
}
.alert-danger  { background: #fef2f2; color: #b91c1c; border-color: #ef4444; }
.alert-success { background: #f0fdf4; color: #166534; border-color: #22c55e; }
.alert-info    { background: #eff6ff; color: #1e40af; border-color: #3b82f6; }
.alert-warning { background: #fffbeb; color: #92400e; border-color: #f59e0b; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}
.data-table thead th {
    padding: .75rem 1rem;
    text-align: left;
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    background: #f8fafc;
    white-space: nowrap;
}
.data-table tbody tr {
    border-bottom: 1px solid #f1f5f9;
    transition: background .1s;
}
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody td {
    padding: .85rem 1rem;
    color: var(--text-secondary);
    vertical-align: middle;
}
.data-table tbody td strong { color: var(--text-primary); }

.data-table tr.auditado { background: #f0fdf4; }
.data-table tr.auditado:hover { background: #dcfce7; }
.data-table tr.auditado td:first-child {
    border-left: 3px solid var(--success);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: .72rem;
    font-weight: 600;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-danger  { background: #fee2e2; color: #991b1b; }

/* Filter bar */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    align-items: flex-end;
    margin-bottom: 1.25rem;
}
.filter-bar .form-group { min-width: 160px; flex: 1; }

/* Modals */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(15,23,42,.5);
    backdrop-filter: blur(3px);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
    opacity: 0; pointer-events: none;
    transition: opacity .2s ease;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%; max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    transform: translateY(-20px);
    transition: transform .2s ease;
    box-shadow: var(--shadow-lg);
}
.modal-overlay.open .modal { transform: translateY(0); }

.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); }
.modal-close {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; font-size: 1.25rem; line-height: 1;
    transition: color .15s; display: flex; align-items: center;
    width: 28px; height: 28px; border-radius: 6px;
    justify-content: center;
}
.modal-close:hover { color: var(--text-primary); background: var(--bg); }
.modal-footer {
    display: flex; gap: .75rem; justify-content: flex-end;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

/* Checkbox */
.audit-check {
    width: 18px; height: 18px;
    cursor: pointer;
    accent-color: var(--success);
}

/* ============================================================
   ATESTADO PREVIEW / PRINT
   ============================================================ */
.editor-container {
    display: flex;
    justify-content: center;
    padding-bottom: 4rem;
}

.paper-preview {
    background: white;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    position: relative;
    color: black;
    display: flex;
    flex-direction: column;
}

/* A5 Sizing: 148mm x 210mm */
.paper-preview[data-format="A5"] {
    width: 148mm;
    min-height: 210mm;
    padding: 15mm;
}

/* A4 Sizing: 210mm x 297mm */
.paper-preview[data-format="A4"] {
    width: 210mm;
    min-height: 297mm;
    padding: 25mm;
}

.field {
    border: none;
    border-bottom: 1px solid black;
    font-size: inherit;
    font-family: inherit;
    padding: 0 4px;
    text-transform: uppercase;
    background: #f8fafc;
    color: #000;
    outline: none;
    transition: background .15s, border-color .15s;
}
.field:focus {
    background: #e0f2fe;
    border-bottom: 2px solid var(--primary);
}
.field-extenso {
    min-width: 80px;
    display: inline-block;
    border-bottom: 1px solid black;
    text-transform: uppercase;
    text-align: center;
}

.atestado-header {
    text-align: center;
    margin-bottom: 10px;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 90px;
}
.atestado-header img {
    max-width: 130px;
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
}
.atestado-header h2 {
    font-size: 14pt;
    text-decoration: underline;
    text-transform: uppercase;
    color: #000;
}

.atestado-body {
    font-size: 11pt;
    line-height: 1.5;
    text-align: justify;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}
.atestado-body p, .atestado-body div {
    margin-bottom: 10px;
}

.signature-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 40px;
    text-align: center;
    gap: 0;
}
.sig-box {
    width: 100%;
    margin-bottom: 5px;
}
.sig-line {
    border-top: 1px solid black;
    margin: 60px auto 5px auto;
    width: 280px;
    padding-top: 5px;
    font-size: 10pt;
    font-weight: bold;
    color: #000;
}
.auth-section {
    margin-top: auto;
    border-top: 2px dashed #94a3b8;
    padding-top: 10px;
    font-size: 9pt;
}
.auth-section h3 {
    font-size: 10pt;
    text-align: center;
    color: #000;
    margin-bottom: 5px;
}

/* History list */
.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .85rem 1.25rem;
    border-bottom: 1px solid #f1f5f9;
    gap: 1rem;
    transition: background .1s;
}
.history-item:hover { background: #f8fafc; }
.history-item:last-child { border-bottom: none; }
.history-info { flex: 1; }
.history-info strong { display: block; color: var(--text-primary); font-size: .9rem; }
.history-info small { color: var(--text-muted); font-size: .78rem; }
.history-actions { display: flex; gap: .5rem; flex-shrink: 0; }

#print-area { display: none; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    :root { --sidebar-w: 0px; }
    .sidebar { transform: translateX(-260px); }
    .sidebar.open { transform: translateX(0); width: 260px; }
    .main-content { margin-left: 0; }
    .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
    .page-body { padding: 1rem; }
}

/* ============================================================
   PRINT
   ============================================================ */
@media print {
    html, body { 
        background: white !important; 
        height: 99vh !important;
        max-height: 99vh !important;
        overflow: hidden !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    .app-layout { display: none !important; }
    
    #print-area { 
        display: block !important; 
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 95vh !important; 
        max-height: 95vh !important;
        overflow: hidden !important;
        page-break-inside: avoid;
    }
    #print-area * { visibility: visible; }
    
    .paper-preview {
        box-shadow: none !important;
        margin: 0 !important;
        border: none !important;
        width: 100% !important;
        height: 100% !important;
        padding: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        page-break-inside: avoid !important;
        page-break-after: avoid !important;
    }
    
    .field {
        background: transparent !important;
        border-bottom: none !important;
    }

    @page {
        margin: 10mm;
    }

    /* Print specific scaling */
    .atestado-header { margin-bottom: 5px !important; min-height: 70px !important; }
    .atestado-header h2 { font-size: 14pt !important; }
    .atestado-body { font-size: 11.5pt !important; line-height: 1.4 !important; }
    .atestado-body p, .atestado-body div { margin-bottom: 6px !important; }
    .signature-section { margin-top: 25px !important; }
    .sig-line { font-size: 10pt !important; margin-top: 50px !important; }
    .auth-section { font-size: 9pt !important; padding-top: 6px !important; }
    .auth-section h3 { font-size: 10pt !important; margin-bottom: 3px !important; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
