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

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #dc2626;
  --border: #e5e7eb;
  --surface: #ffffff;
  --muted: #f3f4f6;
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --color-surface: var(--surface);
  --color-border: var(--border);
  --color-primary: var(--primary);
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  font-size: 14px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f9fafb;
  color: var(--text-primary);
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  color: var(--primary);
}

button,
input,
select,
textarea {
  font: inherit;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  border-radius: 0.5rem;
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.btn:focus {
  outline: 2px solid transparent;
  box-shadow: 0 0 0 3px rgb(37 99 235 / 0.25);
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
  color: #ffffff;
}

.btn-secondary {
  background: #f3f4f6;
  border-color: #d1d5db;
  color: #1f2937;
}

.btn-secondary:hover {
  background: #e5e7eb;
  color: #111827;
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

.btn-danger:hover {
  background: #b91c1c;
  color: #ffffff;
}

.btn-sm {
  min-height: 2rem;
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
}

.card {
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.06);
}

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

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.5rem;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: capitalize;
}

.badge-success,
.badge-approved {
  background: #dcfce7;
  color: #166534;
}

.badge-warning,
.badge-draft,
.badge-submitted,
.badge-in_approval {
  background: #fef3c7;
  color: #92400e;
}

.badge-danger,
.badge-rejected,
.badge-overdue {
  background: #fee2e2;
  color: #991b1b;
}

.form-label {
  display: block;
  margin-bottom: 0.375rem;
  color: #374151;
  font-size: 0.875rem;
  font-weight: 600;
}

.form-input {
  width: 100%;
  min-height: 2.5rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  background: #ffffff;
  color: var(--text-primary);
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(37 99 235 / 0.18);
}

.form-group {
  margin-bottom: 1rem;
}

.toast {
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  color: #ffffff;
  box-shadow: 0 10px 24px rgb(15 23 42 / 0.18);
}

.login-page > nav,
.login-page aside {
  display: none;
}

.login-page > .flex {
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
}

.login-page main {
  flex: 0 1 32rem;
  width: 100%;
  padding: 0;
}

.admin-config-page aside {
  display: none;
}

.admin-config-page main {
  width: 100%;
  max-width: 72rem;
  margin: 0 auto;
}

.login-page .card {
  margin-top: 0;
}

.auth-card {
  width: 100%;
  max-width: 34rem;
}

.auth-header {
  margin-bottom: 1.5rem;
}

.auth-header > * {
  margin-top: 0;
  margin-bottom: 0.375rem;
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.25rem;
  padding: 0.25rem;
  margin-bottom: 1.25rem;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
}

.auth-tab {
  min-height: 2.25rem;
  border: 0;
  border-radius: 0.375rem;
  background: transparent;
  color: #4b5563;
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
}

.auth-tab.active {
  background: #ffffff;
  color: #1d4ed8;
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.08);
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.25rem 0;
  color: #6b7280;
  font-size: 0.875rem;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #e5e7eb;
}

