:root {
  color-scheme: dark;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-strong: #1f2937;
  --text: #111827;
  --muted: #64748b;
  --muted-strong: #475569;
  --border: rgba(15, 23, 42, 0.12);
  --accent: #0f74ff;
  --accent-soft: #dbeafe;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #f59e0b;
  --card-shadow: 0 24px 60px rgba(15, 23, 42, 0.08);
  --radius: 24px;
  --radius-sm: 16px;
  --font: 'Inter', sans-serif;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: linear-gradient(180deg, #e7eefb 0%, #f8fbff 100%);
}

* {
  box-sizing: border-box;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

img,
svg {
  display: block;
  max-width: 100%;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.96) 0%, #111827 100%);
  color: #f8fafc;
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  background: #0ea5e9;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  font-weight: 800;
  color: white;
}

.sidebar h1 {
  margin: 0;
  font-size: 1.25rem;
}

.sidebar p {
  margin: 4px 0 0;
  color: #cbd5e1;
  font-size: 0.95rem;
}

.nav-menu {
  display: grid;
  gap: 10px;
}

.nav-link {
  border: none;
  width: 100%;
  text-align: left;
  padding: 14px 18px;
  border-radius: 18px;
  background: transparent;
  color: inherit;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: background 0.25s ease, transform 0.15s ease;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(255, 255, 255, 0.08);
  transform: translateX(4px);
}

.nav-icon {
  font-size: 1.2rem;
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 20px;
}

.sidebar-footer p {
  margin: 0 0 12px;
  color: #94a3b8;
}

.mobile-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease;
  z-index: 35;
}

body.sidebar-open .mobile-backdrop {
  opacity: 1;
  visibility: visible;
}

.mobile-menu {
  display: none;
  border-radius: 16px;
  margin-right: 12px;
}

.btn-secondary,
.link-button,
.chip,
.btn-primary {
  border: none;
  border-radius: 18px;
  padding: 12px 18px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  transition: transform 0.18s ease, background-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
}

.btn-primary {
  background: #13b77f;
  color: white;
}

.btn-primary:hover {
  background: #10a16a;
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.16);
}

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

.btn-secondary:hover {
  background: #1f2937;
  transform: translateY(-1px);
}

.btn-secondary:active {
  transform: translateY(0);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.16);
}

.link-button {
  background: transparent;
  color: var(--accent);
  padding: 10px 14px;
  border-radius: 14px;
}

.link-button:hover {
  background: rgba(15, 23, 42, 0.05);
}

.chip {
  background: rgba(15, 23, 42, 0.06);
  color: var(--text);
}

.btn-edit,
button[data-action="edit"],
button[data-action="edit-client"] {
  background: #2563eb;
  color: white;
}

.btn-edit:hover,
button[data-action="edit"]:hover,
button[data-action="edit-client"]:hover {
  background: #1d4ed8;
}

.btn-delete,
button[data-action="delete"],
button[data-action="delete-client"],
#confirmDelete {
  background: #dc2626;
  color: white;
}

.btn-delete:hover,
button[data-action="delete"]:hover,
button[data-action="delete-client"]:hover,
#confirmDelete:hover {
  background: #b91c1c;
}

.btn-sign,
button[data-action="sign"],
button[data-action="confirm-sign"],
#btnAddSignature {
  background: #0f62fe;
  color: white;
}

.btn-sign:hover,
button[data-action="sign"]:hover,
button[data-action="confirm-sign"]:hover,
#btnAddSignature:hover {
  background: #0b4ddb;
}

.btn-download,
button[data-action="download-sign"] {
  background: #5b21b6;
  color: white;
}

.btn-download:hover,
button[data-action="download-sign"]:hover {
  background: #4c1d95;
}

.btn-save,
#saveSignature,
button[type="submit"] {
  background: #13b77f;
  color: white;
}

.btn-save:hover,
#saveSignature:hover,
button[type="submit"]:hover {
  background: #0f9d68;
}

.btn-cancel,
button[id^="cancel"],
#cancelSignature,
#cancelDoc,
#cancelClient,
#cancelDelete {
  background: #475569;
  color: white;
}

.btn-cancel:hover,
button[id^="cancel"]:hover,
#cancelSignature:hover,
#cancelDoc:hover,
#cancelClient:hover,
#cancelDelete:hover {
  background: #334155;
}

.btn-add,
#btnNewDocument,
#btnNewClient,
#btnAddDocumentMobile,
#btnResetData,
button[data-action="replace-signature"] {
  background: #13b77f;
  color: white;
}

.btn-add:hover,
#btnNewDocument:hover,
#btnNewClient:hover,
#btnAddDocumentMobile:hover,
#btnResetData:hover,
button[data-action="replace-signature"]:hover {
  background: #10a16a;
}

