:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --ink: #1c1917;
  --muted: #78716c;
  --line: #e4e0d8;
  --accent: #1d4a3a;
  --accent-hover: #16382c;
  --danger: #9f2d2d;
  --danger-bg: #f8ecec;
  --focus: #2f6f57;
  --shadow: 0 1px 0 rgba(28, 25, 23, 0.04);
  --radius: 14px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Figtree, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

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

button { cursor: pointer; }

a { color: var(--accent); }

.app-shell {
  max-width: 1480px;
  margin: 0 auto;
  padding: 0 20px 80px;
}

.app-header {
  padding-top: 28px;
  padding-bottom: 10px;
  margin-bottom: 8px;
}

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

.brand h1 {
  margin: 0;
  font-size: 1.7rem;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.brand h1 span {
  margin-left: 10px;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.toolbar-wrap { margin-bottom: 18px; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.filter-tag {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.86rem;
  font-weight: 600;
}

.filter-tag.all.on {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.filter-tag.on:not(.all) {
  background: var(--tag);
  color: #fff;
  border-color: transparent;
}

input:focus, textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(29, 74, 58, 0.12);
}

.btn {
  border: 0;
  border-radius: 11px;
  padding: 10px 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.btn:hover { background: var(--accent-hover); }

.btn.secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn.secondary:hover { background: #f8f6f2; }

.btn.danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.btn.danger:hover { background: #f1dede; }

.btn.ghost {
  background: transparent;
  color: var(--muted);
  padding-inline: 10px;
}

.btn.ghost:hover { color: var(--ink); background: transparent; }

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
}

.doc-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.card-preview-wrap {
  position: relative;
}

.card-preview {
  display: block;
  width: 100%;
  height: 210px;
  padding: 0;
  border: 0;
  background: #ece9e3;
  overflow: hidden;
}

.card-preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  background: #fff;
}

.card-tags {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  z-index: 1;
}

.card-tag {
  border: 0;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 650;
  line-height: 1.2;
  padding: 3px 8px;
  border-radius: 4px;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-body {
  padding: 10px 12px 8px;
  flex: 1;
  min-width: 0;
}

.card-title {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-line {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  min-width: 0;
}

.card-line + .card-line { margin-top: 4px; }

.card-line span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-line svg,
.card-actions svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.card-actions {
  display: flex;
  border-top: 1px solid var(--line);
  margin-top: auto;
}

.card-actions button {
  flex: 1 1 0;
  background: transparent;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  padding: 10px;
  color: #7a746c;
  min-height: 42px;
}

.card-actions button:last-child { border-right: 0; }

.card-actions button:hover {
  background: #f8f6f2;
  color: var(--ink);
}

.tag-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.tag-choice {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid color-mix(in srgb, var(--tag) 30%, var(--line));
  background: color-mix(in srgb, var(--tag) 12%, #fff);
  color: var(--tag);
  border-radius: 999px;
  padding: 5px 10px 5px 8px;
  font-size: 0.88rem;
  font-weight: 600;
}

.tag-choice.on {
  background: var(--tag);
  color: #fff;
  border-color: transparent;
}

.tag-choice input {
  margin: 0;
  accent-color: currentColor;
}

.select-add {
  display: flex;
  gap: 8px;
  align-items: center;
}

.select-add select { flex: 1; }

.tag-add {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: #2f9d56;
  color: #fff;
  font-size: 1.4rem;
  font-weight: 600;
  line-height: 1;
  padding: 0;
}

.tag-add:hover { background: #248046; }

.tag-new {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.doc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.empty {
  text-align: center;
  padding: 64px 20px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.empty h2 {
  margin: 0 0 6px;
  color: var(--ink);
  font-size: 1.2rem;
}

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

.login-card {
  width: min(100%, 400px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 32px 28px;
}

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

.login-card p {
  margin: 0 0 24px;
  color: var(--muted);
}

.field { display: grid; gap: 6px; margin-bottom: 16px; }

.field label {
  font-size: 0.86rem;
  font-weight: 600;
  color: #44403c;
}

.field input, .field textarea, .field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px 12px;
  background: #fff;
  outline: none;
}

.field textarea { min-height: 160px; resize: vertical; }

.kind-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.kind-toggle button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 11px;
  padding: 14px 10px;
  font-weight: 600;
}

.file-picked {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.kind-toggle button.active {
  border-color: var(--accent);
  background: #eef3f0;
  color: var(--accent);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 23, 0.38);
  display: grid;
  place-items: end center;
  padding: 12px;
  z-index: 20;
}

.modal {
  position: relative;
  width: min(100%, 640px);
  max-height: min(92vh, 860px);
  overflow: auto;
  background: var(--surface);
  border-radius: 18px 18px 12px 12px;
  padding: 22px 22px 18px;
}

.modal h2 {
  margin: 0 40px 16px 0;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
  padding: 0;
}

.modal-close:hover {
  color: var(--ink);
  background: #f4f2ee;
}

.share-hint {
  margin: -8px 0 16px;
  color: var(--muted);
}

.share-row {
  display: flex;
  gap: 8px;
}

.share-link {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px 12px;
  background: #fff;
  outline: none;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.viewer-meta {
  color: var(--muted);
  font-size: 0.92rem;
  margin: -8px 0 16px;
}

.preview {
  background: #f7f5f1;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  min-height: 180px;
}

.preview img, .preview iframe {
  display: block;
  width: 100%;
  min-height: 360px;
  border: 0;
  background: #fff;
}

.preview pre {
  margin: 0;
  padding: 16px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92rem;
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 0 0 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.92rem;
  z-index: 40;
}

@media (min-width: 720px) {
  .overlay { place-items: center; }
  .modal { border-radius: 18px; }
  .app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg);
    box-shadow: 0 14px 18px -10px var(--bg);
  }
}

@media (max-width: 640px) {
  .app-shell { padding: 0 14px 72px; }
  .app-header { padding-top: 18px; }
  .topbar { flex-direction: column; }
  .list { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .card-preview { height: 170px; }
  .btn { min-height: 42px; }
}
