:root {
  color-scheme: light dark;
  --bg: #fafafa;
  --panel: #ffffff;
  --text: #171717;
  --muted: #737373;
  --border: #d4d4d4;
  --accent: #16a34a;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --warning: #b45309;
  --shadow: 0 16px 50px rgb(0 0 0 / 0.16);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a;
    --panel: #171717;
    --text: #fafafa;
    --muted: #a3a3a3;
    --border: #3f3f46;
    --accent: #22c55e;
    --accent-text: #052e16;
    --shadow: 0 16px 50px rgb(0 0 0 / 0.45);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}
button, input, textarea, select {
  font: inherit;
}
button {
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0 14px;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
button.ghost {
  border-color: transparent;
  background: transparent;
}
button.danger {
  color: var(--danger);
}
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
input, textarea, select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 9px 11px;
}
input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  inline-size: 100%;
  min-inline-size: 0;
  max-inline-size: 100%;
  text-align: left;
}
input[type="date"]::-webkit-date-and-time-value {
  display: block;
  width: 100%;
  min-inline-size: 0;
  text-align: left;
}
textarea {
  min-height: 86px;
  resize: vertical;
}
.app {
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
.shell {
  max-width: 1080px;
  margin: 0 auto;
}
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.brand {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand-mark {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--panel);
}
.brand-copy {
  min-width: 0;
}
.brand-copy h1,
.brand-copy .muted {
  overflow-wrap: anywhere;
}
.topbar-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  margin-left: auto;
  max-width: 44%;
}
.brand-mark svg, .icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 1.35rem; margin-bottom: 2px; }
h2 { font-size: 1.1rem; }
.muted { color: var(--muted); }
.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.toolbar .grow { flex: 1 1 220px; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 12px;
}
.card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
}
.card-button {
  width: 100%;
  text-align: left;
  min-height: auto;
  display: block;
}
.card-title {
  font-weight: 650;
  margin-bottom: 6px;
}
.card-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.9rem;
}
.empty {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
}
.sheet-dialog {
  position: fixed;
  inset: 0;
  z-index: 20;
  width: 100%;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  align-items: end;
}
.sheet-dialog[open] {
  display: grid;
}
.sheet-dialog::backdrop {
  background: rgb(0 0 0 / 0.42);
}
.sheet {
  width: min(100vw, 760px);
  max-height: min(calc(92dvh - env(safe-area-inset-bottom)), 860px);
  margin: 0 auto;
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: auto;
}
.sheet-header, .sheet-footer {
  position: sticky;
  background: var(--panel);
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
}
.sheet-header { top: 0; border-bottom: 1px solid var(--border); }
.sheet-header h2 {
  align-self: center;
  line-height: 1.2;
  margin: 0;
}
.sheet-footer {
  bottom: 0;
  border-top: 1px solid var(--border);
  padding-bottom: max(18px, calc(14px + env(safe-area-inset-bottom)));
}
.sheet-body {
  padding: 16px;
}
.form-grid {
  display: grid;
  gap: 12px;
  min-width: 0;
  margin-top: 16px;
}
.form-grid > * {
  min-width: 0;
}
@media (min-width: 680px) {
  .form-grid.two {
    grid-template-columns: 1fr 1fr;
  }
}
.date-range {
  grid-template-columns: minmax(0, 1fr);
}
.date-range label {
  overflow: hidden;
}
@media (min-width: 430px) {
  .date-range {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
label span {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 5px;
}
label {
  min-width: 0;
  max-width: 100%;
}
.attachment-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}
.attachment {
  display: grid;
  grid-template-columns: 54px 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
}
.attachment > div:nth-child(2) {
  min-width: 0;
}
.attachment-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  position: relative;
}
.icon-button {
  width: 38px;
  min-width: 38px;
  height: 38px;
  min-height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  line-height: 1;
}
.attachment-menu {
  position: relative;
}
.attachment-menu summary {
  list-style: none;
  cursor: pointer;
}
.attachment-menu summary::-webkit-details-marker {
  display: none;
}
.attachment-menu-content {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 4;
  min-width: 154px;
  display: grid;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 6px;
}
.attachment-menu-content button {
  width: 100%;
  justify-content: flex-start;
}
.thumb {
  width: 54px;
  height: 54px;
  border-radius: 6px;
  background: var(--bg);
  object-fit: cover;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.78rem;
}
.thumb-link {
  display: block;
  width: 54px;
  height: 54px;
  border-radius: 6px;
  color: inherit;
  text-decoration: none;
}
.thumb-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.warning {
  color: var(--warning);
}
.export-preview {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 8px;
}
.export-preview table {
  width: 100%;
  border-collapse: collapse;
}
.export-preview th, .export-preview td {
  text-align: left;
  border-bottom: 1px solid var(--border);
  padding: 8px;
}
.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  top: calc(16px + env(safe-area-inset-top));
  z-index: 30;
  max-width: 560px;
  margin: 0 auto;
  background: var(--text);
  color: var(--bg);
  border-radius: 8px;
  padding: 12px 14px;
}
.update-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  top: calc(16px + env(safe-area-inset-top));
  z-index: 35;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 10px;
}
.hidden { display: none !important; }
