:root {
  --bg: #191919;
  --bg-elevated: #202020;
  --bg-hover: #2a2a2a;
  --bg-input: #2f2f2f;
  --border: #373737;
  --border-light: #2e2e2e;
  --text: #ebebeb;
  --text-secondary: #9b9b9b;
  --text-tertiary: #6f6f6f;
  --accent: #4a5568;
  --accent-hover: #5a6578;
  --accent-muted: #3a424f;
  --tag-other: #4f7ec9;
  --tag-status-new: #5a5a5a;
  --tag-status-review: #6b6b3a;
  --tag-status-progress: #3d6b8e;
  --tag-status-done: #3d6b4f;
  --tag-status-muted: #4a4a4a;
  --radius: 4px;
  --radius-lg: 8px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, "Apple Color Emoji", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
a:hover { color: var(--text); }

.notion-shell { min-height: 100vh; }

.notion-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 14px;
  min-width: 0;
}

.breadcrumbs a:hover { color: var(--text); }
.breadcrumb-sep { color: var(--text-tertiary); }
.breadcrumb-current { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.ghost-button, .link-button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius);
}

.ghost-button:hover, .link-button:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.primary-button, button.primary-button, a.primary-button {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--accent-muted);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.primary-button:hover, a.primary-button:hover {
  background: var(--accent);
  border-color: var(--accent-hover);
  color: var(--text);
}

.topbar-submit {
  padding: 4px 10px;
  white-space: nowrap;
}

.notion-page {
  max-width: 100%;
  padding: 28px 96px 64px;
}

@media (max-width: 900px) {
  .notion-page { padding: 20px 20px 48px; }
}

.page-icon-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.page-icon {
  display: inline-flex;
  align-items: center;
  line-height: 1;
}

.page-icon svg {
  width: 34px;
  height: 34px;
  color: #7ba7d9;
}

.page-title {
  margin: 0;
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.view-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 0;
  padding-bottom: 0;
}

.view-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 8px;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-size: 14px;
}

.view-tab:hover { color: var(--text); background: var(--bg-hover); border-radius: var(--radius) var(--radius) 0 0; }
.view-tab.active {
  color: var(--text);
  border-bottom-color: var(--text);
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 10px 0 8px;
}

.toolbar-button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.toolbar-button:hover { background: var(--bg-hover); color: var(--text); }

.toolbar-button[aria-expanded="true"] {
  background: var(--bg-hover);
  border-color: var(--border);
  color: var(--text);
}

.search-input {
  width: 220px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  padding: 5px 8px;
  font: inherit;
}

.search-input::placeholder { color: var(--text-tertiary); }

.notion-table-wrap {
  overflow-x: auto;
  margin-top: 4px;
}

.notion-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.notion-table th {
  text-align: left;
  color: var(--text-tertiary);
  font-weight: 400;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
}

.notion-table td {
  padding: 4px 10px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
  height: 34px;
}

.notion-table tbody tr:hover { background: var(--bg-hover); }

.col-id { width: 56px; color: var(--text-tertiary); }
.col-title { min-width: 280px; }
.col-status, .col-type { white-space: nowrap; }

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 3px;
  padding: 1px 6px;
  font-size: 12px;
  line-height: 1.6;
  white-space: nowrap;
}

