:root {
  --ink: #18181b;
  --ink-muted: #71717a;
  --line: #e4e4e7;
  --line-dark: #d4d4d8;
  --surface: #ffffff;
  --surface-tint: #fafafa;
  --surface-head: #f4f4f5;
  --desk-bg: #eceef1;
  --accent: #27272a;
  --font-main: "Sarabun", "Noto Sans Thai", "Leelawadee UI", "Tahoma", sans-serif;
}

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

html,
body {
  margin: 0;
  padding: 0;
  font-family: var(--font-main);
  font-size: 12px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--desk-bg);
  -webkit-font-smoothing: antialiased;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(24, 24, 27, 0.05);
}

.toolbar-inner {
  max-width: 1460px;
  margin: 0 auto;
  padding: 9px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
}

.toolbar-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  padding: 5px 11px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  color: #52525b;
  background: #ffffff;
  border: 1px solid var(--line);
}

.nav-tab:hover {
  background: var(--surface-head);
  color: var(--ink);
}

.nav-tab.is-active {
  background: #18181b;
  color: #ffffff;
  border-color: #18181b;
}

.font-color-control {
  gap: 4px;
}

.color-picker-input {
  width: 26px;
  height: 24px;
  padding: 1px;
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  background: #ffffff;
  cursor: pointer;
}

.btn-icon-reset {
  border: 1px solid var(--line-dark);
  background: var(--surface-head);
  color: var(--ink);
  border-radius: 4px;
  width: 22px;
  height: 24px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.btn-icon-reset:hover {
  background: #e4e4e7;
}

.toolbar-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.toolbar-badge {
  background: var(--surface-head);
  color: var(--ink);
  border: 1px solid var(--line-dark);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
}

.control-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #52525b;
}

.control-item select {
  background: var(--surface-tint);
  color: var(--ink);
  border: 1px solid var(--line-dark);
  border-radius: 5px;
  padding: 5px 8px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn-primary {
  background: #18181b;
  color: #ffffff;
}

.btn-primary:hover {
  background: #27272a;
}

.btn-secondary {
  background: var(--surface-head);
  color: var(--ink);
  border-color: var(--line-dark);
}

.btn-secondary:hover {
  background: #e4e4e7;
}

.toolbar-hint {
  max-width: 1460px;
  margin: 0 auto;
  padding: 4px 16px 7px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--ink-muted);
  border-top: 1px solid var(--surface-head);
}

.save-status {
  color: #52525b;
  font-weight: 600;
}

/* Workspace Layout */
.tpl-workspace {
  max-width: 1460px;
  margin: 0 auto;
  padding: 20px 16px 36px;
}

.tpl-layout {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

@media (max-width: 980px) {
  .tpl-layout {
    grid-template-columns: 1fr;
  }
}

.tpl-sidebar {
  background: #ffffff;
  border: 1px solid var(--line-dark);
  border-radius: 8px;
  overflow: hidden;
}

.tpl-sidebar-title {
  background: var(--surface-head);
  border-bottom: 1px solid var(--line-dark);
  padding: 9px 12px;
  font-size: 12px;
  font-weight: 700;
}

.tpl-search-wrap {
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  background: #fafafa;
}

.tpl-search-input {
  width: 100%;
  height: 28px;
  padding: 3px 9px;
  border: 1px solid var(--line-dark);
  border-radius: 5px;
  background: #ffffff;
  color: var(--ink);
  font-family: inherit;
  font-size: 12px;
  outline: none;
}

.tpl-search-input:focus {
  border-color: #18181b;
}

.tpl-empty {
  padding: 16px 10px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 11.5px;
}

.tpl-list {
  display: flex;
  flex-direction: column;
  padding: 6px;
  gap: 4px;
}

.tpl-group-label {
  font-size: 10.5px;
  font-weight: 700;
  color: #18181b;
  background: #f4f4f5;
  border-left: 3px solid #18181b;
  border-radius: 4px;
  margin: 8px 2px 3px;
  padding: 5px 8px;
  letter-spacing: 0.25px;
}

.tpl-group-label:first-child {
  margin-top: 2px;
}

.tpl-item-btn {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  padding: 7px 9px;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
}

.tpl-item-btn:hover {
  background: var(--surface-head);
}

.tpl-item-btn.is-active {
  background: #18181b;
  color: #ffffff;
}

.tpl-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
}

.tpl-item-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface-head);
  color: var(--ink);
  border: 1px solid var(--line-dark);
}

.tpl-item-btn.is-active .tpl-item-badge {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.25);
}

.tpl-item-desc {
  font-size: 11px;
  opacity: 0.8;
}

