:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #cbd5e1;
  --border-light: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #0f766e;
  --primary-hover: #0d9488;
  --primary-soft: #ccfbf1;
  --accent: #0369a1;
  --danger: #dc2626;
  --success: #15803d;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.hidden {
  display: none !important;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-icon svg {
  width: 22px;
  height: 22px;
}

.app-header h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

.subtitle {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.period-picker {
  display: flex;
  gap: 6px;
}

select,
input[type="text"],
input[type="number"],
textarea {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.15);
}

.view-toggle {
  display: inline-flex;
  background: var(--bg);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.btn-toggle {
  border: none;
  background: transparent;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-toggle.active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

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

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

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-success:hover {
  filter: brightness(1.08);
}

.btn-outline {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}

.btn-outline:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.btn-outline-accent {
  background: #f0f9ff;
  border-color: #bae6fd;
  color: var(--accent);
}

.btn-outline-accent:hover {
  background: #e0f2fe;
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
}

.btn-danger-ghost:hover {
  background: #fef2f2;
}

/* Main Layout */
.app-main {
  max-width: 1480px;
  margin: 0 auto;
  padding: 18px 20px 40px;
  display: grid;
  grid-template-columns: 310px 1fr;
  gap: 20px;
  align-items: start;
}

.app-main.preview-only {
  grid-template-columns: 1fr;
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 78px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

.card-header h2 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 700;
}

.card-body {
  padding: 12px 14px;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.badge {
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.action-grid .btn {
  justify-content: flex-start;
  font-size: 12px;
  padding: 8px 9px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-item {
  background: #f8fafc;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
}

.stat-wide {
  grid-column: span 2;
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
}

.stat-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.stat-value.accent {
  color: var(--primary);
}

.template-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tpl-chip {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  transition: all 0.15s;
}

.tpl-chip:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
}

.field-row select {
  max-width: 165px;
  font-size: 12px;
  padding: 5px 7px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  cursor: pointer;
}

/* Workspace & Editor Toolbar */
.workspace {
  min-width: 0;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  background: var(--surface);
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow);
}

.search-box {
  flex: 1;
  max-width: 360px;
}

.search-box input {
  width: 100%;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.save-indicator {
  font-size: 12px;
  color: var(--success);
  font-weight: 500;
}

/* =========================================================
   THE OFFICIAL VISUM DOCUMENT SHEET (Matches Image Layout)
   ========================================================= */
.sheet-wrapper {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  overflow-x: auto;
}

.app-main.preview-only .sheet-wrapper {
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 36px;
}

.visum-sheet {
  font-family: Arial, Helvetica, sans-serif;
  color: #000;
  background: #fff;
  width: 100%;
  min-width: 720px;
}

.visum-header {
  text-align: center;
  margin-bottom: 8px;
}

.visum-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  line-height: 1.3;
}

.visum-subtitle {
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  line-height: 1.3;
}

.visum-period {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.3;
}

.visum-identity {
  margin-bottom: 6px;
  font-size: 11.5px;
  line-height: 1.4;
}

.identity-row {
  display: flex;
  align-items: baseline;
}

.id-label {
  width: 58px;
  display: inline-block;
}

.id-colon {
  width: 12px;
  display: inline-block;
}

.id-value {
  font-weight: 400;
}

/* Visum Table */
.visum-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 10.5px;
}

.visum-table th,
.visum-table td {
  border: 1px solid #000;
  padding: 3px 5px;
  vertical-align: middle;
  word-wrap: break-word;
}

.visum-table th {
  font-weight: 700;
  text-align: center;
  background: #fff;
  font-size: 10px;
  line-height: 1.25;
  padding: 4px 4px;
}

.col-no {
  width: 34px;
  text-align: center;
}

.col-day {
  width: 62px;
  text-align: center;
}

.col-date {
  width: 106px;
  text-align: center;
}

.col-desc {
  width: auto;
  text-align: left;
}

.col-place {
  width: 145px;
  text-align: center;
}

.col-paraf {
  width: 78px;
  text-align: center;
}

.visum-table td.col-desc {
  text-align: left;
  line-height: 1.3;
}

.desc-main {
  display: block;
}

.desc-sub {
  display: block;
}

/* Interactive row hover & inline editing in edit mode */
body:not(.preview-mode) .visum-table tbody tr {
  transition: background-color 0.1s;
}

body:not(.preview-mode) .visum-table tbody tr:hover td {
  background-color: #f0fdfa;
}

body:not(.preview-mode) .visum-table tbody tr.row-holiday:hover td {
  background-color: #ef4444;
}

body:not(.preview-mode) .visum-table tbody td.col-no,
body:not(.preview-mode) .visum-table tbody td.col-day,
body:not(.preview-mode) .visum-table tbody td.col-date {
  cursor: pointer;
}

.inline-editable {
  min-height: 18px;
  outline: none;
  border-radius: 3px;
}

body:not(.preview-mode) .inline-editable:focus {
  background: #ffffff;
  box-shadow: inset 0 0 0 1.5px var(--primary);
  padding: 2px 4px;
}

body:not(.preview-mode) .inline-editable:empty::before {
  content: attr(data-placeholder);
  color: #94a3b8;
  font-style: italic;
  font-size: 9.5px;
  pointer-events: none;
}

body:not(.preview-mode) tr.row-holiday .inline-editable:empty::before {
  color: rgba(0, 0, 0, 0.45);
}

.row-edit-btn {
  border: 1px solid var(--border);
  background: #f8fafc;
  color: var(--primary);
  border-radius: 4px;
  font-size: 10px;
  padding: 2px 6px;
  cursor: pointer;
  font-weight: 600;
}

.row-edit-btn:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
}

body.preview-mode .row-edit-btn {
  display: none !important;
}

/* Sunday / National Holiday row — Solid Red like the image */
.visum-table tbody tr.row-holiday td {
  background-color: #ff0000;
  color: #000;
}

/* Leave / Sick indicator in edit mode only (subtle tint) */
body:not(.preview-mode) .visum-table tbody tr.row-leave td {
  background-color: #fffbeb;
}

/* Footer Signatures */
.visum-footer {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  padding: 0 28px;
  font-size: 11px;
  line-height: 1.35;
}

.sig-block {
  text-align: center;
  min-width: 220px;
}

.sig-space {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sig-image {
  max-height: 52px;
  max-width: 140px;
  object-fit: contain;
}

.sig-name {
  font-weight: 700;
  text-decoration: underline;
}

.sig-id {
  font-size: 10.5px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border-radius: 12px;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
}

.modal-lg {
  max-width: 720px;
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.btn-close {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.modal-footer-right {
  display: flex;
  gap: 8px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  font-weight: 500;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.form-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--primary);
  margin-top: 6px;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 4px;
}

.day-status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.radio-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 12.5px;
  cursor: pointer;
}

.radio-pill.pill-red {
  border-color: #fecaca;
  background: #fef2f2;
  color: #b91c1c;
}

.radio-pill.pill-amber {
  border-color: #fde68a;
  background: #fffbeb;
  color: #b45309;
}

.quick-fill-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f8fafc;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-light);
}

