:root {
  color-scheme: light;
  --bg: #f5f4ef;
  --panel: #fffdf8;
  --panel-strong: #ffffff;
  --ink: #23221f;
  --muted: #716f68;
  --line: #dfddd4;
  --line-strong: #cbc8bd;
  --green: #1f7a58;
  --green-dark: #145940;
  --mint: #dff1e8;
  --coral: #b64d35;
  --coral-soft: #f3d8cf;
  --amber: #b8831c;
  --amber-soft: #f4e7bf;
  --blue: #386b7a;
  --blue-soft: #dbeaed;
  --shadow: 0 18px 45px rgba(38, 34, 26, 0.11);
  --radius: 8px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(31, 122, 88, 0.06) 1px, transparent 1px),
    linear-gradient(180deg, rgba(31, 122, 88, 0.05) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px;
  color: var(--ink);
  font-family: var(--font);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.icon-sprite {
  display: none;
}

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

.auth-card {
  display: grid;
  gap: 18px;
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
}

.auth-brand {
  margin-bottom: 4px;
}

.auth-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.86);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid #184c38;
  border-radius: var(--radius);
  background: #194f3a;
  color: #fffdf8;
  font-weight: 800;
}

.brand h1,
.brand p,
.section-head h2,
.section-head p,
.detail-title h2,
.detail-title p,
.dialog-head h2,
.dialog-head p,
.empty-state h2,
.empty-state p {
  margin: 0;
}

.brand h1 {
  font-size: 1.04rem;
  line-height: 1.2;
}

.brand p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.86rem;
}

.nav-stack {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.nav-item strong {
  min-width: 28px;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(35, 34, 31, 0.08);
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.nav-item:hover,
.nav-item.active {
  border-color: var(--line-strong);
  background: var(--panel-strong);
}

.nav-item.active {
  color: var(--green-dark);
  font-weight: 750;
}

.tag-panel {
  min-height: 0;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.tag-list,
.category-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-chip,
.category-chip,
.detail-tag {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.82rem;
}

.tag-chip {
  border-color: transparent;
}

.category-chip {
  justify-content: space-between;
  width: 100%;
  min-height: 36px;
  border-color: transparent;
}

.category-chip strong {
  margin-left: 8px;
  color: var(--muted);
  font-size: 0.76rem;
}

.category-chip.active,
.category-chip:hover,
.tag-chip.active,
.tag-chip:hover {
  border-color: var(--green);
  color: var(--green-dark);
}

.backup-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: auto;
}

.full-row {
  grid-column: 1 / -1;
}

.ghost-btn,
.secondary-btn,
.primary-btn,
.danger-btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--panel-strong);
  color: var(--ink);
  text-decoration: none;
}

.ghost-btn,
.secondary-btn {
  padding: 0 12px;
}

.ghost-btn {
  font-size: 0.88rem;
}

.primary-btn {
  padding: 0 15px;
  border-color: #155d43;
  background: var(--green);
  color: white;
  font-weight: 750;
}

.primary-btn:hover {
  background: var(--green-dark);
}

.secondary-btn:hover,
.ghost-btn:hover,
.icon-btn:hover {
  border-color: var(--ink);
}

.danger-btn {
  padding: 0 12px;
  border-color: #d8afa3;
  background: var(--coral-soft);
  color: #81311f;
}

.danger-btn:hover {
  border-color: var(--coral);
}

.file-btn {
  cursor: pointer;
}

#importFile {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  padding: 24px;
}

.toolbar {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  max-width: 720px;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel-strong);
  box-shadow: 0 8px 22px rgba(38, 34, 26, 0.06);
}

.search-wrap svg {
  color: var(--muted);
}

.search-wrap input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.toolbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.92fr) minmax(420px, 1.08fr);
  gap: 20px;
  min-height: 0;
}

.snippet-column,
.detail-pane {
  min-width: 0;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.eyebrow {
  color: var(--green-dark);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.section-head h2 {
  margin-top: 4px;
  font-size: 1.35rem;
}

.result-count {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.75);
  color: var(--muted);
  font-size: 0.84rem;
  white-space: nowrap;
}

.snippet-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 124px);
  overflow: auto;
  padding: 0 4px 18px 0;
}