.tag-other { background: rgba(79, 126, 201, 0.35); color: #c8d8f0; }
.tag-status-new { background: rgba(90, 90, 90, 0.5); color: #d0d0d0; }
.tag-status-review { background: rgba(107, 107, 58, 0.45); color: #e0e0b8; }
.tag-status-progress { background: rgba(61, 107, 142, 0.45); color: #c8dff0; }
.tag-status-done { background: rgba(61, 107, 79, 0.45); color: #c8f0d8; }
.tag-status-muted { background: rgba(74, 74, 74, 0.5); color: #c0c0c0; }

.empty-state {
  padding: 48px 12px;
  text-align: center;
  color: var(--text-tertiary);
}

.messages {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.message {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 10px 12px;
  border-radius: var(--radius-lg);
}

.form-page {
  max-width: 708px;
  margin: 0 auto;
}

.form-hero-title {
  margin: 0 0 8px;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
  text-align: center;
}

.form-hero-subtitle {
  margin: 0 0 28px;
  text-align: center;
  color: var(--text-secondary);
}

.form-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  padding: 22px;
}

.form-stack { display: grid; gap: 18px; }

.field-block label {
  display: block;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

input, textarea, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font: inherit;
  background: var(--bg-input);
  color: var(--text);
}

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

input:focus, textarea:focus, select:focus {
  outline: 2px solid rgba(90, 101, 120, 0.45);
  border-color: var(--accent-hover);
}

.form-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 8px;
}

.secondary-link { color: var(--text-secondary); }
.secondary-link:hover { color: var(--text); }

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  padding: 18px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.property-list {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px 14px;
  margin-bottom: 16px;
}

.body-text { white-space: pre-wrap; color: var(--text); }

.timeline { margin: 0; padding-left: 18px; color: var(--text-secondary); }
.timeline li { margin-bottom: 10px; }
.timeline time { display: block; color: var(--text-tertiary); font-size: 12px; }

.property-list {
  display: grid;
  gap: 12px;
  margin: 0 0 20px;
}

.property-list div {
  display: grid;
  gap: 3px;
}

.property-list dt {
  color: var(--text-secondary);
  font-size: 12px;
}

.property-list dd {
  margin: 0;
}

.ticket-label-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 20px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  padding: 28px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 24px;
  letter-spacing: -0.03em;
}

.login-card .muted { color: var(--text-secondary); margin: 0 0 20px; }

.errorlist {
  color: #ff8e8e;
  margin: 4px 0 0;
  padding-left: 18px;
}

.notion-table th.sortable {
  padding: 0;
}

.notion-table th.sortable a {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 32px;
  padding: 6px 10px;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius);
  transition: background 120ms ease, color 120ms ease;
}

.notion-table th.sortable a:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.notion-table th.sortable a:hover .sort-icon {
  opacity: 0.85;
  color: var(--text-secondary);
}

.notion-table th.sort-asc a,
.notion-table th.sort-desc a {
  color: var(--text);
  background: var(--bg-hover);
}

.col-label {
  font-weight: 500;
}

.sort-icon {
  flex-shrink: 0;
  min-width: 14px;
  font-size: 12px;
  line-height: 1;
  opacity: 0.4;
  text-align: center;
}

.notion-table th.sort-asc .sort-icon,
.notion-table th.sort-desc .sort-icon {
  opacity: 1;
  color: var(--text);
  font-weight: 700;
}

.notion-table thead tr {
  border-bottom: 1px solid var(--border);
}

.col-updated { color: var(--text-secondary); white-space: nowrap; }

.tab-panel { margin-top: 16px; }

.ticket-header {
  margin-bottom: 8px;
}

.ticket-hero-title {
  margin: 0 0 4px;
  font-size: clamp(28px, 4vw, 42px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--text);
}

.ticket-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
  gap: 20px;
  align-items: start;
  margin-top: 16px;
}

.ticket-main {
  min-width: 0;
}

.ticket-description-hero {
  margin-bottom: 20px;
}

.ticket-description {
  margin: 0;
  font-size: 17px;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
}

.ticket-meta-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 3px;
  background: var(--bg-hover);
  color: var(--text-secondary);
  font-size: 12px;
}

.meta-chip.meta-muted {
  background: transparent;
  color: var(--text-tertiary);
  padding-left: 0;
}

.ticket-comments-panel {
  position: sticky;
  top: 56px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
}

.ticket-comments-panel h2 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.inline-form {
  display: inline;
  margin: 0;
}

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

.page-header-row .page-icon-title {
  margin-bottom: 0;
  min-width: 0;
}

.view-tabs {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.view-tabs::-webkit-scrollbar { display: none; }

.view-tab {
  flex-shrink: 0;
  min-height: 40px;
}

.filter-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}

.filter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-hover);
  color: var(--text-secondary);
  font-size: 12px;
}

.table-row-link {
  cursor: pointer;
}

.row-title-link {
  display: block;
  padding: 2px 0;
}

.row-title-link:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.search-form {
  display: flex;
  align-items: center;
}

.htmx-indicator {
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.htmx-indicator.htmx-request {
  opacity: 1;
}

.inbox-loading {
  height: 2px;
  margin-bottom: 6px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 200% 100%;
  animation: loading-slide 900ms linear infinite;
}

@keyframes loading-slide {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

@media (max-width: 900px) {
  .notion-topbar {
    flex-wrap: nowrap;
    padding: 10px 12px;
  }

  .breadcrumbs {
    flex: 1 1 auto;
    width: auto;
    font-size: 13px;
  }

  .topbar-actions {
    margin-left: 0;
  }

  .page-title {
    font-size: clamp(22px, 7vw, 32px);
  }

  .page-icon {
    font-size: 32px;
  }

  .table-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .search-input {
    width: 100%;
    min-width: 0;
  }

  .search-form {
    flex: 1;
  }

  .filter-form {
    grid-template-columns: 1fr;
  }

  .notion-table .col-id,
  .notion-table .col-updated {
    display: none;
  }

  .col-title {
    min-width: 180px;
  }

  .notion-table td,
  .notion-table th {
    padding: 8px 8px;
    height: auto;
    min-height: 44px;
  }

  .property-list {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .ticket-layout {
    grid-template-columns: 1fr;
  }

  .ticket-comments-panel {
    position: static;
    max-height: none;
    order: 2;
  }

  .ticket-description {
    font-size: 16px;
  }
}

/* Rendered markdown */

.markdown-body { white-space: normal; }

.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }

.markdown-body p { margin: 0 0 0.7em; }

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin: 1.1em 0 0.45em;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.markdown-body h1 { font-size: 1.35em; }
.markdown-body h2 { font-size: 1.2em; }
.markdown-body h3 { font-size: 1.08em; }
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 { font-size: 1em; }

.markdown-body ul,
.markdown-body ol {
  margin: 0 0 0.7em;
  padding-left: 1.5em;
}

.markdown-body li { margin: 0.15em 0; }

.markdown-body a {
  color: #7ba7d9;
  text-decoration: underline;
  text-decoration-color: rgba(123, 167, 217, 0.4);
  text-underline-offset: 2px;
}

.markdown-body a:hover { text-decoration-color: #7ba7d9; }

.markdown-body code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 0.88em;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: 3px;
  padding: 1px 5px;
}

.markdown-body pre {
  margin: 0 0 0.8em;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  overflow-x: auto;
}

.markdown-body pre code {
  background: transparent;
  border: 0;
  padding: 0;
}

.markdown-body blockquote {
  margin: 0 0 0.8em;
  padding: 2px 0 2px 12px;
  border-left: 3px solid var(--border);
  color: var(--text-secondary);
}

.markdown-body hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1.2em 0;
}

.markdown-body table {
  border-collapse: collapse;
  margin: 0 0 0.8em;
  font-size: 0.95em;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border);
  padding: 5px 10px;
  text-align: left;
}

