:root {
  --ink: #14273a;
  --ink-soft: #3d5a72;
  --bg: #f4ede2;
  --paper: #fffdf8;
  --line: #d6dde6;
  --shadow: 0 10px 30px rgba(16, 39, 61, 0.12);
  --shadow-soft: 0 4px 14px rgba(15, 31, 48, 0.08);
  --radius: 16px;
  --sidebar: #10283d;
  --sidebar-soft: #173750;
  --accent: #ff6f35;
  --accent-strong: #e45f2b;
  --font-ui: 'Avenir Next', 'Trebuchet MS', 'Gill Sans', sans-serif;
  --font-display: 'Avenir Next', 'Gill Sans', 'Trebuchet MS', sans-serif;
  --sidebar-width: 280px;
  --sidebar-width-collapsed: 88px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: linear-gradient(140deg, #faf7f0 0%, #efe7d8 46%, #f6f1e6 100%);
  font-family: var(--font-ui);
}

.icon-system {
  display: none;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

body.sidebar-collapsed .app-shell {
  grid-template-columns: var(--sidebar-width-collapsed) 1fr;
}

.sidebar {
  background: linear-gradient(185deg, #0f293e 0%, #0b2030 100%);
  color: #e9f0f7;
  border-right: 1px solid #21435d;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button {
  border: 1px solid rgba(233, 240, 247, 0.35);
  color: #f0f5fb;
  background: rgba(12, 37, 59, 0.45);
  width: 36px;
  min-width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 10px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.brand h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.05;
  letter-spacing: 0.02em;
  font-family: var(--font-display);
}

.brand .version {
  color: #8ab2d8;
  font-size: 11px;
  line-height: 1;
  margin-top: 2px;
  opacity: 0.9;
}

.brand p,
.brand .kicker {
  margin: 0;
}

.brand .kicker {
  color: #b5c8dc;
  font-size: 13px;
}

.sidebar--collapsed .brand,
.sidebar--collapsed .section,
.sidebar--collapsed .sidebar-actions .label,
.sidebar--collapsed #sync-label,
.sidebar--collapsed .search-block,
.sidebar--collapsed .filter-row,
.sidebar--collapsed h1,
.sidebar--collapsed h2 {
  display: none;
}

.sidebar-scroll {
  display: grid;
  gap: 12px;
  overflow: auto;
  padding-bottom: 4px;
}

.section {
  border: 1px solid #214a69;
  border-radius: 12px;
  padding: 10px;
  background: rgba(10, 40, 63, 0.42);
}

.section h2 {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 12px;
  color: #c5d5e3;
}

.button-stack {
  display: grid;
  gap: 6px;
}

.status-filter,
.tree-item button {
  width: 100%;
  border: 1px solid #2c5574;
  background: #173855;
  color: #ebf1f7;
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  cursor: pointer;
}

.status-filter[data-active='true'],
.status-filter:hover,
.tree-item button:hover {
  border-color: #4c87af;
  background: #225272;
}

.badge {
  border-radius: 999px;
  font-size: 11px;
  background: #245174;
  color: #d7e6f4;
  padding: 2px 7px;
}

.tree {
  display: grid;
  gap: 6px;
}

.tree-group {
  border: 1px solid #2a5070;
  border-radius: 10px;
  padding: 5px;
}

.tree-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 2px 4px;
  color: #d9e7f3;
  font-weight: 600;
  font-size: 13px;
}

.tree-items {
  display: grid;
  gap: 4px;
}

.tree-item {
  width: 100%;
  border: 1px solid #2b5372;
  background: #173a58;
  color: #e7f0f7;
  border-radius: 9px;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
}

.tree-item:hover {
  border-color: #4c84aa;
  background: #205272;
}

.sidebar-actions {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

.sidebar-action {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 30px;
  padding: 6px 9px;
  justify-content: flex-start;
  border-radius: 10px;
  text-align: left;
  font-size: 12px;
  line-height: 1.2;
}

.sidebar-action .label {
  font-size: 12px;
  font-weight: 500;
}

.sidebar-action svg {
  width: 17px;
  height: 17px;
  fill: currentColor;
}

.sidebar--collapsed .sidebar-action {
  justify-content: center;
}

.inbox-status {
  border-radius: 10px;
  border: 1px solid #28516f;
  background: rgba(6, 36, 59, 0.55);
  padding: 6px 9px;
  color: #c9d6e4;
  font-size: 11px;
  line-height: 1.35;
}

.inbox-status.error {
  border-color: #7c2c1a;
  background: rgba(74, 24, 14, 0.45);
  color: #ffe7de;
}

.inbox-status.ok {
  border-color: #256b4a;
  background: rgba(20, 68, 42, 0.38);
  color: #d3f4e0;
}

.sidebar--collapsed .inbox-status {
  display: none;
}

.workspace-wrap {
  padding: 12px;
  display: grid;
  gap: 12px;
}

.topbar {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px;
  display: grid;
  gap: 10px;
  box-shadow: var(--shadow-soft);
}

.search-block label,
.filter-row label,
.panel-head p,
.toolbar label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #4b6479;
}

.search {
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #d3dbe4;
  border-radius: 10px;
  background: #fff;
  padding: 8px 10px;
}

.search input {
  border: 0;
  min-width: 180px;
  width: min(440px, 100%);
}

.search svg {
  width: 15px;
  height: 15px;
  fill: #657c90;
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}

.filter-row label,
.toolbar label {
  display: grid;
  gap: 4px;
}

.inline {
  display: flex;
  align-items: center;
  gap: 6px;
}

.filter-row label.inline {
  display: flex;
  align-items: flex-end;
  min-height: 34px;
  padding: 0 4px 7px;
  text-transform: none;
  letter-spacing: 0;
  line-height: 1.25;
}

.filter-row label.inline input {
  flex: 0 0 auto;
  margin: 0 1px 2px 0;
}

.mini-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mini-stats span {
  border-radius: 999px;
  border: 1px solid #d6e0ea;
  padding: 5px 10px;
  background: #f0f4f9;
  font-size: 12px;
  color: #334e63;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(330px, 0.34fr) minmax(300px, 0.28fr) minmax(360px, 0.38fr);
  gap: 12px;
}

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
  box-shadow: var(--shadow-soft);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.panel-head h2 {
  margin: 0;
  font-size: 16px;
}

.list-panel .panel-head p {
  margin: 3px 0 0;
  color: #4d667b;
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
}

.cards {
  margin: 8px 0 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: #f9f5ec;
}

.card strong {
  color: #304a60;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.card .value {
  margin-top: 3px;
  font-size: 28px;
  line-height: 1;
  font-weight: 600;
}

.items {
  display: grid;
  gap: 7px;
  max-height: min(650px, calc(100vh - 360px));
  overflow: auto;
  padding-right: 2px;
}

.item {
  border: 1px solid #d7e0ea;
  border-radius: 11px;
  padding: 10px;
  background: #fcfaf5;
  display: grid;
  gap: 5px;
  text-align: left;
  cursor: pointer;
}

.item[aria-selected='true'],
.item:hover {
  border-color: #89afce;
  background: #fffaf3;
}

.item-main,
.item-meta,
.item-summary {
  min-width: 0;
}

.item-main {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sender {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.path {
  color: #647485;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-meta {
  color: #546a7f;
  font-size: 12px;
}

.item-summary {
  color: #2d4457;
  font-size: 13px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.status-pill,
.category-pill,
.due-pill,
.important-pill {
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 11px;
}

.status-pill {
  color: #f5fbff;
  background: #2e607f;
}

.category-pill {
  color: #263e53;
  background: #dbe8f4;
}

.due-pill {
  color: #273e53;
  background: #deebf8;
}

.due-pill.overdue {
  background: #ffc0ad;
  color: #74231a;
}

.important-pill {
  background: #ffdece;
  color: #8a3217;
}

.detail-panel,
.preview-panel {
  min-height: calc(100vh - 165px);
}

.preview-content {
  display: grid;
  gap: 10px;
}

.preview-frame {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0e1f2f;
  padding: 6px;
}

.preview-frame img {
  width: 100%;
  border-radius: 8px;
  display: block;
  background: #fff;
}

.preview-frame-media {
  width: 100%;
  height: min(500px, 60vh);
  min-height: 260px;
  border: 0;
  border-radius: 8px;
  display: block;
}

.preview-meta {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff8f1;
  padding: 8px;
  display: grid;
  gap: 6px;
}

.preview-meta h3 {
  margin: 0;
  font-size: 16px;
}

.preview-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.preview-facts .fact-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fcfcfc;
  padding: 7px 8px;
  font-size: 12px;
  color: #2f4458;
}

.preview-text {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
  display: grid;
  gap: 6px;
}

.preview-text h4 {
  margin: 0;
}

.preview-text p {
  margin: 0;
  font-size: 13px;
  color: #2f4658;
  line-height: 1.35;
}

#detail-content,
#preview-content,
#detail-empty,
#preview-empty {
  margin-top: 10px;
}

.detail-fields {
  margin-top: 10px;
  display: grid;
  gap: 9px;
}

.detail-title {
  display: grid;
  gap: 4px;
}

.detail-title h3 {
  margin: 0;
  font-size: 18px;
}

.detail-title .item-id {
  color: #607182;
  font-size: 12px;
  letter-spacing: 0.02em;
}

.detail-actions {
  display: grid;
  gap: 8px;
}

input,
textarea,
select,
button {
  font: inherit;
  color: var(--ink);
  border: 1px solid #d1dde6;
  border-radius: 10px;
  background: #fff;
}

input,
textarea,
select {
  padding: 7px 10px;
}

textarea {
  width: 100%;
  min-height: 72px;
  resize: vertical;
}

label {
  display: grid;
  gap: 4px;
  color: #2d4155;
  font-size: 13px;
}

button {
  cursor: pointer;
  background: #fff;
  padding: 8px 12px;
}

.primary {
  background: var(--accent);
  color: #fff4eb;
  border-color: var(--accent-strong);
}

.primary:hover {
  background: #ff8450;
}

.ghost {
  background: #213f58;
  color: #ebf2f8;
  border-color: #315f81;
}

button svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

.empty-state {
  border: 1px dashed #c8d5e0;
  border-radius: 12px;
  padding: 16px;
  background: #f7fafc;
  color: #4f6476;
}

.muted {
  color: #6f8599;
}

#capture-form label {
  margin: 8px 0;
}

.capture-switch {
  margin-bottom: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.switch {
  border: 1px solid #cad9e7;
  background: #f5f9fd;
}

.switch.active {
  border-color: var(--accent);
  color: #8d3b1b;
  background: #ffe6d4;
}

.capture-panel {
  padding-top: 6px;
}

.capture-panel video {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0d1f30;
}

.camera-actions,
.dialog-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

#toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  border-radius: 11px;
  padding: 10px 12px;
  min-width: 200px;
  opacity: 0;
  transition: 0.2s;
  background: #17344a;
  color: #f0f7ff;
  box-shadow: var(--shadow);
  pointer-events: none;
}

#toast.show {
  opacity: 1;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  width: min(820px, calc(100vw - 40px));
  max-height: calc(100vh - 36px);
  overflow: hidden;
}

dialog::backdrop {
  background: rgba(12, 26, 40, 0.55);
}

dialog form {
  display: grid;
  gap: 7px;
  max-height: calc(100vh - 120px);
  overflow: auto;
}

.result-highlight,
mark {
  background: #ffd9bd;
  color: #3d2c1f;
  border-radius: 4px;
  padding: 0 2px;
}

.comment-block,
.audit-block {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafdff;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.comment-block h3,
.audit-block h3 {
  margin: 0;
  font-size: 14px;
}

.log-list {
  display: grid;
  gap: 6px;
}

.comment-item,
.audit-item {
  border: 1px solid #dde5ef;
  border-radius: 10px;
  background: #fff;
  padding: 6px 8px;
}

.comment-item p,
.audit-item p {
  margin: 5px 0 0;
  white-space: pre-wrap;
  color: #2d4456;
}

.comment-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.comment-head small {
  font-size: 12px;
  color: #66788a;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none;
}

.attachment-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 10px;
  padding: 8px 10px;
  border: 1px solid #e6d4c6;
  border-radius: 11px;
  color: #76411f;
  background: #fff7ee;
  font-size: 12px;
}

.attachment-summary span {
  color: #8d796b;
}

.source-pill {
  color: #687785;
  background: #f3f6f8;
}

.source-pill.is-email {
  color: #1f617c;
  background: #e2f2f6;
}

.mailbox-item {
  align-items: center;
}

.mailbox-item[data-active='true'] {
  border-color: #f48a54;
  background: #2b6380;
}

.mailbox-item strong,
.mailbox-item small {
  display: block;
  max-width: 184px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mailbox-item small {
  margin-top: 2px;
  color: #a8c0d3;
  font-size: 10px;
}

.smart-card {
  display: grid;
  gap: 8px;
  padding: 11px;
  border: 1px solid #cde2e9;
  border-radius: 12px;
  background: linear-gradient(145deg, #f2fbfc, #fffaf4);
}

.smart-card-head,
.smart-facts,
.smart-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
}

.smart-card h3,
.smart-card p {
  margin: 0;
}

.smart-card-head {
  justify-content: space-between;
}

.smart-card-head span {
  color: #23708b;
  font-size: 11px;
  font-weight: 700;
}

.smart-card p {
  color: #385366;
  font-size: 12px;
  line-height: 1.4;
}

.smart-facts span {
  min-width: 112px;
  padding: 6px 7px;
  border: 1px solid #d9e8eb;
  border-radius: 8px;
  background: #fff;
  color: #4e6576;
  font-size: 11px;
}

.smart-facts b {
  display: block;
  margin-bottom: 2px;
  color: #1e3d50;
  font-size: 10px;
  text-transform: uppercase;
}

.smart-actions {
  align-items: flex-start;
}

.smart-actions > b {
  padding-top: 6px;
  font-size: 11px;
}

.suggestion {
  padding: 5px 7px;
  border-color: #f0c4a6;
  background: #fff5eb;
  color: #81441e;
  font-size: 11px;
  text-align: left;
}

.suggestion:hover {
  border-color: var(--accent);
  background: #ffe4d1;
}

@media (max-width: 1400px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }

  .preview-panel,
  .detail-panel {
    min-height: auto;
  }

  .items {
    max-height: 300px;
  }
}

@media (max-width: 1024px) {
  .app-shell {
    grid-template-columns: var(--sidebar-width-collapsed) 1fr;
  }

  .workspace-wrap {
    padding: 8px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid #23435c;
  }

  .workspace-wrap {
    padding: 8px;
  }

  .filter-row,
  .toolbar {
    grid-template-columns: 1fr;
  }

  .attachment-summary {
    align-items: flex-start;
    flex-direction: column;
  }
}
.quick-scan-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  margin: 0 0 18px;
  padding: 16px 18px;
  border: 1px solid rgba(31, 53, 86, 0.12);
  border-radius: 16px;
  background: linear-gradient(110deg, #f8fbff, #edf4fb);
  box-shadow: 0 10px 28px rgba(26, 48, 80, 0.08);
}

.quick-scan-copy {
  display: grid;
  gap: 4px;
}

.quick-scan-copy strong {
  color: #182941;
  font-size: 15px;
}

.quick-scan-copy span:last-child {
  color: #67758a;
  font-size: 12px;
}

.quick-scan-button {
  white-space: nowrap;
}

.quick-scan-preview {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #53657b;
  font-size: 12px;
}

.quick-scan-preview img {
  width: 76px;
  height: 54px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid rgba(31, 53, 86, 0.14);
  background: #fff;
}

@media (max-width: 720px) {
  .quick-scan-panel {
    grid-template-columns: 1fr;
  }

  .quick-scan-button {
    width: 100%;
  }
}