/* Preview Pane */
.tpl-preview-pane {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.tpl-preview-bar {
  background: #ffffff;
  border: 1px solid var(--line-dark);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.tpl-preview-bar strong {
  display: block;
  font-size: 14px;
}

.preview-sub {
  font-size: 11.5px;
  color: var(--ink-muted);
}

.tpl-preview-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.tpl-layout-switch {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 4px;
  border: 1px solid var(--line-dark);
  border-radius: 6px;
  background: var(--surface-tint);
}

.tpl-layout-switch[hidden] {
  display: none;
}

.tpl-layout-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-muted);
  padding: 0 5px;
}

.tpl-dir-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
}

.tpl-dir-btn:hover {
  background: var(--surface-head);
}

.tpl-dir-btn.is-active {
  background: #18181b;
  color: #ffffff;
}

.preview-stage {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-x: auto;
}

/* Simulated 16:9 Slide Card */
.mock-slide-16x9 {
  --ink: var(--doc-ink, #18181b);
  font-family: var(--doc-font, var(--font-main));
  color: var(--ink);
  width: 100%;
  max-width: 1020px;
  aspect-ratio: 16 / 9;
  background: #ffffff;
  border: 1px solid var(--line-dark);
  box-shadow: 0 10px 28px rgba(24, 24, 27, 0.1);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mock-top-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.mock-logo {
  width: 96px;
  height: 48px;
  flex: 0 0 auto;
  border: 1.25px dashed var(--line-dark);
  background: var(--surface-tint);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--ink-muted);
}

.mock-hdr-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 16% 8.5% 15% 15% 16.5% 8% 21%;
  grid-template-rows: 24px 24px;
  border: 1px solid var(--line-dark);
  font-size: 11px;
  font-weight: 700;
}

.mock-cell {
  display: flex;
  align-items: center;
  padding: 0 7px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mock-cell.span2 {
  grid-column: 1 / 3;
  background: var(--surface-head);
}

.mock-cell.span-part {
  grid-column: 2 / 4;
}

.mock-cell.lbl {
  background: var(--surface-tint);
}

.mock-cell.lbl2 {
  background: var(--surface-head);
}

.mock-cell.center {
  justify-content: center;
}

.mock-cell.status-review {
  background: #FCC963;
  color: #2e2c2a;
  justify-content: center;
}

.mock-board {
  flex: 1;
  min-height: 0;
  border: 1px solid #d4d4d8;
  display: flex;
  flex-direction: column;
}

.mock-banner {
  background: #27272a;
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  padding: 4px 10px;
}

.mock-body {
  flex: 1;
  min-height: 0;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mock-box {
  border: 1px solid var(--line-dark);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.mock-box-head {
  background: var(--surface-head);
  border-bottom: 1px solid var(--line-dark);
  padding: 4px 8px;
  font-size: 11.5px;
  font-weight: 700;
}

.mock-photo {
  flex: 1;
  min-height: 0;
  border: 1.25px dashed var(--line-dark);
  background: var(--surface-tint);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-muted);
  font-size: 11px;
  font-weight: 600;
}

/* Simulated A4 Sheet */
.mock-a4 {
  --ink: var(--doc-ink, #18181b);
  font-family: var(--doc-font, var(--font-main));
  color: var(--ink);
  width: 100%;
  max-width: 720px;
  background: #ffffff;
  border: 1px solid var(--line-dark);
  box-shadow: 0 10px 28px rgba(24, 24, 27, 0.1);
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mock-a4-hdr {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 10px;
  border-bottom: 1.5px solid #18181b;
}

.mock-a4-tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.mock-a4-tbl th,
.mock-a4-tbl td {
  border: 1px solid var(--line-dark);
  padding: 5px 7px;
  text-align: left;
}

.mock-a4-tbl th {
  background: var(--surface-head);
  font-weight: 700;
}

@media print {
  html,
  body {
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

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

  .tpl-workspace,
  .tpl-layout,
  .tpl-preview-pane,
  .preview-stage {
    display: block !important;
    width: 100% !important;
    max-width: none !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
  }

  .mock-slide-16x9 {
    width: 338.67mm !important;
    max-width: none !important;
    height: 190.2mm !important;
    max-height: 190.2mm !important;
    aspect-ratio: 16 / 9 !important;
    box-shadow: none !important;
    border: none !important;
    padding: 10px 12px !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .mock-a4 {
    width: 100% !important;
    max-width: none !important;
    min-height: 277mm;
    box-shadow: none !important;
    border: none !important;
    padding: 8mm 10mm !important;
  }
}