.dashboard-shell {
  background: transparent;
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: 24px 32px 18px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.search-group {
  display: flex;
  gap: 8px;
  flex: 1;
  max-width: 560px;
}

.search-group input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px 18px;
  outline: none;
  transition: border-color 0.2s ease;
}

.search-group input:focus {
  border-color: var(--accent);
}

.icon-button {
  border: none;
  background: rgba(15, 23, 42, 0.06);
  border-radius: 16px;
  padding: 12px 14px;
  color: var(--text);
  position: relative;
}

.badge {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--danger);
  color: white;
  font-size: 0.7rem;
}

.profile-pill {
  display: grid;
  gap: 2px;
  padding: 12px 18px;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.06);
  align-items: center;
}

.profile-pill strong {
  display: block;
}

.page-content {
  padding: 32px;
  display: grid;
  gap: 24px;
}

.page-panel {
  display: none;
  gap: 24px;
}

.page-panel.active {
  display: grid;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
}

.page-header.split {
  align-items: center;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent);
  font-size: 0.82rem;
}

.page-header h2,
.page-header h3,
.page-header h4,
.page-header h1 {
  margin: 0;
}

.page-header p {
  margin: 10px 0 0;
  color: var(--muted);
  max-width: 640px;
}

.stats-grid,
.grid-two-column,
.grid-three-column,
.profile-grid {
  display: grid;
  gap: 20px;
}

.stats-grid {
  grid-template-columns: repeat(4, minmax(180px, 1fr));
}

.stat-card,
.panel-card,
.mini-card,
.profile-card {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--card-shadow);
  padding: 24px;
}

.stat-card strong {
  display: block;
  margin-top: 18px;
  font-size: 2.2rem;
}

.panel-card .panel-header,
.activity-card .panel-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 20px;
}

.panel-actions {
  display: flex;
  gap: 10px;
}

.table-wrapper {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 16px 18px;
  border-bottom: 1px solid #e2e8f0;
}

.data-table th {
  color: var(--muted-strong);
  font-weight: 600;
}

.data-table tbody tr:hover {
  background: rgba(15, 23, 42, 0.04);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
}

.badge-pending {
  background: rgba(245, 158, 11, 0.12);
  color: #b45309;
}

.badge-signed {
  background: rgba(16, 185, 129, 0.12);
  color: #15803d;
}

.badge-rejected {
  background: rgba(220, 38, 38, 0.12);
  color: #991b1b;
}

.badge-expired {
  background: rgba(248, 113, 113, 0.12);
  color: #b91c1c;
}

.activity-list,
.agenda-list,
.info-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 14px;
}

.activity-item,
.agenda-item,
.info-item {
  display: grid;
  gap: 8px;
  padding: 18px;
  border-radius: 20px;
  background: #f8fbff;
  border: 1px solid #e2e8f0;
}

.activity-item strong,
.agenda-item strong,
.info-item strong {
  font-size: 1rem;
}

.activity-item span,
.agenda-item span,
.info-item span {
  color: var(--muted);
  font-size: 0.95rem;
}

.signature-grid {
  display: grid;
  gap: 20px;
}

.signature-card {
  display: grid;
  gap: 18px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border);
  padding: 24px;
  border-radius: var(--radius-sm);
}

.signature-card h4 {
  margin: 0;
}

