/* ==========================================================================
   Nikki Note — Shared Components
   --------------------------------------------------------------------------
   This file defines `nn-`-prefixed component classes built on top of the
   CSS custom properties declared in tokens.css. Always load tokens.css
   first:

     <link rel="stylesheet" href="../_shared/tokens.css">
     <link rel="stylesheet" href="../_shared/components.css">

   Conventions:
   - Every class is prefixed with `nn-` to avoid colliding with any app's
     existing styles.
   - Only tokens from tokens.css are referenced — no hard-coded colors
     beyond `#fff` for text on solid colored buttons.
   - Modern CSS (flex, grid, gap) is used freely; no build step required.
   ========================================================================== */


/* --------------------------------------------------------------------------
   Shared interaction states
   -------------------------------------------------------------------------- */
.nn-btn:focus-visible,
.nn-input:focus-visible,
.nn-textarea:focus-visible,
.nn-select:focus-visible,
.nn-checkbox:focus-visible,
.nn-radio:focus-visible,
.nn-list-item:focus-visible,
.nn-modal-close:focus-visible,
.nn-toast-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.nn-btn:disabled,
.nn-btn[aria-disabled="true"],
.nn-input:disabled,
.nn-input[aria-disabled="true"],
.nn-textarea:disabled,
.nn-textarea[aria-disabled="true"],
.nn-select:disabled,
.nn-select[aria-disabled="true"],
.nn-list-item[aria-disabled="true"] {
  opacity: .5;
  cursor: not-allowed;
  pointer-events: none;
}


/* --------------------------------------------------------------------------
   Layout helpers
   -------------------------------------------------------------------------- */
.nn-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}

.nn-col {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.nn-spacer {
  flex: 1;
}


/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.nn-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-md);
  border: 1px solid transparent;
  font-family: var(--f-sans);
  font-size: var(--fs-md);
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  color: var(--text);
  background: transparent;
  transition:
    background var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    color var(--dur) var(--ease),
    filter var(--dur) var(--ease);
}

.nn-btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.nn-btn-primary:hover {
  filter: brightness(.95);
}

.nn-btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.nn-btn-ghost:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.nn-btn-subtle {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.nn-btn-subtle:hover {
  background: var(--surface-3);
}

.nn-btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.nn-btn-danger:hover {
  filter: brightness(.95);
}

.nn-btn-sm {
  padding: var(--s-1) var(--s-3);
  font-size: var(--fs-sm);
}

.nn-btn-lg {
  padding: var(--s-3) var(--s-5);
  font-size: var(--fs-lg);
}

.nn-btn-icon {
  padding: var(--s-2);
  aspect-ratio: 1;
  min-width: 36px;
}


/* --------------------------------------------------------------------------
   Inputs
   -------------------------------------------------------------------------- */
.nn-input,
.nn-textarea,
.nn-select {
  display: block;
  width: 100%;
  padding: var(--s-2) var(--s-3);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-family: var(--f-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-normal);
  outline: none;
  transition:
    border-color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease);
}

.nn-input:focus,
.nn-textarea:focus,
.nn-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.nn-input::placeholder,
.nn-textarea::placeholder {
  color: var(--text-subtle);
}

.nn-textarea {
  min-height: 80px;
  resize: vertical;
}

.nn-select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: var(--s-8);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 50%,
    calc(100% - 12px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

/* Search input — wrap with <div class="nn-input-search"><input class="nn-input">…</div> */
.nn-input-search {
  position: relative;
  display: block;
}

.nn-input-search::before {
  content: "🔍";
  position: absolute;
  left: var(--s-3);
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--fs-sm);
  opacity: .55;
  pointer-events: none;
}

.nn-input-search .nn-input {
  padding-left: var(--s-8);
}

.nn-checkbox,
.nn-radio {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
}


/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */
.nn-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.nn-card-header {
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--s-3);
}

.nn-card-title {
  font-size: var(--fs-lg);
  font-weight: 600;
  margin: 0;
  color: var(--text);
}

.nn-card-meta {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.nn-card-body {
  padding: var(--s-4) var(--s-5);
}

.nn-card-footer {
  padding: var(--s-3) var(--s-5);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: var(--s-2);
}


/* --------------------------------------------------------------------------
   Lists
   -------------------------------------------------------------------------- */
.nn-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}

