/* ===== 변수 & 리셋 ===== */
:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-detail: #1c2030;
  --bg-input: #12151e;
  --text: #e8eaed;
  --text-muted: #8b919a;
  --border: #2a2f3a;
  --accent: #3dd6c8;
  --accent-hover: #2ec4b6;
  --accent-dim: rgba(61, 214, 200, 0.12);
  --danger: #e07070;
  --danger-dim: rgba(224, 112, 112, 0.12);
  --important: #d4a843;
  --important-dim: rgba(212, 168, 67, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --font: system-ui, -apple-system, "Segoe UI", "Pretendard", sans-serif;
  --max-width: 1200px;
  --gap: 14px;
  --touch: 44px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ===== 앱 레이아웃 ===== */
.app {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 20px 16px calc(48px + env(safe-area-inset-bottom, 0px));
}

.header {
  margin-bottom: 24px;
}

.header__title {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header__desc {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

.main {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.layout-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

/* ===== 카드 ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.card__title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 14px;
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== 폼 ===== */
.note-form {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.form-group label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
}

input[type="text"],
input[type="search"],
select,
textarea {
  font-family: var(--font);
  font-size: 16px; /* iOS 자동 확대 방지 */
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 11px 14px;
  width: 100%;
  min-height: var(--touch);
  transition: border-color 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
}

textarea {
  resize: vertical;
  min-height: 120px;
  line-height: 1.55;
}

.form-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 6px;
}

.form-actions--create {
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

.form-actions--detail {
  flex-direction: row;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
  min-height: var(--touch);
  padding: 4px 0;
}

.checkbox-label input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

/* ===== 버튼 ===== */
.btn {
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0 20px;
  min-height: var(--touch);
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn:active {
  opacity: 0.85;
}

.btn--primary {
  background: var(--accent);
  color: #0a0e14;
}

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

.btn--save {
  width: 100%;
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  min-height: 36px;
  padding: 0 14px;
  font-size: 0.85rem;
}

.btn--ghost:hover {
  background: var(--bg-input);
  color: var(--text);
}

.btn--danger {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid transparent;
}

.btn--danger:hover {
  background: rgba(224, 112, 112, 0.2);
}

.btn--delete {
  flex: 0 0 auto;
  min-width: 72px;
}

.form-actions--detail .btn--save {
  flex: 1;
  width: auto;
}

.btn--sm {
  min-height: 36px;
  padding: 0 14px;
  font-size: 0.85rem;
}

/* ===== 필터 ===== */
.filter-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap);
}

.filter-search {
  grid-column: 1 / -1;
}

/* ===== 노트 목록 ===== */
.notes-panel {
  box-shadow: var(--shadow);
}

.notes-section {
  margin-top: 0;
}

.notes-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.note-card {
  position: relative;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 14px 12px 16px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s, transform 0.12s;
  min-width: 0;
  -webkit-tap-highlight-color: transparent;
}

.note-card:hover {
  border-color: rgba(61, 214, 200, 0.35);
  background: #1e2230;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.note-card:active {
  transform: scale(0.995);
  background: #1e2230;
}

.note-card--active {
  border-color: var(--accent);
  background: rgba(61, 214, 200, 0.06);
  box-shadow: inset 3px 0 0 var(--accent);
}

.note-card--active:hover {
  border-color: var(--accent);
  background: rgba(61, 214, 200, 0.08);
}

.note-card--important {
  padding-left: 18px;
}

.note-card--important::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--important);
  opacity: 0.7;
}

.note-card--highlight {
  animation: card-highlight 1.2s ease;
}

@keyframes card-highlight {
  0% { box-shadow: 0 0 0 2px var(--accent-dim); }
  100% { box-shadow: none; }
}

.note-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.note-card__title {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.45;
  word-break: break-word;
  flex: 1;
  min-width: 0;
  color: var(--text);
}

.note-card__badge-important {
  flex-shrink: 0;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--important);
  background: var(--important-dim);
  padding: 2px 7px;
  border-radius: 999px;
  margin-top: 3px;
}