.quick-fill-inline label {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.quick-fill-inline select {
  flex: 1;
}

.upload-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.upload-row input[type="file"] {
  font-size: 12px;
  max-width: 220px;
}

.template-add-box {
  background: #f8fafc;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.template-manage-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.template-manage-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
}

.template-manage-info strong {
  display: block;
  font-size: 13px;
}

.template-manage-info small {
  color: var(--muted);
  font-size: 11.5px;
}

.divider {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 6px 0;
}

/* Responsive */
@media (max-width: 1024px) {
  .app-main {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
  }
}

@media (max-width: 640px) {
  .form-row-2,
  .form-row-3 {
    grid-template-columns: 1fr;
  }
}

/* =========================================================
   PRINT STYLES (Exact A4 / F4 Single-Page Crisp Output)
   ========================================================= */
@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .no-print {
    display: none !important;
  }

  .app-main {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    max-width: none !important;
  }

  .sheet-wrapper {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
  }

  .visum-sheet {
    min-width: 0 !important;
    width: 100% !important;
  }

  body.print-compact .visum-title {
    font-size: 11.5px;
  }
  body.print-compact .visum-subtitle,
  body.print-compact .visum-period {
    font-size: 11px;
  }
  body.print-compact .visum-identity {
    font-size: 10px;
    margin-bottom: 4px;
  }
  body.print-compact .visum-table {
    font-size: 9px;
  }
  body.print-compact .visum-table th {
    font-size: 8.5px;
    padding: 3px 3px;
  }
  body.print-compact .visum-table td {
    padding: 2px 4px;
  }
  body.print-compact .visum-footer {
    margin-top: 10px;
    font-size: 10px;
    page-break-inside: avoid;
  }
  body.print-compact .sig-space {
    height: 44px;
  }
}