.signature-info {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.signature-info span {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  color: var(--muted);
}

.signature-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.signature-actions .btn-primary,
.signature-actions .btn-secondary {
  padding: 12px 18px;
}

.agenda-board {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.agenda-card {
  border-radius: 22px;
  padding: 20px;
  background: linear-gradient(180deg, #eff6ff 0%, #e0f2fe 100%);
  border: 1px solid #b6e0fe;
}

.agenda-card h4,
.agenda-card p {
  margin: 0;
}

.profile-grid {
  grid-template-columns: repeat(2, minmax(240px, 1fr));
}

.profile-card dl {
  margin: 18px 0 0;
}

.profile-card dt {
  font-weight: 600;
  color: var(--muted-strong);
}

.profile-card dd {
  margin: 6px 0 14px;
  color: var(--text);
}

.profile-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: none;
  place-items: center;
  padding: 24px;
  z-index: 30;
}

.modal-overlay.active {
  display: grid;
}

.modal {
  width: min(680px, 100%);
  background: white;
  border-radius: 28px;
  box-shadow: var(--card-shadow);
  overflow: hidden;
}

.signature-modal {
  display: grid;
  gap: 18px;
}

.signature-form-row {
  display: grid;
  gap: 12px;
}

.signature-canvas-container {
  position: relative;
  overflow: hidden;
  border-radius: 24px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: #f8fbff;
  min-height: 280px;
  display: grid;
  align-items: center;
  justify-items: center;
  padding: 12px;
}

.signature-canvas-container canvas {
  width: 100%;
  height: 100%;
  border-radius: 20px;
  background: white;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.08);
}

.canvas-label {
  position: absolute;
  top: 18px;
  left: 20px;
  background: rgba(255, 255, 255, 0.9);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.88rem;
  color: var(--muted-strong);
  z-index: 2;
}

.signature-preview-large-container {
  display: grid;
  gap: 10px;
  align-items: center;
}

.signature-preview-large-container span {
  color: var(--muted-strong);
  font-size: 0.95rem;
}

.signature-preview-large {
  width: 100%;
  max-height: 180px;
  border-radius: 18px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  object-fit: contain;
}

.signature-placeholder {
  padding: 18px;
  text-align: center;
  border-radius: 18px;
  background: #f1f5f9;
  color: var(--muted-strong);
}

.signature-actions-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.signature-actions-row .btn-secondary,
.signature-actions-row .btn-primary {
  min-height: 52px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 22px 24px;
  border-bottom: 1px solid #e2e8f0;
}

.modal-body {
  padding: 24px;
  display: grid;
  gap: 18px;
}

.close-button {
  border: none;
  background: transparent;
  font-size: 1.2rem;
}

.form-grid {
  display: grid;
  gap: 16px;
}

.form-row {
  display: grid;
  gap: 16px;
}

.form-row input,
.form-row select,
.form-row textarea {
  padding: 14px 16px;
  border: 1px solid #cbd5e1;
  border-radius: 16px;
  width: 100%;
  outline: none;
}

.form-row textarea {
  min-height: 120px;
  resize: vertical;
}

.form-row label {
  font-weight: 600;
  color: var(--muted-strong);
}

.toast-container {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: grid;
  gap: 12px;
  z-index: 40;
}

.toast {
  min-width: 280px;
  background: rgba(15, 23, 42, 0.96);
  color: white;
  padding: 16px 18px;
  border-radius: 18px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  animation: slideIn 0.35s ease;
}

.toast button {
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(18px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    z-index: 40;
    box-shadow: 24px 0 80px rgba(15, 23, 42, 0.14);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .dashboard-shell { grid-row: 1; }
  .sidebar { grid-row: 2; }
  .mobile-menu { display: inline-flex; }
  .page-content { padding: 24px; }
  .stats-grid { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
  .profile-grid { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .topbar { flex-direction: column; align-items: stretch; padding: 20px; }
  .search-group { width: 100%; }
  .page-header { flex-direction: column; }
  .grid-two-column { grid-template-columns: 1fr; }
  .grid-three-column { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
  .sidebar { padding: 24px 18px; width: 100%; }
  .nav-link { padding: 14px 16px; }
  .signature-actions-row { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .topbar { padding: 18px; }
  .page-content { padding: 18px; }
  .modal { width: 100%; }
  .activity-item,
  .agenda-item,
  .info-item { padding: 16px; }
  .signature-canvas-container { min-height: 220px; }
  .signature-actions-row { gap: 10px; }
}

.dark-mode {
  --bg: #0b1120;
  --surface: #111827;
  --surface-strong: #0f172a;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --muted-strong: #cbd5e1;
  --border: rgba(148, 163, 184, 0.18);
  --accent-soft: rgba(14, 116, 255, 0.14);
}

.dark-mode body,
.dark-mode .app-shell {
  background: linear-gradient(180deg, #020617 0%, #0c152d 100%);
}

.dark-mode .sidebar,
.dark-mode .modal,
.dark-mode .panel-card,
.dark-mode .stat-card,
.dark-mode .mini-card,
.dark-mode .profile-card,
.dark-mode .signature-card,
.dark-mode .agenda-card,
.dark-mode .activity-item,
.dark-mode .agenda-item,
.dark-mode .info-item {
  background: #111827;
  color: var(--text);
}

.dark-mode .search-group input,
.dark-mode .form-row input,
.dark-mode .form-row select,
.dark-mode .form-row textarea {
  background: #111827;
  color: var(--text);
  border-color: rgba(148, 163, 184, 0.2);
}

.dark-mode .btn-secondary,
.dark-mode .link-button,
.dark-mode .chip {
  background: rgba(255, 255, 255, 0.05);
  color: #e2e8f0;
}

.dark-mode .topbar,
.dark-mode .table-wrapper {
  background: transparent;
}

.dark-mode .data-table th,
.dark-mode .data-table td {
  border-color: rgba(148, 163, 184, 0.14);
}

.dark-mode .panel-card,
.dark-mode .mini-card,
.dark-mode .profile-card,
.dark-mode .signature-card,
.dark-mode .agenda-card {
  border-color: rgba(148, 163, 184, 0.12);
}