.snippet-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  min-height: 126px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.92);
  box-shadow: 0 10px 26px rgba(38, 34, 26, 0.05);
}

.snippet-card.selected {
  border-color: var(--green);
  background: #ffffff;
}

.snippet-card:hover {
  border-color: var(--line-strong);
}

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

.card-topline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.type-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 750;
}

.type-pill.email {
  background: var(--blue-soft);
  color: #25525e;
}

.type-pill.message {
  background: var(--amber-soft);
  color: #78550f;
}

.type-pill svg {
  width: 15px;
  height: 15px;
}

.card-title {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.28;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-subject {
  margin: 4px 0 0;
  overflow: hidden;
  color: var(--green-dark);
  font-size: 0.86rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-preview {
  display: -webkit-box;
  margin: 6px 0 10px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

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

.mini-tag {
  display: inline-flex;
  align-items: center;
  max-width: 130px;
  min-height: 24px;
  padding: 0 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(35, 34, 31, 0.07);
  color: var(--muted);
  font-size: 0.76rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-actions {
  display: flex;
  gap: 6px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
}

.icon-btn.favorited {
  border-color: #d2aa48;
  background: #fff3cb;
  color: #8a650e;
}

.detail-pane {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 90px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 460px;
  padding: 36px;
  color: var(--muted);
  text-align: center;
}

.empty-state svg {
  width: 44px;
  height: 44px;
  color: var(--green);
}

.empty-state h2 {
  color: var(--ink);
  font-size: 1.25rem;
}

.detail-content {
  display: grid;
  gap: 22px;
  padding: 24px;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.detail-title {
  min-width: 0;
}

.detail-title h2 {
  margin-top: 8px;
  overflow-wrap: anywhere;
  font-size: 1.62rem;
  line-height: 1.16;
}

.detail-title p {
  margin-top: 9px;
  color: var(--muted);
}

.detail-actions {
  display: flex;
  gap: 8px;
  align-items: start;
}

.subject-box,
.body-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffefa;
}

.subject-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
}

.subject-box strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.body-box {
  padding: 18px;
}

.body-box pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #2f2d29;
  font: 0.98rem/1.62 var(--font);
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 0.84rem;
}

.snippet-dialog {
  width: min(760px, calc(100vw - 28px));
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel-strong);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.snippet-dialog::backdrop {
  background: rgba(35, 34, 31, 0.36);
  backdrop-filter: blur(3px);
}

.snippet-dialog form {
  display: grid;
  gap: 20px;
}

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

.dialog-head h2 {
  margin-top: 4px;
  font-size: 1.4rem;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 170px;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.full-width {
  grid-column: 1 / -1;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fffefa;
  color: var(--ink);
  outline: 0;
}

input,
select {
  min-height: 42px;
  padding: 0 11px;
}

textarea {
  min-height: 210px;
  padding: 12px;
  resize: vertical;
  line-height: 1.5;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(31, 122, 88, 0.14);
}

.dialog-actions {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 10px;
  align-items: center;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  transform: translateY(14px);
  min-width: 210px;
  max-width: min(420px, calc(100vw - 44px));
  padding: 12px 14px;
  border: 1px solid #155d43;
  border-radius: var(--radius);
  background: #173f30;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.no-results {
  display: grid;
  place-items: center;
  min-height: 260px;
  padding: 26px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 230px minmax(0, 1fr);
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .snippet-list,
  .detail-pane {
    max-height: none;
  }
}

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

  .sidebar {
    position: static;
    padding: 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    padding: 16px;
  }

  .toolbar,
  .section-head,
  .detail-header {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions,
  .backup-actions {
    grid-template-columns: 1fr 1fr;
    display: grid;
    width: 100%;
  }

  .secondary-btn,
  .primary-btn,
  .ghost-btn {
    width: 100%;
  }

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

  .dialog-actions {
    grid-template-columns: 1fr 1fr;
  }

  .dialog-actions span {
    display: none;
  }

  .detail-actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  .snippet-card {
    grid-template-columns: 1fr;
  }

  .card-actions,
  .detail-actions {
    display: grid;
    grid-template-columns: repeat(3, 38px);
  }

  .subject-box {
    align-items: stretch;
    flex-direction: column;
  }

  .subject-box .icon-btn {
    align-self: end;
  }
}