.note-card__preview {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.55;
  margin-bottom: 10px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.note-card__footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.note-card__labels {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.note-card__tags {
  display: contents;
}

.note-card__date {
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
}

.badge--category {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  font-weight: 500;
}

.badge--important {
  background: var(--important-dim);
  color: var(--important);
  font-weight: 600;
}

.tag {
  display: inline-block;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
}

/* ===== 빈 상태 ===== */
.empty-state {
  text-align: center;
  padding: 32px 20px;
}

.empty-state--compact {
  padding: 28px 16px;
  background: transparent;
  border: 1px dashed var(--border);
  box-shadow: none;
}

.empty-state__title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.empty-state__hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

[hidden] {
  display: none !important;
}

/* ===== 상세 영역 ===== */
.detail-section {
  scroll-margin-top: 16px;
  background: var(--bg-detail);
  border-color: rgba(61, 214, 200, 0.2);
  display: flex;
  flex-direction: column;
}

.detail-section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.detail-section__label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0;
}

.detail-section__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.note-form--detail {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.form-group--title {
  margin-bottom: 2px;
}

.detail-title-input {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 4px 0 10px;
  min-height: auto;
  line-height: 1.35;
}

.detail-title-input:focus {
  border-bottom-color: var(--accent);
}

.form-group--content textarea {
  min-height: 200px;
  line-height: 1.65;
  font-size: 0.95rem;
}

.checkbox-label--compact {
  min-height: auto;
  padding: 4px 0 8px;
}

.detail-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 0 0 8px;
}

.detail-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.detail-actions .btn--save {
  min-width: 110px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===== 상세 빈 상태 ===== */
.detail-placeholder {
  background: var(--bg-input);
  border: 1px solid var(--border);
  box-shadow: none;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.detail-placeholder__inner {
  text-align: center;
  padding: 32px 24px;
}

.detail-placeholder__icon {
  display: block;
  width: 40px;
  height: 48px;
  margin: 0 auto 14px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  position: relative;
  opacity: 0.5;
}

.detail-placeholder__icon::before {
  content: "";
  position: absolute;
  top: 10px;
  left: 8px;
  right: 8px;
  height: 2px;
  background: var(--border);
  box-shadow: 0 6px 0 var(--border), 0 12px 0 var(--border);
  border-radius: 1px;
}

.detail-placeholder__text {
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
}

.detail-placeholder__hint {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ===== 토스트 ===== */
.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: rgba(26, 29, 39, 0.92);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  max-width: calc(100vw - 32px);
  text-align: center;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== 반응형: 태블릿/PC ===== */
@media (min-width: 480px) {
  .app {
    padding: 32px 20px 64px;
  }

  .card {
    padding: 20px;
  }

  .header__title {
    font-size: 1.75rem;
  }

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

  .filter-row {
    grid-template-columns: 1fr 1fr;
  }

  .form-actions--create {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .btn--save {
    width: auto;
    min-width: 120px;
  }
}

@media (min-width: 900px) {
  .app {
    padding: 36px 32px 64px;
  }

  .header {
    margin-bottom: 28px;
  }

  .main {
    display: grid;
    grid-template-columns: 2fr 3fr;
    gap: 24px;
    align-items: start;
  }

  .layout-col--left {
    position: sticky;
    top: 24px;
  }

  .layout-col--left .form-row,
  .layout-col--left .filter-row {
    grid-template-columns: 1fr;
  }

  .layout-col--right {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: calc(100vh - 180px);
  }

  .notes-list {
    max-height: min(440px, 42vh);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
  }

  .notes-list::-webkit-scrollbar {
    width: 6px;
  }

  .notes-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 999px;
  }

  .detail-placeholder {
    flex: 1;
    min-height: 240px;
  }

  .detail-section {
    flex: 1;
    min-height: 320px;
  }

  .form-group--content textarea {
    min-height: 260px;
  }
}

@media (min-width: 640px) and (max-width: 899px) {
  .app {
    padding: 40px 24px 64px;
  }
}

@media (max-width: 430px) {
  .app {
    padding-left: 14px;
    padding-right: 14px;
  }

  .card {
    padding: 16px 14px;
  }

  .form-actions--detail,
  .detail-actions {
    flex-direction: column-reverse;
  }

  .form-actions--detail .btn,
  .detail-actions .btn {
    width: 100%;
  }

  .form-actions--detail .btn--delete,
  .detail-actions .btn--delete {
    min-width: unset;
  }
}