.skeleton {
  background: #e5e7eb;
  border-radius: 0.5rem;
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.bg-gray-50 { background-color: #f9fafb; }
.bg-white { background-color: #ffffff; }
.bg-gray-100 { background-color: #f3f4f6; }
.bg-gray-200 { background-color: #e5e7eb; }
.bg-blue-600 { background-color: #2563eb; }
.bg-green-500 { background-color: #22c55e; }
.bg-yellow-400 { background-color: #facc15; }
.bg-orange-500 { background-color: #f97316; }
.bg-red-500 { background-color: #ef4444; }
.bg-red-600 { background-color: #dc2626; }
.bg-black\/40 { background-color: rgb(0 0 0 / 0.4); }

.text-white { color: #ffffff; }
.text-gray-500 { color: #6b7280; }
.text-gray-600 { color: #4b5563; }
.text-gray-700 { color: #374151; }
.text-gray-900 { color: #111827; }
.text-blue-700 { color: #1d4ed8; }

.text-xs { font-size: 0.75rem; line-height: 1rem; }
.text-sm { font-size: 0.875rem; line-height: 1.25rem; }
.text-lg { font-size: 1.125rem; line-height: 1.75rem; }
.text-xl { font-size: 1.25rem; line-height: 1.75rem; }
.text-2xl { font-size: 1.5rem; line-height: 2rem; }
.text-3xl { font-size: 1.875rem; line-height: 2.25rem; }

.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

.block { display: block; }
.hidden { display: none !important; }
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }

.flex-1 { flex: 1 1 0%; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }

.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }

.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }

.space-y-2 > * + * { margin-top: 0.5rem; }
.space-y-4 > * + * { margin-top: 1rem; }
.space-y-6 > * + * { margin-top: 1.5rem; }

.fixed { position: fixed; }
.absolute { position: absolute; }
.relative { position: relative; }
.sticky { position: sticky; }
.inset-0 { inset: 0; }
.top-0 { top: 0; }
.-top-1 { top: -0.25rem; }
.-right-1 { right: -0.25rem; }
.right-4 { right: 1rem; }
.bottom-4 { bottom: 1rem; }

.z-40 { z-index: 40; }
.z-50 { z-index: 50; }

.mx-auto { margin-left: auto; margin-right: auto; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mt-10 { margin-top: 2.5rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }

.p-4 { padding: 1rem; }
.p-6 { padding: 1.5rem; }
.px-3 { padding-left: 0.75rem; padding-right: 0.75rem; }
.px-6 { padding-left: 1.5rem; padding-right: 1.5rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-3 { padding-top: 0.75rem; padding-bottom: 0.75rem; }

.w-4 { width: 1rem; }
.w-6 { width: 1.5rem; }
.w-8 { width: 2rem; }
.w-64 { width: 16rem; }
.w-full { width: 100%; }
.h-2 { height: 0.5rem; }
.h-4 { height: 1rem; }
.h-6 { height: 1.5rem; }
.h-8 { height: 2rem; }
.min-h-screen { min-height: 100vh; }
.max-w-md { max-width: 28rem; }
.max-w-lg { max-width: 32rem; }

.rounded { border-radius: 0.25rem; }
.rounded-lg { border-radius: 0.5rem; }
.rounded-full { border-radius: 999px; }

.border { border: 1px solid var(--border); }
.border-b { border-bottom: 1px solid var(--border); }
.border-r { border-right: 1px solid var(--border); }
.border-gray-200 { border-color: #e5e7eb; }

.shadow-xl { box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1); }

.cursor-pointer { cursor: pointer; }
.overflow-x-auto { overflow-x: auto; }
.whitespace-nowrap { white-space: nowrap; }

.hover\:bg-gray-100:hover { background-color: #f3f4f6; }
.hover\:shadow-lg:hover { box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1); }

@media (min-width: 640px) {
  .sm\:flex-row { flex-direction: row; }
}

@media (min-width: 768px) {
  .md\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .md\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .md\:col-span-2 { grid-column: span 2 / span 2; }
}

@media (min-width: 1024px) {
  .lg\:block { display: block; }
  .lg\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 1280px) {
  .xl\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@keyframes pulse {
  50% {
    opacity: 0.5;
  }
}

.admin-config {
  display: grid;
  gap: 1.5rem;
}

.admin-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem 0 0.5rem;
}

.admin-hero p,
.admin-hero h1 {
  margin-top: 0;
  margin-bottom: 0.25rem;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(20rem, 0.95fr);
  gap: 1rem;
  align-items: start;
}

.admin-inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 7rem auto;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.workflow-type-list {
  display: grid;
  gap: 0.75rem;
}

.workflow-type-item {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: #ffffff;
  overflow: hidden;
}

.workflow-type-toggle {
  width: 100%;
  min-height: 4rem;
  border: 0;
  background: #ffffff;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  cursor: pointer;
  text-align: left;
}

.workflow-type-toggle:hover {
  background: #f9fafb;
}

.workflow-type-panel {
  border-top: 1px solid var(--border);
  padding: 1rem;
  background: #f9fafb;
}

.chain-list {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.chain-item {
  padding: 0.75rem;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
  background: #ffffff;
}

.csv-workflow-detail {
  display: grid;
  gap: 0.75rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.step-list {
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
  color: var(--text-secondary);
}

.chain-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.75rem;
}

.chain-form .chain-form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.csv-empty-state {
  min-height: 14rem;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0.75rem;
  text-align: center;
  border: 1px dashed #cbd5e1;
  border-radius: 0.5rem;
  background: #f8fafc;
  padding: 1.5rem;
}

.csv-summary {
  margin-bottom: 1rem;
  padding: 0.75rem;
  border-radius: 0.5rem;
  background: #eff6ff;
  color: #1e40af;
  font-weight: 700;
}

.csv-preview-list {
  display: grid;
  gap: 0.75rem;
  max-height: 28rem;
  overflow: auto;
}

.csv-preview-row {
  padding: 0.875rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: #ffffff;
  opacity: 0;
  transform: translateY(0.75rem);
  animation: workflow-preview-in 0.28s ease forwards;
}

.csv-preview-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.csv-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgb(15 23 42 / 0.46);
}

.modal-card {
  width: min(42rem, 100%);
  max-height: 90vh;
  overflow: auto;
  padding: 1.5rem;
  border-radius: 0.5rem;
  background: #ffffff;
  box-shadow: 0 20px 50px rgb(15 23 42 / 0.24);
}

.document-viewer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 0;
  background: rgb(15 23 42 / 0.58);
}

.document-viewer-modal {
  width: 100%;
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border-radius: 0;
  background: var(--surface);
  box-shadow: 0 24px 60px rgb(15 23 42 / 0.28);
}

.document-viewer-header,
.document-viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.document-viewer-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
}

.document-viewer-main {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.document-viewer-comments {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 0.75rem;
  padding: 1rem;
  border-left: 1px solid var(--border);
  overflow: auto;
}

.document-viewer-comments h3 {
  margin: 0;
  font-size: 0.875rem;
}

.document-viewer-canvas {
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 1rem;
  justify-items: center;
  align-items: start;
  padding: 1rem;
  background: #f8fafc;
}

.document-viewer-canvas canvas,
.document-docx-body,
.document-image {
  max-width: 100%;
  border: 1px solid var(--border);
  background: #ffffff;
}

.document-docx-body {
  width: min(48rem, 100%);
  padding: 1.5rem;
}

.document-viewer-loading {
  align-self: center;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.document-pdf-page {
  display: grid;
  gap: 0.5rem;
  justify-items: center;
}

.document-page-label {
  color: var(--text-secondary);
  font-size: 0.8125rem;
}

.document-comment-list {
  display: grid;
  gap: 0.5rem;
}

.document-comment {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.5rem;
  align-items: start;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 0.8125rem;
}

.document-viewer-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.document-action-group {
  min-width: 14rem;
}

.document-action-buttons {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

.document-feedback-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.8125rem;
}

.signature-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.profile-signature-card {
  grid-column: 2;
}

.signature-preview {
  min-height: 6rem;
  display: grid;
  place-items: center;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: #f8fafc;
  color: var(--text-secondary);
  font-size: 0.8125rem;
}

.signature-upload-box {
  width: 100%;
  border-style: dashed;
  cursor: pointer;
}

.signature-upload-box:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.signature-preview img {
  max-height: 5rem;
}

.csv-error-list {
  display: grid;
  gap: 0.5rem;
}

.csv-error-item {
  padding: 0.75rem;
  border-radius: 0.5rem;
  background: #fef2f2;
  color: #991b1b;
}

.csv-example {
  overflow-x: auto;
  padding: 1rem;
  border-radius: 0.5rem;
  background: #111827;
  color: #f9fafb;
  font-size: 0.8125rem;
  line-height: 1.5;
}

@keyframes workflow-preview-in {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

td, th {
  font-size: 13px;
}

.form-label {
  font-size: 13px;
}

.card-header-title,
.card .card-title,
.card > h2,
.card > h3 {
  font-size: 15px;
}

.modal-card,
.modal-body {
  font-size: 14px;
}

@media (max-width: 900px) {
  .admin-hero,
  .csv-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .admin-grid {
    grid-template-columns: 1fr;
  }

  .document-viewer-modal {
    height: 100vh;
  }

  .document-viewer-grid,
  .signature-grid {
    grid-template-columns: 1fr;
  }

  .profile-signature-card {
    grid-column: auto;
  }

  .document-viewer-comments {
    border-left: 0;
    border-top: 1px solid var(--border);
  }

  .document-viewer-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .document-action-buttons {
    width: 100%;
    margin-left: 0;
  }

  .admin-inline-form,
  .chain-form,
  .detail-grid {
    grid-template-columns: 1fr;
  }
}
