:root {
  --pd-bg: #f5f3ee;
  --pd-surface: #fbfaf7;
  --pd-panel: #efede7;
  --pd-ink: #262520;
  --pd-muted: #77736a;
  --pd-border: #d9d5cc;
  --pd-border-strong: #c7c1b5;
  --pd-accent: #176b43;
  --pd-accent-hover: #125737;
  --pd-danger: #a33d35;
  --pd-shadow: 0 12px 36px rgba(42, 38, 29, .1);
  color-scheme: light;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--pd-bg); color: var(--pd-ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; letter-spacing: 0; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { color: inherit; }
a { color: inherit; }
code, pre { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }

.pd-min-w-0 { min-width: 0; }
.pd-page-body { width: min(100%, 1240px); margin: 0 auto; padding: 34px 40px 64px; }
.pd-view-stack { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.pd-page-header { display: flex; min-height: 64px; align-items: flex-start; justify-content: space-between; gap: 24px; }
.pd-page-header h1 { margin: 0; font-size: 24px; line-height: 1.25; font-weight: 650; }
.pd-page-header p { margin: 7px 0 0; max-width: 720px; color: var(--pd-muted); font-size: 14px; line-height: 1.5; }
.pd-actions, .pd-form-actions, .pd-editor-footer > div { display: flex; align-items: center; gap: 8px; }
.pd-actions { flex: none; }

.pd-button, .pd-icon-button { display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 6px; cursor: pointer; transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease; }
.pd-button { min-height: 36px; gap: 7px; padding: 0 13px; font-size: 13px; font-weight: 560; white-space: nowrap; }
.pd-button-primary { background: var(--pd-ink); color: #fff; }
.pd-button-primary:hover { background: #3b3932; }
.pd-button-secondary { border-color: var(--pd-border); background: var(--pd-surface); }
.pd-button-secondary:hover, .pd-button-ghost:hover { background: var(--pd-panel); }
.pd-button-ghost { background: transparent; }
.pd-button-danger { border-color: rgba(163, 61, 53, .25); background: #fff7f5; color: var(--pd-danger); }
.pd-button:disabled, .pd-icon-button:disabled { cursor: not-allowed; opacity: .48; }
.pd-icon-button { width: 34px; height: 34px; padding: 0; border-color: var(--pd-border); background: var(--pd-surface); }
.pd-icon-button:hover { background: var(--pd-panel); border-color: var(--pd-border-strong); }

.pd-table-stack { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.pd-table-toolbar { display: flex; align-items: center; gap: 10px; min-height: 36px; }
.pd-table-toolbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.pd-search { display: flex; width: min(320px, 100%); height: 34px; align-items: center; gap: 8px; padding: 0 10px; border: 1px solid var(--pd-border); border-radius: 6px; background: var(--pd-surface); color: var(--pd-muted); }
.pd-search:focus-within { border-color: var(--pd-border-strong); box-shadow: 0 0 0 3px rgba(38, 37, 32, .05); }
.pd-search input { min-width: 0; flex: 1; border: 0; outline: 0; background: transparent; color: var(--pd-ink); font-size: 13px; }
.pd-table-frame { overflow: hidden; border: 1px solid var(--pd-border); border-radius: 7px; background: var(--pd-surface); }
.pd-table-scroll { overflow-x: auto; }
.pd-table-frame table { width: 100%; min-width: 680px; border-collapse: collapse; table-layout: auto; }
.pd-table-frame th { height: 39px; padding: 0 14px; border-bottom: 1px solid var(--pd-border); background: var(--pd-panel); color: var(--pd-muted); font-size: 11px; font-weight: 620; text-align: left; text-transform: uppercase; }
.pd-table-frame th button { display: inline-flex; align-items: center; gap: 5px; width: 100%; padding: 0; border: 0; background: none; color: inherit; cursor: pointer; text-transform: inherit; }
.pd-table-frame td { height: 58px; padding: 9px 14px; border-bottom: 1px solid var(--pd-border); font-size: 13px; vertical-align: middle; }
.pd-table-frame tbody tr:last-child td { border-bottom: 0; }
.pd-table-frame tbody tr[data-clickable="true"] { cursor: pointer; outline: none; }
.pd-table-frame tbody tr[data-clickable="true"]:hover td, .pd-table-frame tbody tr[data-clickable="true"]:focus td { background: #f3f1eb; }
.pd-table-frame [data-align="right"] { text-align: right; }
.pd-table-frame [data-align="center"] { text-align: center; }
.pd-table-frame th[data-align="right"] button { justify-content: flex-end; }
.pd-table-frame th[data-align="center"] button { justify-content: center; }
.pd-table-frame td code { display: inline-block; max-width: 280px; overflow: hidden; color: #5f5a50; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
.pd-primary-cell { display: flex; min-width: 0; align-items: center; gap: 10px; }
.pd-primary-cell > svg { flex: none; color: #686258; }
.pd-primary-cell > div { display: flex; min-width: 0; flex: 1; flex-direction: column; gap: 3px; }
.pd-primary-cell strong, .pd-primary-cell span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pd-primary-cell strong { font-size: 13px; font-weight: 610; }
.pd-primary-cell span { color: var(--pd-muted); font-size: 12px; }
.pd-file-name { display: flex; min-width: 0; align-items: center; gap: 9px; }
.pd-file-name svg { flex: none; color: #686258; }
.pd-file-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pd-empty-cell { height: 220px !important; text-align: center; }
.pd-pagination { display: flex; min-height: 46px; align-items: center; justify-content: space-between; padding: 6px 10px 6px 14px; border-top: 1px solid var(--pd-border); color: var(--pd-muted); font-size: 12px; }
.pd-pagination > div { display: flex; gap: 6px; }

.pd-empty { display: flex; min-height: 190px; align-items: center; justify-content: center; flex-direction: column; gap: 8px; color: var(--pd-muted); }
.pd-empty strong { color: var(--pd-ink); font-size: 14px; }
.pd-empty span { margin-bottom: 6px; font-size: 13px; }
.pd-error { padding: 11px 13px; border: 1px solid rgba(163, 61, 53, .22); border-radius: 6px; background: #fff6f4; color: var(--pd-danger); font-size: 13px; }
.pd-saved { color: var(--pd-accent); font-size: 12px; font-weight: 600; }
.pd-spin { animation: pd-spin 800ms linear infinite; }
@keyframes pd-spin { to { transform: rotate(360deg); } }

.pd-loading-rows { overflow: hidden; border: 1px solid var(--pd-border); border-radius: 7px; background: var(--pd-surface); }
.pd-loading-rows div { height: 58px; border-bottom: 1px solid var(--pd-border); background: linear-gradient(90deg, transparent, rgba(255,255,255,.82), transparent), var(--pd-panel); background-size: 240px 100%; animation: pd-shimmer 1.2s infinite linear; }
.pd-loading-rows div:last-child { border-bottom: 0; }
@keyframes pd-shimmer { from { background-position: -240px 0; } to { background-position: calc(100% + 240px) 0; } }

.pd-modal-backdrop { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(35, 33, 28, .42); backdrop-filter: blur(3px); }
.pd-modal { width: min(640px, 100%); max-height: min(760px, calc(100vh - 40px)); overflow: auto; border: 1px solid var(--pd-border-strong); border-radius: 8px; background: var(--pd-surface); box-shadow: var(--pd-shadow); }
.pd-modal > header { position: sticky; z-index: 1; top: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 20px; border-bottom: 1px solid var(--pd-border); background: var(--pd-surface); }
.pd-modal h2 { margin: 0; font-size: 18px; line-height: 1.3; }
.pd-modal header p { margin: 6px 0 0; color: var(--pd-muted); font-size: 13px; line-height: 1.5; }
.pd-form { display: flex; flex-direction: column; gap: 18px; padding: 20px; }
.pd-field { display: flex; flex-direction: column; gap: 7px; }
.pd-field > span { font-size: 12px; font-weight: 620; }
.pd-field small { color: var(--pd-muted); font-size: 11px; line-height: 1.45; }
.pd-field input, .pd-field textarea, .pd-field select, .pd-memory-editor textarea, .pd-editor input, .pd-editor textarea, .pd-composer textarea, .pd-playground-toolbar select { width: 100%; border: 1px solid var(--pd-border); border-radius: 6px; outline: 0; background: #fff; color: var(--pd-ink); }
.pd-field input, .pd-editor input, .pd-playground-toolbar select { height: 38px; padding: 0 11px; }
.pd-field textarea, .pd-editor textarea { resize: vertical; padding: 10px 11px; line-height: 1.55; }
.pd-field input:focus, .pd-field textarea:focus, .pd-editor input:focus, .pd-editor textarea:focus, .pd-memory-editor textarea:focus, .pd-composer textarea:focus, .pd-playground-toolbar select:focus { border-color: var(--pd-border-strong); box-shadow: 0 0 0 3px rgba(38, 37, 32, .05); }
.pd-form-actions { justify-content: flex-end; padding-top: 2px; }

.pd-editor, .pd-memory-editor { overflow: hidden; border: 1px solid var(--pd-border); border-radius: 7px; background: var(--pd-surface); }
.pd-editor-section { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; padding: 22px; }
.pd-editor-section h2 { grid-column: 1 / -1; margin: 0 0 2px; font-size: 15px; }
.pd-editor-section .pd-field:last-child { grid-column: 1 / -1; }
.pd-editor-footer { display: flex; min-height: 58px; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 14px; border-top: 1px solid var(--pd-border); background: var(--pd-panel); }
.pd-memory-editor textarea { display: block; min-height: min(62vh, 650px); resize: vertical; padding: 18px; border: 0; border-radius: 0; background: transparent; font-family: "SFMono-Regular", Consolas, monospace; font-size: 13px; line-height: 1.65; }
.pd-memory-editor footer { display: flex; min-height: 56px; align-items: center; justify-content: space-between; padding: 9px 12px 9px 16px; border-top: 1px solid var(--pd-border); background: var(--pd-panel); color: var(--pd-muted); font-size: 12px; }

.pd-breadcrumb { display: flex; min-height: 34px; align-items: center; gap: 6px; color: var(--pd-muted); font-size: 12px; }
.pd-breadcrumb span { display: inline-flex; align-items: center; gap: 6px; }
.pd-breadcrumb button { max-width: 220px; overflow: hidden; padding: 4px 6px; border: 0; border-radius: 4px; background: transparent; color: inherit; cursor: pointer; text-overflow: ellipsis; white-space: nowrap; }
.pd-breadcrumb button:hover { background: var(--pd-panel); color: var(--pd-ink); }

.pd-playground { display: flex; min-height: calc(100vh - 64px); flex-direction: column; gap: 18px; }
.pd-playground-toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.pd-playground-toolbar label { display: flex; width: min(320px, 100%); flex-direction: column; gap: 6px; }
.pd-playground-toolbar label span { color: var(--pd-muted); font-size: 11px; font-weight: 620; text-transform: uppercase; }
.pd-playground-toolbar code { padding: 6px 8px; border: 1px solid var(--pd-border); border-radius: 5px; background: var(--pd-panel); color: var(--pd-muted); font-size: 11px; }
.pd-chat-frame { display: flex; min-height: 520px; flex: 1; flex-direction: column; overflow: hidden; border: 1px solid var(--pd-border); border-radius: 7px; background: var(--pd-surface); }
.pd-messages { display: flex; min-height: 0; flex: 1; flex-direction: column; gap: 26px; overflow-y: auto; padding: 28px max(24px, calc((100% - 760px) / 2)); }
.pd-chat-empty { display: flex; min-height: 360px; align-items: center; justify-content: center; flex-direction: column; gap: 8px; color: var(--pd-muted); text-align: center; }
.pd-chat-empty strong { color: var(--pd-ink); }
.pd-chat-empty span { font-size: 13px; }
.pd-message { max-width: 720px; }
.pd-message[data-role="user"] { align-self: flex-end; max-width: min(620px, 86%); padding: 11px 14px; border-radius: 7px 7px 2px 7px; background: var(--pd-panel); }
.pd-message-role { margin-bottom: 7px; color: var(--pd-muted); font-size: 10px; font-weight: 650; text-transform: uppercase; }
.pd-markdown { overflow-wrap: anywhere; font-size: 14px; line-height: 1.65; }
.pd-markdown > :first-child { margin-top: 0; }
.pd-markdown > :last-child { margin-bottom: 0; }
.pd-markdown pre { overflow-x: auto; padding: 13px; border: 1px solid var(--pd-border); border-radius: 6px; background: #292823; color: #f4f2eb; font-size: 12px; }
.pd-markdown code:not(pre code) { padding: 2px 4px; border-radius: 3px; background: var(--pd-panel); font-size: .9em; }
.pd-tool-call { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 9px; padding: 8px 10px; border: 1px solid var(--pd-border); border-radius: 5px; color: var(--pd-muted); font-size: 11px; }
.pd-tool-call code { font-size: 10px; }
.pd-composer { display: flex; align-items: flex-end; gap: 8px; padding: 12px; border-top: 1px solid var(--pd-border); background: var(--pd-panel); }
.pd-composer textarea { min-height: 42px; max-height: 160px; resize: none; padding: 10px 11px; line-height: 1.45; }

.pd-transcript { display: flex; flex-direction: column; gap: 14px; }
.pd-transcript article { padding: 18px; border: 1px solid var(--pd-border); border-radius: 7px; background: var(--pd-surface); }
.pd-transcript article[data-role="user"] { margin-left: min(10%, 80px); background: var(--pd-panel); }
.pd-transcript article header { margin-bottom: 9px; color: var(--pd-muted); font-size: 10px; font-weight: 650; text-transform: uppercase; }

@media (max-width: 760px) {
  .pd-page-body { padding: 24px 16px 48px; }
  .pd-page-header { min-height: auto; flex-direction: column; gap: 14px; }
  .pd-actions { width: 100%; flex-wrap: wrap; }
  .pd-table-toolbar { align-items: stretch; flex-wrap: wrap; }
  .pd-search { width: 100%; }
  .pd-table-toolbar-right { margin-left: auto; }
  .pd-table-frame table { min-width: 0; table-layout: fixed; }
  .pd-table-frame [data-mobile-hidden="true"] { display: none; }
  .pd-table-frame th, .pd-table-frame td { padding-right: 12px; padding-left: 12px; }
  .pd-editor-section { grid-template-columns: 1fr; padding: 16px; }
  .pd-editor-section .pd-field:last-child { grid-column: auto; }
  .pd-editor-footer { align-items: stretch; flex-direction: column-reverse; }
  .pd-editor-footer > div { justify-content: flex-end; }
  .pd-playground { min-height: calc(100vh - 56px); }
  .pd-playground-toolbar { align-items: stretch; flex-direction: column; }
  .pd-playground-toolbar label { width: 100%; }
  .pd-messages { padding: 20px 14px; }
  .pd-message[data-role="user"] { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
