:root {
  --ui-font-body: 14px;
  --ui-font-metadata: 12px;
  --ui-font-heading: 16px;
  --ui-line-body: 1.5;
  --ui-space-1: 4px;
  --ui-space-2: 8px;
  --ui-space-3: 12px;
  --ui-space-4: 16px;
  --ui-control-height: 36px;
  --ui-touch-target: 44px;
  --ui-icon-size: 20px;
}

.app-header {
  min-height: 60px;
  padding: 8px 16px;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
}

.app-header > #workspace-identity {
  grid-column: 1;
  grid-row: 1;
}

.app-header > h1 {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-header > #device-storage-ui {
  grid-column: 2;
  grid-row: 1;
}

.app-header > .header-controls {
  grid-column: 3;
  grid-row: 1;
}

#header-settings {
  grid-column: 3;
  grid-row: 1;
  min-width: 0;
}

html[data-ui-settings="ready"] .app-header {
  grid-template-columns: minmax(0, 1fr) auto auto;
}

html[data-ui-settings="ready"] .app-header > #device-storage-ui .device-storage-panel {
  right: -52px;
}

.app-header #workspace-identity > .brand-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

html[data-ui-settings="ready"] .app-header #workspace-identity > .local-guest {
  display: none;
}

.brand,
.brand-name {
  font-size: var(--ui-font-heading);
  font-weight: 600;
  line-height: 1.5;
  letter-spacing: 0;
}

.header-settings-widget {
  position: relative;
}

.header-settings-gear,
.header-settings-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
}

.header-settings-panel {
  position: absolute;
  z-index: 70;
  top: calc(100% + 8px);
  right: 0;
  width: min(360px, calc(100vw - 24px));
  max-height: calc(100dvh - 88px - env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--ui-border-strong);
  border-radius: 4px;
  background: var(--ui-surface);
  color: var(--ui-text);
  box-shadow: 0 8px 24px var(--ui-menu-shadow);
  font-size: var(--ui-font-body);
  line-height: var(--ui-line-body);
}

.header-settings-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 4px 8px 4px 16px;
  border-bottom: 1px solid var(--ui-border);
}

.header-settings-heading-row h2 {
  margin: 0;
  font-size: var(--ui-font-heading);
  font-weight: 600;
  line-height: 1.5;
}

.header-settings-body {
  display: flex;
  flex-direction: column;
  padding: 0 16px 16px;
}

.header-settings-body h3 {
  margin: 0;
  font-size: var(--ui-font-body);
  font-weight: 600;
  line-height: 1.5;
}

.header-settings-space {
  order: 0;
  padding: 12px 0 8px;
}

.header-settings-space-action {
  margin-top: 8px;
}

.header-settings-native,
.header-settings-native .header-controls {
  display: contents;
}

.header-settings-appearance-label {
  order: 2;
  padding-top: 12px;
}

.header-settings-native .theme-control {
  order: 3;
  width: 100%;
  min-height: 40px;
  padding: 8px 0 12px;
  justify-content: space-between;
  border-bottom: 1px solid var(--ui-border);
  font-size: 14px;
}

.header-settings-native #theme-select {
  flex: 1;
  max-width: 220px;
  min-height: 36px;
  font-size: 14px;
}

.header-settings-language-label {
  order: 4;
  padding-top: 12px;
}

.header-settings-native .language-toggle {
  order: 5;
  width: 100%;
  min-height: 36px;
  margin-top: 4px;
  border-color: var(--ui-control-border);
  background: var(--ui-surface);
  color: var(--ui-text);
}

:is(.app-header, .workspace-modebar, .documents-panel, .notes-panel, .reader-heading-row, .reader-toolbar, .data-workspace-header, .assistant-header, .assistant-management, .app-status) {
  font-size: var(--ui-font-body);
  line-height: var(--ui-line-body);
}

:is(.app-header, .workspace-modebar, .documents-panel, .notes-panel, .reader-heading-row, .reader-toolbar, .data-workspace-header, .assistant-header, .assistant-management) :is(.button, button, summary, select):not(.note-rich-content *, .ql-editor *) {
  font-size: var(--ui-font-body);
}

