* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--color-text);
  background: var(--color-page);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.875rem;
  line-height: 1.35;
}

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

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

h1,
.h1 {
  font-size: 1.35rem;
}

h2,
.h2 {
  font-size: 1.12rem;
}

h3,
.h3,
.h4 {
  font-size: 1rem;
}

h1,
h2,
h3,
h4,
h5,
h6,
p {
  margin-top: 0;
}

.rounded,
.rounded-1,
.rounded-2,
.rounded-3,
.rounded-4,
.rounded-5 {
  border-radius: 0 !important;
}

.btn,
.card,
.dropdown-menu,
.accordion,
.accordion-item,
.accordion-button {
  border-radius: 0 !important;
}

.form-control,
.form-select {
  /*
  border-radius: var(--radius-pill);
*/
  border-radius: 0;
}

.w-50r {
  width: 50rem !important;
}

.w-40r {
  width: 40rem !important;
}

.w-30r {
  width: 30rem !important;
}

.w-20r {
  width: 20rem !important;
}

.w-10r {
  width: 10rem !important;
}

.app-shell {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.mobile-shell-bar,
.mobile-sidebar-header {
  display: none;
}

.app-navigation {
  flex: 0 0 auto;
}

.app-navigation-body {
  display: flex;
  align-items: stretch;
  height: 100vh;
  padding: 0;
  overflow: visible;
}

.app-sidebar {
  flex: 0 0 auto;
  height: 100vh;
  overflow: auto;
  border-right: 1px solid var(--color-border);
  background: var(--color-sidebar);
}

.app-sidebar-primary {
  display: flex;
  flex-direction: column;
  flex-basis: var(--sidebar-primary-width);
  width: var(--sidebar-primary-width);
}

.app-sidebar-secondary {
  flex-basis: var(--sidebar-secondary-width);
  width: var(--sidebar-secondary-width);
  background: var(--color-sidebar-alt);
  padding: var(--space-2);
}

.app-sidebar-secondary[hidden] {
  display: none;
}

.app-main {
  flex: 1 1 auto;
  width: 0;
  min-width: 0;
  height: 100vh;
  overflow: auto;
  padding: var(--space-3);
  background: var(--color-page);
}

.app-main>* {
  width: 100%;
}

.app-main table,
.app-main .table-responsive {
  width: 100%;
}

.app-main img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

.sidebar-brand {
  padding: var(--space-3) var(--space-3) var(--space-2);
  font-weight: 700;
  letter-spacing: 0;
  border-bottom: 1px solid var(--color-border);
}

.sidebar-brand a {
  display: block;
}

.sidebar-user {
  padding: var(--space-2) var(--space-3);
  font-size: 0.8rem;
  color: var(--color-muted);
  border-bottom: 1px solid var(--color-border);
  overflow-wrap: anywhere;
}

.sidebar-search {
  padding: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.sidebar-section {
  border-bottom: 1px solid var(--color-border);
}

.app-accordion .accordion-item {
  color: var(--color-text);
  background: transparent;
  border: 0;
}

.app-accordion .accordion-button {
  min-height: 2rem;
  padding: var(--space-2) var(--space-3);
  color: var(--color-menu-text);
  font-size: 0.82rem;
  box-shadow: none;
}

.app-accordion .accordion-button::after {
  width: 0.8rem;
  height: 0.8rem;
  background-size: 0.8rem;
}

.app-accordion .accordion-button:not(.collapsed) {
  color: var(--color-menu-text);
  box-shadow: none;
}

.menu-level-1 {
  background: var(--color-menu-level-1);
}

.menu-level-2 {
  background: var(--color-menu-level-2);
}

.menu-link {
  display: block;
  min-height: 1.85rem;
  padding: var(--space-2) var(--space-3);
  color: var(--color-menu-text);
  font-size: 0.8rem;
}

.menu-link:hover,
.app-accordion .accordion-button:hover {
  color: var(--color-menu-text);
  background: var(--color-menu-hover);
}

.content-menu {
  min-height: 10rem;
}

.campaign-selector {
  padding: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.icon-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  padding: 0;
  color: var(--color-text);
  background: var(--color-control);
  border: 1px solid var(--color-border);
}

.icon-button:hover:not(:disabled) {
  background: var(--color-control-hover);
}

.icon-button:disabled {
  color: var(--color-disabled);
  cursor: not-allowed;
  opacity: 0.75;
}

.icon-button svg,
.account-link svg,
.campaign-selector .btn svg,
.tree-item svg {
  width: 1rem;
  height: 1rem;
  stroke-width: 1.8;
}

.campaign-selector .input-group .form-select {
  border-radius: var(--radius-pill) 0 0 var(--radius-pill);
}

.campaign-selector .input-group .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0 var(--radius-pill) var(--radius-pill) 0 !important;
}

.folder-tree,
.file-list {
  padding: var(--space-1) 0;
}

.folder-tree .accordion-item {
  background: transparent;
  border: 0;
}

.folder-tree .accordion-header {
  margin: 0;
}

.folder-tree-children {
  padding: 0;
}

.tree-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 2rem;
  padding: var(--space-2) var(--space-3);
  color: var(--color-text);
  font-size: 0.82rem;
  line-height: 1.35;
  text-align: left;
  background: transparent;
  border: 0;
}