.nn-list-item {
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  transition: background var(--dur-fast) var(--ease);
  color: var(--text);
  text-decoration: none;
}

.nn-list-item:last-child {
  border-bottom: none;
}

.nn-list-item:hover {
  background: var(--surface-2);
}

.nn-list-item.is-active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.nn-list-item-main {
  flex: 1;
  min-width: 0;
}

.nn-list-item-title {
  font-weight: 500;
  font-size: var(--fs-md);
  margin: 0;
  line-height: var(--lh-tight);
}

.nn-list-item-meta {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-top: 2px;
}


/* --------------------------------------------------------------------------
   Modal
   -------------------------------------------------------------------------- */
.nn-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-5);
  z-index: 1000;
}

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

.nn-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.nn-modal-header {
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}

.nn-modal-title {
  font-size: var(--fs-lg);
  font-weight: 600;
  margin: 0;
}

.nn-modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: var(--s-1) var(--s-2);
  font-size: var(--fs-lg);
  line-height: 1;
  border-radius: var(--r-sm);
}

.nn-modal-close:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nn-modal-body {
  padding: var(--s-4) var(--s-5);
  overflow-y: auto;
  flex: 1;
}

.nn-modal-footer {
  padding: var(--s-3) var(--s-5);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: var(--s-2);
}


/* --------------------------------------------------------------------------
   Toolbar
   -------------------------------------------------------------------------- */
.nn-toolbar {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.nn-toolbar-title {
  font-size: var(--fs-lg);
  font-weight: 600;
  margin: 0;
}

.nn-toolbar-spacer {
  flex: 1;
}

.nn-toolbar-search {
  max-width: 320px;
  min-width: 160px;
  flex: 1;
}


/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */
.nn-toast-stack {
  position: fixed;
  top: var(--s-4);
  right: var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  z-index: 1100;
  max-width: 360px;
  pointer-events: none;
}

.nn-toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--text-muted);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  animation: nnToastIn 220ms var(--ease);
  pointer-events: auto;
}

.nn-toast-success { border-left-color: var(--success); }
.nn-toast-warn    { border-left-color: var(--warn); }
.nn-toast-danger  { border-left-color: var(--danger); }
.nn-toast-info    { border-left-color: var(--info); }

.nn-toast-main {
  flex: 1;
  min-width: 0;
}

.nn-toast-title {
  font-weight: 600;
  font-size: var(--fs-md);
  margin: 0;
  line-height: var(--lh-tight);
  color: var(--text);
}

.nn-toast-body {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-top: 2px;
}

.nn-toast-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  font-size: var(--fs-lg);
  line-height: 1;
}

@keyframes nnToastIn {
  from { transform: translateX(110%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}


/* --------------------------------------------------------------------------
   Chip
   -------------------------------------------------------------------------- */
.nn-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 2px var(--s-2);
  font-size: var(--fs-xs);
  font-weight: 500;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--text-muted);
  line-height: 1.4;
  font-family: var(--f-sans);
  letter-spacing: .02em;
  white-space: nowrap;
}

.nn-chip-accent  { background: var(--accent-soft);  color: var(--accent-strong); }
.nn-chip-success { background: var(--success-soft); color: var(--success); }
.nn-chip-warn    { background: var(--warn-soft);    color: var(--warn); }
.nn-chip-danger  { background: var(--danger-soft);  color: var(--danger); }
.nn-chip-info    { background: var(--info-soft);    color: var(--info); }


/* --------------------------------------------------------------------------
   Empty state
   -------------------------------------------------------------------------- */
.nn-empty {
  text-align: center;
  padding: var(--s-10) var(--s-5);
  color: var(--text-muted);
}

.nn-empty-icon {
  font-size: 32px;
  margin-bottom: var(--s-3);
  opacity: .5;
  line-height: 1;
}

.nn-empty-title {
  font-weight: 600;
  color: var(--text);
  margin: 0 0 var(--s-2);
  font-size: var(--fs-md);
}

.nn-empty-body {
  font-size: var(--fs-sm);
  margin: 0;
}