:is(.reader-heading-row, .data-workspace-header, .assistant-header) h2,
.panel-heading > h2 {
  font-size: var(--ui-font-heading);
  font-weight: 600;
  line-height: 1.5;
}

:is(.documents-panel, .notes-panel) :is(h3, summary, .note-label):not(.note-rich-content *, .ql-editor *) {
  font-size: var(--ui-font-body);
  font-weight: 600;
}

:is(.document-meta, .page-count, .document-title, .character-count, .notes-count, .note-source, .library-trash-help, .library-search-status, .rich-text-draft-help) {
  font-size: var(--ui-font-metadata);
  line-height: 1.5;
}

.workspace-modebar {
  min-height: 52px;
  padding: 4px 16px;
  gap: 12px;
}

.workspace-mode-button {
  min-height: 36px;
  padding: 6px 14px;
}

.library-search {
  padding: 8px 12px;
}

.library-search-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.library-search-row {
  flex-wrap: nowrap;
  gap: 4px;
}

#library-search-input {
  min-height: 36px;
  height: 36px;
  padding: 6px 8px;
  font-size: 14px;
}

.library-search-row :is(#library-search-submit, #library-search-clear) {
  display: inline-flex;
  flex: 0 0 40px;
  align-items: center;
  justify-content: center;
  width: 40px;
  min-width: 40px;
  min-height: 36px;
  height: 36px;
  padding: 0;
}

.library-search-row button > svg,
.upload-button > svg {
  width: var(--ui-icon-size);
  height: var(--ui-icon-size);
  flex: none;
}

.library-search-row button > span {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.paper-library-actions {
  min-height: 0;
  padding: 8px 12px;
  border-bottom: 0;
}

.upload-button {
  gap: 8px;
  min-height: 36px;
  padding: 6px 12px;
}

#documents-empty {
  padding: 12px;
  font-size: 14px;
  line-height: 1.5;
}

#documents-empty #sample-open {
  min-height: 36px;
  margin-top: 8px;
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: var(--ui-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}

#documents-list .document-open,
.search-result-open {
  font-size: 14px;
  line-height: 1.5;
}

@media (max-width: 820px) {
  .mobile-layout-active .app-header {
    min-height: 52px;
    padding: calc(4px + env(safe-area-inset-top, 0px)) calc(12px + env(safe-area-inset-right, 0px)) 4px calc(12px + env(safe-area-inset-left, 0px));
    gap: 8px;
  }

  .mobile-layout-active .brand,
  .mobile-layout-active .brand > .brand-name {
    max-width: none;
    font-size: 16px;
    line-height: 1.5;
  }

  .mobile-layout-active .header-settings-panel {
    max-height: calc(var(--mobile-viewport-height, 100dvh) - 76px - env(safe-area-inset-bottom, 0px));
  }

  .mobile-layout-active .header-settings-native :is(.theme-control, #theme-select, .language-toggle) {
    min-height: 44px;
  }

  .mobile-layout-active .header-settings-native #theme-select {
    font-size: 16px;
  }

  .mobile-layout-active .workspace-modebar {
    min-height: 52px;
    padding: 4px 12px;
  }

  .mobile-layout-active .workspace-mode-button {
    min-height: 44px;
  }

  .mobile-layout-active .library-search {
    padding: 8px 12px;
  }

  .mobile-layout-active #library-search-input {
    height: 44px;
    min-height: 44px;
    font-size: 16px !important;
  }

  .mobile-layout-active .library-search-row :is(#library-search-submit, #library-search-clear) {
    flex-basis: 44px;
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
  }

  .mobile-layout-active .paper-library-actions {
    padding: 8px 12px;
  }

  .mobile-layout-active .upload-button,
  .mobile-layout-active #documents-empty #sample-open {
    min-height: 44px;
  }
}

@media (max-width: 420px) {
  .mobile-layout-active .library-search-row #library-search-input {
    flex-basis: auto;
  }
}