.folder-tree .accordion-button.tree-item {
  color: var(--color-menu-text);
  font-size: 0.82rem;
  box-shadow: none;
}

.folder-tree .accordion-button.tree-item:not(.collapsed) {
  color: var(--color-menu-text);
  box-shadow: none;
}

.folder-tree .tree-item.folder-level-0 {
  color: var(--color-menu-text);
  background: var(--color-menu-level-1);
}

.folder-tree .tree-item.folder-level-1 {
  color: var(--color-menu-text);
  background: var(--color-menu-level-2);
}

.folder-tree .tree-item.folder-level-2 {
  color: var(--color-menu-text);
  background: #4b6367;
}

.folder-tree .tree-item.folder-level-3 {
  color: var(--color-menu-text);
  background: #5a7074;
}

.folder-tree .tree-item.folder-level-4 {
  color: var(--color-menu-text);
  background: #687d80;
}

.folder-tree .tree-item.folder-level-5,
.folder-tree .tree-item.folder-level-6,
.folder-tree .tree-item.folder-level-7,
.folder-tree .tree-item.folder-level-8,
.folder-tree .tree-item.folder-level-9 {
  color: var(--color-menu-text);
  background: #75888b;
}

.tree-item:hover,
.tree-item.is-active {
  color: var(--color-menu-text);
  background: var(--color-menu-hover);
}

.file-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 1.9rem;
  padding: var(--space-1) var(--space-3);
  color: var(--color-text);
  overflow-wrap: anywhere;
}

.file-item:hover,
.file-item.is-active {
  color: var(--color-text);
  background: var(--color-control-hover);
}

.file-item svg {
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
  stroke-width: 1.8;
}

.empty-state {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  color: var(--color-muted);
  font-size: 0.78rem;
}

.sidebar-account {
  margin-top: auto;
  border-top: 1px solid var(--color-border);
  background: var(--color-sidebar);
}

.account-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 2rem;
  padding: var(--space-2) var(--space-3);
  color: var(--color-text);
  background: transparent;
  border: 0;
  font: inherit;
  text-align: left;
}

.account-link:hover {
  color: var(--color-link);
  background: var(--color-control-hover);
}

.account-button {
  cursor: pointer;
}

.sidebar-title {
  margin: var(--space-2) var(--space-2) var(--space-1);
  color: var(--color-muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.document-view,
.document-editor {
  width: 100%;
}

.document-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.document-header h1 {
  margin-bottom: 0;
}

.document-path {
  margin-bottom: var(--space-1);
  color: var(--color-muted);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.document-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-1);
}

.document-actions .btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.document-actions svg {
  width: 1rem;
  height: 1rem;
}

.document-metadata {
  width: 100%;
  margin-bottom: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}

.document-metadata h2 {
  margin-bottom: var(--space-2);
  font-size: 1rem;
}

.document-metadata th {
  width: 14rem;
  color: var(--color-muted);
  font-weight: 600;
}

.document-metadata td {
  white-space: pre-wrap;
}

.markdown-body {
  width: 100%;
  padding: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}

.image-viewer {
  width: 100%;
  margin: 0;
  padding: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}

.image-viewer img {
  display: block;
  width: 100%;
  max-height: calc(100vh - 18rem);
  object-fit: contain;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin-top: var(--space-3);
  margin-bottom: var(--space-2);
}

.markdown-body h1:first-child,
.markdown-body h2:first-child,
.markdown-body h3:first-child {
  margin-top: 0;
}

.markdown-body p,
.markdown-body ul,
.markdown-body blockquote,
.markdown-body .markdown-table-wrapper,
.markdown-body pre {
  margin-bottom: var(--space-2);
}

.markdown-body blockquote {
  padding: var(--space-2) var(--space-3);
  color: var(--color-muted);
  background: var(--color-page);
  border-left: 4px solid var(--color-border);
}

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

.markdown-table-wrapper {
  width: 100%;
  overflow-x: auto;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
}

.markdown-body th,
.markdown-body td {
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-border);
  vertical-align: top;
}

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