.markdown-body th {
  background: var(--bg-elevated);
  font-weight: 600;
}

/* Flash message variants */

.message-success { border-color: var(--tag-status-done); }
.message-error { border-color: #a05252; }
.message-warning { border-color: var(--tag-status-review); }

/* EasyMDE dark theme */

.EasyMDEContainer { color: var(--text); }

.EasyMDEContainer .editor-toolbar {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  opacity: 1;
  padding: 4px 6px;
}

.EasyMDEContainer .editor-toolbar button {
  color: var(--text-secondary) !important;
  border: 1px solid transparent;
}

.EasyMDEContainer .editor-toolbar button:hover,
.EasyMDEContainer .editor-toolbar button.active {
  background: var(--bg-hover);
  border-color: var(--border);
  color: var(--text) !important;
}

.EasyMDEContainer .editor-toolbar i.separator {
  border-left: 1px solid var(--border);
  border-right: 0;
}

.EasyMDEContainer .CodeMirror {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  padding: 4px 6px;
}

.EasyMDEContainer .CodeMirror-focused { border-color: var(--accent-hover); }
.EasyMDEContainer .CodeMirror-cursor { border-left: 1px solid var(--text); }
.EasyMDEContainer .CodeMirror-selected { background: var(--accent-muted); }
.EasyMDEContainer .CodeMirror-placeholder { color: var(--text-tertiary) !important; }

.EasyMDEContainer .cm-s-easymde .cm-header { color: var(--text); }
.EasyMDEContainer .cm-s-easymde .cm-quote { color: var(--text-secondary); font-style: italic; }
.EasyMDEContainer .cm-s-easymde .cm-link,
.EasyMDEContainer .cm-s-easymde .cm-url { color: #7ba7d9; }
.EasyMDEContainer .cm-s-easymde .cm-comment {
  background: var(--bg-elevated);
  border-radius: 3px;
}

.EasyMDEContainer .editor-preview {
  background: var(--bg-input);
  color: var(--text);
  padding: 10px 12px;
}

.EasyMDEContainer .editor-preview pre,
.EasyMDEContainer .editor-preview code {
  background: var(--bg-elevated);
}

/* Premium polish: toasts */

.messages {
  position: fixed;
  top: 52px;
  right: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  max-width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  pointer-events: auto;
  background: var(--bg-elevated);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.04);
  font-size: 13px;
  animation: toast-in 220ms cubic-bezier(0.2, 0.9, 0.3, 1);
  transition: opacity 240ms ease, transform 240ms ease;
}

.message-leaving {
  opacity: 0;
  transform: translateX(12px);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-text { flex: 1; }

.message-close {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-tertiary);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  border-radius: var(--radius);
}

.message-close:hover { color: var(--text); }

/* Premium polish: button loading state */

button.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

button.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px;
  height: 14px;
  border: 2px solid var(--text-secondary);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: button-spin 600ms linear infinite;
}

@keyframes button-spin {
  to { transform: rotate(360deg); }
}

/* Premium polish: focus and motion */

:focus-visible {
  outline: 2px solid var(--accent-hover);
  outline-offset: 1px;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
}

.notion-table tbody tr,
.view-tab,
.tag,
.meta-chip {
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Premium polish: login */

.login-card {
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.login-card .primary-button {
  width: 100%;
  padding: 9px 12px;
  font-size: 14px;
}

/* Ticket readability */

.ticket-meta-header {
  margin: 10px 0 4px;
}

.ticket-description,
.ticket-description-hero {
  max-width: 68ch;
}

/* Inline filter row */

.filter-inline {
  display: flex;
  align-items: center;
  min-width: 0;
}

.filter-inline[hidden] { display: none !important; }

.filter-inline .filter-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.filter-inline select,
.filter-inline input {
  width: auto;
  padding: 5px 8px;
}
