:root {
  color-scheme: dark;
  --bg: #0f1117;
  --panel: #181b23;
  --panel-2: #20242f;
  --line: #303645;
  --text: #f4f6fb;
  --muted: #9ea7b8;
  --accent: #8d7bff;
  --accent-2: #6757dc;
  --danger: #ff7180;
  --success: #65d5a5;
  --warning: #f3c164;
  --radius: 18px;
  --shadow: 0 16px 45px rgba(0, 0, 0, .28);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 85% -10%, rgba(141,123,255,.12), transparent 34rem),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic", sans-serif;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; color: inherit; }
input, textarea, select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 11px 13px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px;
  outline: none;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus {
  border-color: rgba(141,123,255,.8);
  box-shadow: 0 0 0 3px rgba(141,123,255,.12);
}
.app-shell {
  width: min(100%, 980px);
  min-height: 100vh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 14px calc(92px + env(safe-area-inset-bottom));
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin: 0 -14px;
  padding: 14px 16px 12px;
  background: linear-gradient(to bottom, rgba(15,17,23,.98), rgba(15,17,23,.88), rgba(15,17,23,0));
  backdrop-filter: blur(16px);
}
.eyebrow { margin: 0 0 2px; color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: .16em; }
h1 { margin: 0; font-size: clamp(21px, 4vw, 29px); }
.top-actions { display: flex; align-items: center; gap: 8px; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}
.badge-cloud { color: #d9d4ff; border-color: rgba(141,123,255,.38); background: rgba(141,123,255,.1); }
.badge-error { color: #ffd0d5; border-color: rgba(255,113,128,.38); }
.icon-button {
  width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 13px;
  background: var(--panel); font-size: 19px;
}
.toolbar { display: flex; gap: 9px; margin: 7px 0 10px; }
.search-box {
  flex: 1; display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 15px; padding: 0 12px;
  background: var(--panel);
}
.search-box input { border: 0; background: transparent; box-shadow: none; padding-left: 0; }
.search-box span { color: var(--muted); font-size: 21px; }
.filter-panel {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
  gap: 8px;
  padding: 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.filter-panel label, .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #cbd0db;
  font-size: 12px;
}
.summary-row {
  display: flex; justify-content: space-between; align-items: center;
  min-height: 30px; margin: 4px 2px 8px; color: var(--muted); font-size: 12px;
}
.material-list { display: grid; gap: 11px; }
.material-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.card-image-button {
  width: 112px; height: 112px; padding: 0; overflow: hidden;
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel-2);
}
.card-image { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-body { min-width: 0; }
.card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-title { margin: 0; font-size: 16px; line-height: 1.4; overflow-wrap: anywhere; }
.card-source { margin: 5px 0 0; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-time {
  flex: none; padding: 5px 8px; border-radius: 9px;
  background: rgba(141,123,255,.13); color: #ded9ff; font-size: 12px; font-weight: 750;
}
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.chip {
  padding: 4px 7px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel-2); color: #d6dae4; font-size: 10px;
}
.chip.priority-high { color: #ffd0d5; border-color: rgba(255,113,128,.4); background: rgba(255,113,128,.1); }
.chip.status { color: #d8fff0; border-color: rgba(101,213,165,.35); background: rgba(101,213,165,.09); }
.card-memo { margin: 9px 0 0; white-space: pre-wrap; line-height: 1.5; font-size: 13px; }
.card-idea {
  margin: 8px 0 0; padding: 8px 10px; border-left: 3px solid var(--accent);
  border-radius: 8px; background: rgba(141,123,255,.08); color: #ddd9ff;
  white-space: pre-wrap; line-height: 1.45; font-size: 12px;
}
.card-actions { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 7px; margin-top: 11px; }
.primary-mini, .secondary-mini, .danger-mini, .mini-button {
  min-height: 37px; border-radius: 10px; border: 1px solid var(--line); font-size: 11px;
}
.primary-mini { border: 0; background: linear-gradient(135deg, var(--accent), var(--accent-2)); font-weight: 750; }
.secondary-mini, .mini-button { background: var(--panel-2); }
.danger-mini { background: transparent; color: #ffc2c9; border-color: rgba(255,113,128,.32); }
button:disabled { opacity: .38; cursor: default; }
.empty-state {
  margin-top: 48px; padding: 30px 20px; text-align: center;
  border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted);
}
.empty-state h2 { margin: 6px 0; color: var(--text); font-size: 18px; }
.empty-state p { margin: 0 0 17px; font-size: 13px; line-height: 1.5; }
.empty-icon { font-size: 38px; color: var(--accent); }
.primary-button, .secondary-button, .danger-button {
  min-height: 46px; padding: 10px 14px; border-radius: 13px; font-weight: 700;
}
.primary-button { border: 0; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: white; }
.secondary-button { border: 1px solid var(--line); background: var(--panel-2); }
.danger-button { border: 1px solid rgba(255,113,128,.34); background: rgba(255,113,128,.06); color: #ffc3ca; }
.compact { min-height: 46px; padding-inline: 13px; }
.full-button { width: 100%; }
.bottom-nav {
  position: fixed; z-index: 40; left: 0; right: 0; bottom: 0;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: rgba(18,20,27,.93); backdrop-filter: blur(18px);
}
.bottom-nav {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  max-width: 980px; margin: 0 auto;
}
.nav-button {
  min-height: 53px; border: 0; border-radius: 14px; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.nav-button span { font-size: 20px; }
.nav-button small { font-size: 10px; }
.nav-button.active { background: var(--panel-2); color: white; }
.add-button { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: white; }
.modal {
  position: fixed; z-index: 100; inset: 0; display: flex; align-items: flex-end; justify-content: center;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.63); }
.modal-sheet {
  position: relative; width: min(100%, 700px); max-height: min(93dvh, 880px); overflow: auto;
  padding: 10px 16px calc(22px + env(safe-area-inset-bottom));
  border: 1px solid var(--line); border-bottom: 0; border-radius: 24px 24px 0 0;
  background: #171a22; box-shadow: var(--shadow);
}
.editor-sheet { width: min(100%, 760px); }
.modal-handle { width: 42px; height: 5px; margin: 0 auto 12px; border-radius: 999px; background: #4a5060; }
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 13px; }
.modal-header h2 { margin: 0; font-size: 19px; }
.modal-header p { margin: 4px 0 0; font-size: 12px; }
.close-button {
  flex: none; width: 35px; height: 35px; border: 0; border-radius: 50%; background: var(--panel-2); font-size: 19px;
}
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field.full { margin: 12px 0; }
.inline-field { display: grid; grid-template-columns: 1fr auto; gap: 7px; }
.inline-field .mini-button { min-width: 58px; }
.image-editor { display: grid; gap: 9px; }
.image-preview {
  width: 100%; min-height: 165px; max-height: 300px; overflow: hidden;
  border: 1px dashed var(--line); border-radius: 16px; background: var(--panel-2); color: var(--muted);
}
.image-preview img { width: 100%; max-height: 300px; object-fit: cover; display: block; }
.image-preview.empty { display: grid; place-items: center; }
.image-actions { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
.file-button { position: relative; display: inline-flex; align-items: center; justify-content: center; text-align: center; cursor: pointer; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.details-block { margin: 8px 0 13px; }
.details-block summary { padding: 9px 2px; color: #d5d0ff; cursor: pointer; }
.details-fields { margin-top: 8px; }
.save-button { width: 100%; min-height: 51px; margin-top: 6px; }
.notice {
  padding: 11px 12px; margin: 0 0 12px; border: 1px solid rgba(141,123,255,.28);
  border-radius: 13px; background: rgba(141,123,255,.08); color: #d9d5f5; font-size: 12px; line-height: 1.55;
}
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 10px; }
.stack { display: grid; gap: 10px; }
.centered { width: 100%; }
.small { font-size: 11px; }
.muted { color: var(--muted); }
.image-modal {
  position: fixed; z-index: 150; inset: 0; display: grid; place-items: center; padding: 20px;
  background: rgba(0,0,0,.88);
}
.image-modal img { max-width: 100%; max-height: 92vh; object-fit: contain; border-radius: 15px; }
.image-modal-close {
  position: fixed; z-index: 151; top: calc(14px + env(safe-area-inset-top)); right: 15px;
  width: 40px; height: 40px; border: 0; border-radius: 50%; background: rgba(255,255,255,.14); font-size: 20px;
}
.toast {
  position: fixed; z-index: 200; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translate(-50%, 14px); max-width: 92vw; padding: 10px 15px;
  border: 1px solid #444b5b; border-radius: 999px; background: #2b2f39; color: white;
  opacity: 0; pointer-events: none; transition: .2s; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 720px) {
  .app-shell { padding-inline: 22px; padding-bottom: 32px; }
  .topbar { margin-inline: -22px; padding-inline: 24px; }
  .material-list { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .material-card { grid-template-columns: 1fr; align-content: start; }
  .card-image-button { width: 100%; height: 190px; }
  .bottom-nav {
    position: sticky; bottom: 14px; width: 360px; margin-top: 18px;
    border: 1px solid var(--line); border-radius: 18px; padding: 7px; box-shadow: var(--shadow);
  }
  .modal { align-items: center; padding: 20px; }
  .modal-sheet { border-bottom: 1px solid var(--line); border-radius: 24px; }
}
@media (max-width: 680px) {
  .filter-panel { grid-template-columns: 1fr 1fr; }
  .filter-panel .secondary-button { grid-column: span 2; }
}
@media (max-width: 430px) {
  .material-card { grid-template-columns: auto 1fr; }
  .card-image-button { width: 84px; height: 84px; }
  .card-actions { grid-template-columns: repeat(2, 1fr); }
  .image-actions { grid-template-columns: 1fr 1fr; }
  .image-actions .danger-button { grid-column: span 2; }
}