.markdown-body pre {
  padding: var(--space-2);
  overflow: auto;
  background: var(--color-page);
  border: 1px solid var(--color-border);
}

.markdown-editor {
  width: 100%;
  min-height: 24rem;
  background: var(--color-surface);
}

.markdown-editor .toastui-editor-defaultUI {
  width: 100%;
}

.markdown-source {
  min-height: 24rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

ttrpg-structured-form {
  display: block;
  width: 100%;
}

.session-view {
  width: 100%;
}

.session-sticky {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--color-page);
  border-bottom: 1px solid var(--color-border);
}

.session-titlebar,
.session-quick-event,
.session-inline-form,
.session-player-event,
.session-tool-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.session-title-input {
  flex: 1 1 auto;
  min-width: 12rem;
}

.session-date-input,
.session-status-input {
  flex: 0 0 12rem;
}

.session-tools-grid,
.session-notes-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.session-tool,
.session-panel {
  min-width: 0;
}

.session-current-date,
.session-dice-result {
  margin: 0;
  min-height: 1.5rem;
}

.session-scroll {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-3);
}

.session-markdown-box {
  min-height: 14rem;
  resize: vertical;
}

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

.session-player-event {
  width: 100%;
}

.session-player-box .session-player-event {
  flex: 0 0 auto;
  width: auto;
}

.session-player-box [data-player-aspects] {
  min-height: 3rem;
}

.session-player-event .form-control,
.session-quick-event .form-control,
.session-inline-form .form-select {
  flex: 1 1 auto;
}

.session-linked-list {
  margin: 0;
  padding-left: 1.25rem;
}

@media (max-width: 991.98px) {

  .session-titlebar,
  .session-quick-event {
    flex-wrap: wrap;
  }

  .session-date-input,
  .session-status-input {
    flex: 1 1 10rem;
  }

  .session-tools-grid,
  .session-notes-grid {
    grid-template-columns: 1fr;
  }
}

.structured-page {
  display: grid;
  gap: var(--space-3);
  width: 100%;
}

.structured-section {
  border: 1px solid var(--color-border);
  padding: var(--space-3);
  background: var(--color-surface);
}

.structured-section-title {
  margin: 0 0 var(--space-2);
  font-size: 1rem;
  font-weight: 700;
}

.structured-heading {
  margin: 0;
  font-weight: 700;
  line-height: 1.2;
}

.structured-heading-level-1 {
  font-size: 1.75rem;
}

.structured-heading-level-2 {
  font-size: 1.4rem;
}

.structured-heading-level-3 {
  font-size: 1.15rem;
}

.structured-heading-level-4,
.structured-heading-level-5,
.structured-heading-level-6 {
  font-size: 1rem;
}

.structured-hr {
  width: 100%;
  margin: var(--space-1) 0;
  border: 0;
  border-top: 1px solid var(--color-border);
}

.structured-link {
  color: var(--color-link);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.structured-link:hover {
  text-decoration: underline;
}

.structured-row {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--space-2);
  align-items: start;
}

.structured-column {
  min-width: 0;
  grid-column: span var(--structured-col, 12);
}

.structured-control {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}

.structured-label {
  font-size: 0.875rem;
  font-weight: 600;
}

.structured-list {
  display: grid;
  gap: var(--space-2);
}

.structured-list-horizontal {
  grid-template-columns: repeat(var(--structured-list-columns, auto-fit), minmax(0, 1fr));
  align-items: start;
}

.structured-list-horizontal>.structured-section-title {
  grid-column: 1 / -1;
}

.structured-list-item {
  border: 1px solid var(--color-border);
  padding: var(--space-2);
}

