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

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --info: #0891b2;
  --info-light: #ecfeff;
  --sidebar: #0f172a;
  --sidebar-hover: #1e293b;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --bg: #f8fafc;
  --white: #ffffff;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

/* === LOGIN PAGE === */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%); }
.login-card { background: var(--white); border-radius: 16px; padding: 48px; width: 400px; box-shadow: var(--shadow-lg); }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo h1 { font-size: 28px; font-weight: 800; color: var(--primary); letter-spacing: -0.5px; }
.login-logo p { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.login-card h2 { font-size: 20px; font-weight: 600; margin-bottom: 24px; }

/* === LAYOUT === */
.app-layout { display: flex; min-height: 100vh; }
.sidebar { width: 240px; background: var(--sidebar); color: #94a3b8; display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh; z-index: 100; }
.sidebar-logo { padding: 20px 20px 16px; border-bottom: 1px solid #1e293b; }
.sidebar-logo h1 { font-size: 20px; font-weight: 800; color: var(--white); letter-spacing: -0.3px; }
.sidebar-logo p { font-size: 11px; color: #475569; margin-top: 2px; }
.sidebar-user { padding: 16px 20px; border-bottom: 1px solid #1e293b; display: flex; align-items: center; gap: 10px; }
.sidebar-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 700; color: white; font-size: 15px; flex-shrink: 0; }
.sidebar-user-info { min-width: 0; }
.sidebar-user-info strong { display: block; color: var(--white); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-info small { font-size: 11px; color: #64748b; }
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-section { padding: 8px 20px 4px; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: #334155; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 20px; color: #94a3b8; text-decoration: none; cursor: pointer; transition: background 0.15s, color 0.15s; border: none; background: none; width: 100%; font-size: 13.5px; }
.nav-item:hover { background: #1e293b; color: var(--white); }
.nav-item.active { background: var(--primary); color: var(--white); }
.nav-item .icon { font-size: 16px; flex-shrink: 0; width: 18px; text-align: center; }
.nav-badge { margin-left: auto; background: var(--danger); color: white; font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 10px; min-width: 18px; text-align: center; }
.sidebar-bottom { padding: 12px 0; border-top: 1px solid #1e293b; }
.main-content { margin-left: 240px; flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.top-bar { background: var(--white); border-bottom: 1px solid var(--border); padding: 12px 24px; display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 50; }
.top-bar-title { font-size: 16px; font-weight: 600; flex: 1; }
.page-content { padding: 24px; flex: 1; }

/* === CARDS === */
.card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-header h3 { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }

/* === STATS === */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stat-card .stat-label { font-size: 12px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card .stat-value { font-size: 32px; font-weight: 700; margin: 4px 0; line-height: 1; }
.stat-card .stat-sub { font-size: 12px; color: var(--text-muted); }
.stat-card.blue .stat-value { color: var(--primary); }
.stat-card.green .stat-value { color: var(--success); }
.stat-card.amber .stat-value { color: var(--warning); }
.stat-card.red .stat-value { color: var(--danger); }

/* === FORMS === */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text); }
.form-control { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; color: var(--text); background: var(--white); transition: border-color 0.15s, box-shadow 0.15s; }
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-row { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }

/* === BUTTONS === */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 6px; font-size: 13.5px; font-weight: 500; cursor: pointer; border: 1px solid transparent; transition: all 0.15s; white-space: nowrap; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; border-color: var(--success); }
.btn-success:hover:not(:disabled) { background: #15803d; }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-warning { background: var(--warning); color: white; border-color: var(--warning); }
.btn-warning:hover:not(:disabled) { background: #b45309; }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover:not(:disabled) { background: var(--primary-light); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }
.btn-icon { padding: 7px; }

/* === BADGES / STATUS === */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 500; white-space: nowrap; }
.badge-incoming { background: #f1f5f9; color: #475569; }
.badge-in_review { background: #eff6ff; color: #2563eb; }
.badge-in_progress { background: #fffbeb; color: #d97706; }
.badge-pending_signature { background: #fdf4ff; color: #9333ea; }
.badge-signed { background: #f0fdf4; color: #16a34a; }
.badge-rejected { background: #fef2f2; color: #dc2626; }
.badge-archived { background: #f8fafc; color: #94a3b8; }
.badge-admin { background: #0f172a; color: white; }
.badge-secretary { background: #0369a1; color: white; }
.badge-manager { background: #0891b2; color: white; }
.badge-responsible { background: #7c3aed; color: white; }
.badge-viewer { background: #475569; color: white; }

/* === DOCUMENT CARDS === */
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.doc-card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); cursor: pointer; transition: box-shadow 0.15s, border-color 0.15s; }
.doc-card:hover { box-shadow: var(--shadow-md); border-color: #cbd5e1; }
.doc-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.doc-card-title { font-size: 14px; font-weight: 600; line-height: 1.4; }
.doc-card-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.doc-card-footer { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--text-muted); border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px; }
.doc-type-icon { font-size: 20px; }

/* === TABLE === */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead { background: var(--bg); }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13.5px; }
th { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; white-space: nowrap; }
tr:hover td { background: #fafafa; }

/* === MODAL === */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--white); border-radius: 12px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal-lg { max-width: 760px; }
.modal-header { padding: 20px 24px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); padding: 2px; line-height: 1; }

/* === UPLOAD ZONE === */
.upload-zone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 32px; text-align: center; cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--primary); background: var(--primary-light); }
.upload-zone input { display: none; }
.upload-zone p { color: var(--text-muted); font-size: 13px; }
.upload-zone strong { display: block; font-size: 15px; margin-bottom: 4px; color: var(--text); }

/* === NOTIFICATIONS === */
.notif-panel { position: absolute; top: 52px; right: 0; width: 340px; background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); z-index: 300; max-height: 420px; overflow-y: auto; }
.notif-item { padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.notif-item:hover { background: var(--bg); }
.notif-item.unread { background: var(--primary-light); }
.notif-item.unread:hover { background: #dbeafe; }
.notif-item strong { display: block; font-size: 13px; }
.notif-item p { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.notif-item time { font-size: 11px; color: #94a3b8; margin-top: 4px; display: block; }

/* === LOG / TIMELINE === */
.timeline { position: relative; }
.timeline-item { display: flex; gap: 12px; padding-bottom: 16px; }
.timeline-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); margin-top: 5px; flex-shrink: 0; position: relative; }
.timeline-dot::after { content: ''; position: absolute; left: 3px; top: 8px; width: 2px; background: var(--border); height: calc(100% + 8px); }
.timeline-item:last-child .timeline-dot::after { display: none; }
.timeline-content strong { display: block; font-size: 13px; }
.timeline-content p { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.timeline-content time { font-size: 11px; color: #94a3b8; }

/* === ALERTS & TOAST === */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 16px; border-radius: var(--radius); box-shadow: var(--shadow-md); font-size: 13.5px; display: flex; align-items: center; gap: 8px; animation: slideIn 0.25s ease; max-width: 320px; }
.toast-success { background: var(--success); color: white; }
.toast-error { background: var(--danger); color: white; }
.toast-info { background: var(--primary); color: white; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* === UTILITIES === */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.font-bold { font-weight: 700; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.text-center { text-align: center; }
.relative { position: relative; }

/* === EMPTY STATE === */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty-state p { font-size: 13.5px; }

/* === SEARCH BAR === */
.search-bar { display: flex; gap: 8px; align-items: center; }
.search-bar input { flex: 1; }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

/* === SIGNATURE BLOCK === */
.signature-block { background: var(--success-light); border: 1px solid #bbf7d0; border-radius: var(--radius); padding: 12px 16px; font-size: 13px; }
.signature-block strong { display: block; color: var(--success); margin-bottom: 2px; }

/* === SCROLLBAR === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* === RESPONSIVE === */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.3s; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .doc-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* === DOCUMENT DETAIL === */
.doc-detail-header { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; margin-bottom: 20px; }
.doc-detail-title { font-size: 22px; font-weight: 700; margin-bottom: 12px; }
.doc-detail-meta { display: flex; flex-wrap: wrap; gap: 16px; font-size: 13px; color: var(--text-muted); }
.doc-detail-meta span { display: flex; align-items: center; gap: 4px; }
.doc-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.section-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

/* === ADMIN TABLE ACTIONS === */
.action-cell { display: flex; gap: 4px; }
.user-row-info { display: flex; align-items: center; gap: 8px; }
.user-avatar-sm { width: 28px; height: 28px; border-radius: 50%; background: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: white; flex-shrink: 0; }
