:root {
  color-scheme: light;
  --bg: #f8faf9;
  --surface: #ffffff;
  --surface-soft: #f3f6f4;
  --text: #1d2520;
  --muted: #6b746e;
  --line: #dfe6e1;
  --line-strong: #c8d3cc;
  --accent: #2f7658;
  --accent-soft: #e4f2eb;
  --danger: #b63838;
  --favorite: #bf8b11;
  --shadow: 0 14px 40px rgba(27, 37, 31, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

body:not(.is-authenticated) .app-shell,
body:not(.is-authenticated) .fab-add,
body:not(.is-authenticated) .selection-box,
body:not(.is-authenticated) .modal-backdrop,
body:not(.is-authenticated) .confirm-backdrop {
  display: none;
}

body.is-authenticated .login-screen,
.login-screen[hidden] {
  display: none;
}

.login-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  display: grid;
  gap: 16px;
  width: min(390px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 22px;
}

.login-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.login-card input {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  color: var(--text);
}

.login-card input:focus {
  border-color: var(--line-strong);
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.logout-button {
  width: 100%;
  min-height: 40px;
  margin-top: auto;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  text-align: left;
}

.logout-button:hover {
  border-color: var(--line-strong);
  color: var(--text);
}


.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(210px, 300px) minmax(180px, 640px);
  gap: 18px;
  align-items: center;
  min-height: 72px;
  padding: 12px 24px;
  background: rgba(248, 250, 249, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 700;
}

.brand h1,
.brand p,
.view-header h2,
.view-header p,
.empty-state h3,
.empty-state p {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.2;
}

.brand p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 640px;
  min-height: 46px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
}

.search:focus-within {
  border-color: var(--line-strong);
  background: var(--surface);
}

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

.layout {
  display: grid;
  grid-template-columns: 244px 1fr;
  min-height: calc(100vh - 72px);
}

.bulk-toolbar {
  position: sticky;
  top: 72px;
  z-index: 18;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 54px;
  padding: 8px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 22px rgba(27, 37, 31, 0.08);
  backdrop-filter: blur(14px);
}

.bulk-toolbar[hidden] {
  display: none;
}

.bulk-toolbar strong {
  margin-right: 8px;
  font-size: 14px;
}

.bulk-toolbar input {
  width: 180px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
}

.bulk-toolbar input:focus {
  border-color: var(--line-strong);
}

.danger-text {
  color: var(--danger);
}

.sidebar {
  position: sticky;
  top: 72px;
  align-self: start;
  height: calc(100vh - 72px);
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 18px 12px 24px;
  border-right: 1px solid var(--line);
  background: var(--bg);
  overflow: auto;
}

.nav-section {
  display: grid;
  gap: 4px;
}

.nav-item,
.tag-filter {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.nav-item:hover,
.tag-filter:hover,
.nav-item.active,
.tag-filter.active {
  background: var(--accent-soft);
}

.nav-item strong,
.tag-filter strong {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.nav-icon {
  color: var(--muted);
  text-align: center;
}

.tag-list {
  display: grid;
  gap: 4px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.empty-tags {
  margin: 0;
  padding: 8px 12px;
  color: var(--muted);
  font-size: 13px;
}

.main {
  min-width: 0;
  padding: 24px clamp(16px, 4vw, 42px) 48px;
}

.composer {
  display: none;
  max-width: 720px;
  margin: 0 auto 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 5px 18px rgba(27, 37, 31, 0.07);
  overflow: hidden;
}

body.mobile-compose-open .composer {
  display: block;
}

.composer-title,
.composer-content,
.composer-tags,
.modal-title,
.modal-content,
.modal-tags {
  display: block;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.composer-title {
  height: 52px;
  padding: 0 18px;
  font-size: 16px;
}

.composer-content,
.composer-tags,
.composer-actions {
  display: none;
}

.composer.expanded .composer-content,
.composer.expanded .composer-tags,
.composer.expanded .composer-actions {
  display: block;
}

.composer-content {
  min-height: 112px;
  padding: 0 18px 14px;
  resize: vertical;
  line-height: 1.65;
}

.composer-tags {
  min-height: 44px;
  padding: 0 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.composer-actions {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 12px 18px;
  color: var(--muted);
  font-size: 13px;
}

.composer.expanded .composer-actions {
  display: flex;
}

.composer-actions span {
  flex: 1;
  min-width: 0;
}

.primary-button,
.text-button {
  min-height: 36px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid transparent;
}

.primary-button {
  background: var(--accent);
  color: white;
  font-weight: 700;
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.text-button {
  background: transparent;
  color: var(--muted);
}

.text-button:hover {
  background: var(--surface-soft);
  color: var(--text);
}

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

.view-header h2 {
  font-size: 22px;
}

.view-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.ideas-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.idea-card {
  position: relative;
  display: grid;
  gap: 12px;
  min-height: 150px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: left;
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

.idea-card.selected,
.idea-card.selecting {
  border-color: #8bbcf8;
  background: #f2f8ff;
  box-shadow: 0 0 0 3px rgba(139, 188, 248, 0.28);
}

.selection-check {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  display: none;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #2f70c8;
  color: white;
  font-size: 13px;
  font-weight: 700;
}

.idea-card.selected .selection-check,
.idea-card.selecting .selection-check {
  display: grid;
}

.idea-card.selected h3,
.idea-card.selecting h3 {
  padding-left: 28px;
}

.selection-box {
  position: fixed;
  z-index: 80;
  border: 1px solid #8bbcf8;
  background: rgba(139, 188, 248, 0.18);
  pointer-events: none;
}

.selection-box[hidden] {
  display: none;
}

body.selecting-cards {
  user-select: none;
  cursor: crosshair;
}

.idea-card[draggable="true"] {
  cursor: grab;
}

.idea-card.dragging {
  cursor: grabbing;
  border: 2px dashed #9fc4f4;
  background: #eef6ff;
  box-shadow: none;
  opacity: 1;
}

.idea-card.dragging > * {
  opacity: 0;
}

.drag-preview {
  position: fixed;
  top: -1200px;
  left: -1200px;
  z-index: 1000;
  pointer-events: none;
  border-color: #8bbcf8;
  background: #dcebff;
  box-shadow: 0 10px 24px rgba(40, 84, 130, 0.22);
}

.idea-card.drag-over {
  border-color: #8bbcf8;
  background: #f2f8ff;
  box-shadow: 0 0 0 3px rgba(139, 188, 248, 0.28), 0 10px 24px rgba(27, 37, 31, 0.1);
}

.idea-card.dragging:hover,
.idea-card.drag-over:hover {
  border-color: #8bbcf8;
  box-shadow: 0 0 0 3px rgba(139, 188, 248, 0.28), 0 10px 24px rgba(27, 37, 31, 0.1);
  transform: none;
}

.idea-card:hover {
  border-color: var(--line-strong);
  box-shadow: 0 10px 24px rgba(27, 37, 31, 0.1);
  transform: translateY(-1px);
}

.idea-card h3 {
  margin: 0;
  padding-right: 112px;
  font-size: 16px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.idea-card p {
  margin: 0;
  color: #3f4a43;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.idea-card p a {
  color: #2357c6;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.idea-card p a:hover {
  color: #173f94;
}

.idea-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
  color: var(--muted);
  font-size: 12px;
}

.idea-meta span {
  white-space: nowrap;
}

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

.tag {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: #466354;
  font-size: 12px;
}

.card-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 4px;
}

.icon-button,
.icon-action {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}

.icon-button:hover,
.icon-action:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.icon-action.favorite.active {
  color: var(--favorite);
}

.icon-action.danger:hover {
  color: var(--danger);
}

.empty-state {
  margin-top: 80px;
  text-align: center;
}

.empty-state h3 {
  font-size: 18px;
}

.empty-state p {
  margin-top: 8px;
  color: var(--muted);
}

.modal-backdrop,
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(20, 28, 23, 0.38);
}

.confirm-backdrop {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(20, 28, 23, 0.38);
}

.modal-backdrop[hidden] {
  display: none;
}

.confirm-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(680px, calc(100vw - 28px));
  margin: 7vh auto 0;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.confirm-modal {
  width: min(420px, calc(100vw - 32px));
  margin: 18vh auto 0;
  padding: 24px;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.confirm-modal h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.35;
}

.confirm-modal p {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

.danger-button {
  min-height: 36px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--danger);
  color: white;
  font-weight: 700;
}

.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  color: var(--muted);
  font-size: 13px;
}

.modal-title {
  min-height: 62px;
  padding: 2px 22px;
  font-size: 22px;
  font-weight: 700;
}

.modal-content {
  min-height: 240px;
  padding: 0 22px 18px;
  overflow: auto;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.modal-content:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
}

.modal-content a {
  color: #2357c6;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.modal-content a:hover {
  color: #173f94;
}

.modal-tags {
  min-height: 48px;
  padding: 0 22px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.modal-actions {
  display: flex;
  gap: 4px;
}

.modal-status {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.modal-status span {
  overflow-wrap: anywhere;
}

.menu-button {
  display: none;
}

.menu-button span {
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.sidebar-backdrop {
  display: none;
}

.fab-add {
  position: fixed;
  right: 28px;
  bottom: calc(28px + env(safe-area-inset-bottom));
  z-index: 45;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  box-shadow: 0 12px 28px rgba(47, 118, 88, 0.32);
  font-size: 32px;
  line-height: 1;
}

body.mobile-compose-open .fab-add,
body.modal-open .fab-add,
body.sidebar-open .fab-add {
  display: none;
}

.icon-action:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

body.sidebar-open {
  overflow: hidden;
}

@media (max-width: 1280px) {
  .ideas-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .ideas-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: auto 1fr auto;
    gap: 12px;
    padding: 10px 14px;
  }

  .brand p {
    display: none;
  }

  .search {
    grid-column: 1 / -1;
    max-width: none;
  }

  .menu-button {
    display: grid;
  }

  .layout {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 60;
    width: min(82vw, 300px);
    height: 100vh;
    padding-top: 18px;
    transform: translateX(-104%);
    transition: transform 160ms ease;
    box-shadow: var(--shadow);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  body.sidebar-open .sidebar-backdrop {
    display: block;
  }

  .main {
    padding: 18px 14px 36px;
  }

  .fab-add {
    right: 18px;
    bottom: calc(18px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 560px) {
  .ideas-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .idea-card {
    min-height: 132px;
    padding: 12px;
  }

  .idea-card h3 {
    padding-right: 84px;
    font-size: 14px;
  }

  .idea-card p {
    font-size: 12px;
    line-height: 1.5;
  }

  .card-actions {
    top: 6px;
    right: 6px;
  }

  .icon-action {
    width: 30px;
    height: 30px;
  }

  .tag {
    min-height: 22px;
    padding: 0 6px;
    font-size: 11px;
  }

  .idea-meta {
    font-size: 11px;
  }

  .composer-actions {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .composer-actions span {
    flex-basis: 100%;
  }

  .primary-button,
  .text-button {
    flex: 1;
  }

  .modal {
    width: calc(100vw - 28px);
    max-height: calc(100vh - 40px);
    margin: 20px auto;
    border-radius: 8px;
    overflow: auto;
  }

  .modal-content {
    min-height: 34vh;
  }
}