.structured-error {
  color: var(--bs-danger, #dc3545);
  margin: 0;
}

.structured-control textarea.form-control {
  min-height: 7rem;
  resize: vertical;
}

.structured-control .form-check-input {
  margin: 0;
}

.bg-white {
  background-color: var(--color-surface) !important;
}

.bg-light {
  background-color: var(--color-page) !important;
}

.border {
  border-color: var(--color-border) !important;
}

.btn {
  font-size: 0.82rem;
}

.btn-primary,
.btn-outline-primary:hover {
  background: var(--color-link);
  border-color: var(--color-link);
}

.btn-outline-primary {
  color: var(--color-link);
  border-color: var(--color-link);
}

.counter {
  border-radius: 0 !important;
}

/*
.re-table {
  min-width: 48rem;
  table-layout: fixed;
}
*/
.re-table {
  width: max-content;
  min-width: 100%;
  table-layout: auto;
}

.re-table tr {
  background-color: var(--bs-table-bg);

}

.re-table th,
.re-table td {
  vertical-align: middle;
  padding: 0 0.5rem;
}

.re-table td:first-child {
  width: 3.5rem;
  white-space: nowrap;
}

.re-table td:not(:first-child) {
  min-width: 8.5rem;
}

.re-table .form-control {
  width: 100%;
  margin: 0.2rem;
  padding: 0 0.1rem;
}

.re-table td.w8rem,
.re-table th.w8rem {
  width: 8rem !important;
}

.re-table td.w6rem,
.re-table th.w6rem {
  width: 6rem !important;
}

.re-table td.w4rem,
.re-table th.w4rem {
  width: 4rem !important;
}

.re-table td.w2rem,
.re-table th.w2rem {
  width: 2rem !important;
}

.min-h-5 {
  min-height: 5rem !important;
}

.min-h-10 {
  min-height: 10rem !important;
}

.min-h-15 {
  min-height: 15rem !important;
}

.text-small {
  font-size: 0.9em !important;
}

#structured-character-renderer h1 {
  font-size: 1.6rem !important;
}

#structured-character-renderer h2 {
  font-size: 1.5rem !important;
}

#structured-character-renderer h3 {
  font-size: 1.4rem !important;
}

#structured-character-renderer h4 {
  font-size: 1.3rem !important;
}

#structured-character-renderer h5 {
  font-size: 1.2rem !important;
}

#structured-character-renderer h6 {
  font-size: 1.1rem !important;
}

@media print {
  html,
  body {
    height: auto;
  }

  /*
   * The desktop UI scrolls inside .app-main instead of the document body.
   * Printing that viewport-sized container clips structured character sheets
   * after the visible page, so the print layout must return to normal flow.
   */
  .app-shell {
    display: block;
    width: auto;
    min-height: auto;
    overflow: visible;
  }

  .app-main {
    width: auto;
    height: auto;
    min-height: auto;
    overflow: visible;
    padding: 0;
  }

  .table-responsive,
  .markdown-table-wrapper {
    overflow: visible;
  }
}

@media (max-width: 991.98px) {
  body {
    padding-top: 2.5rem;
  }

  .mobile-shell-bar {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 2.5rem;
    padding: var(--space-1) var(--space-2);
    background: var(--color-sidebar);
    border-bottom: 1px solid var(--color-border);
  }

  .mobile-shell-brand {
    font-weight: 700;
  }

  .mobile-sidebar-header {
    display: flex;
    min-height: 2.5rem;
    padding: var(--space-2) var(--space-3);
    background: var(--color-sidebar);
    border-bottom: 1px solid var(--color-border);
  }

  .mobile-sidebar-header .offcanvas-title {
    font-size: 1rem;
  }

  .app-shell {
    width: 100%;
    min-height: calc(100vh - 2.5rem);
    overflow: visible;
  }

  .app-navigation {
    --bs-offcanvas-width: min(22rem, 92vw);
    color: var(--color-text);
    background: var(--color-sidebar);
  }

  .app-navigation-body {
    display: block;
    height: calc(100vh - 2.5rem);
    padding: 0;
    overflow: auto;
  }

  .app-sidebar,
  .app-main {
    width: 100%;
    height: auto;
    max-height: none;
  }

  .app-sidebar-primary {
    display: block;
    flex-basis: auto;
    min-height: auto;
  }

  .app-sidebar-secondary {
    flex-basis: auto;
    width: 100%;
    padding: 0;
    background: var(--color-sidebar);
    border-top: 1px solid var(--color-border);
  }

  .app-sidebar-secondary .icon-toolbar {
    background: var(--color-sidebar);
  }

  .sidebar-brand {
    display: none;
  }

  .sidebar-account {
    margin-top: 0;
    background: var(--color-sidebar);
  }

  .app-main {
    min-height: calc(100vh - 2.5rem);
    padding: var(--space-2);
  }

  .document-header {
    display: block;
  }

  .document-actions {
    justify-content: flex-start;
    margin-top: var(--space-2);
  }

  .structured-row {
    grid-template-columns: 1fr;
  }

  .structured-column {
    grid-column: 1 / -1;
  }
}
