/* ================================================================
   Canifa Note Extension — shadcn/ui Design System
   Dark-first, token-driven, Canifa red accent
   ================================================================ */

/* ---- Design Tokens ---- */
:root {
  /* Surface */
  --background: hsl(240 10% 3.9%);
  --foreground: hsl(0 0% 98%);
  --card: hsl(240 10% 3.9%);
  --card-foreground: hsl(0 0% 98%);
  --popover: hsl(240 10% 3.9%);
  --popover-foreground: hsl(0 0% 98%);

  /* Canifa Red Accent */
  --primary: hsl(2 78% 53%);
  --primary-foreground: hsl(0 0% 100%);

  /* Secondary / Muted */
  --secondary: hsl(240 3.7% 15.9%);
  --secondary-foreground: hsl(0 0% 98%);
  --muted: hsl(240 3.7% 15.9%);
  --muted-foreground: hsl(240 5% 64.9%);
  --accent: hsl(240 3.7% 15.9%);
  --accent-foreground: hsl(0 0% 98%);

  /* Feedback */
  --destructive: hsl(0 62.8% 30.6%);
  --destructive-foreground: hsl(0 0% 98%);
  --success: hsl(142 71% 45%);
  --success-foreground: hsl(0 0% 100%);
  --warning: hsl(48 96% 53%);

  /* Border / Input / Ring */
  --border: hsl(240 3.7% 15.9%);
  --input: hsl(240 3.7% 15.9%);
  --ring: hsl(2 78% 53%);

  /* Radius */
  --radius: 8px;

  /* Typography */
  --font-sans: "Geist", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, monospace;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);

  /* Motion */
  --duration-fast: 150ms;
  --duration-normal: 200ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ================================================================
   Base Reset
   ================================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: var(--background);
  color: var(--foreground);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  width: 380px;
  min-height: 200px;
  overflow-x: hidden;
}

/* ================================================================
   Animations
   ================================================================ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ================================================================
   Popup Container
   ================================================================ */
.popup-container {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  animation: fadeIn var(--duration-normal) var(--ease-out);
}

/* ================================================================
   Header
   ================================================================ */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  color: var(--foreground);
  letter-spacing: -0.02em;
}

.header-brand-logo {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  object-fit: contain;
}

.header-brand-name {
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.02em;
}

.header-brand-suffix {
  font-weight: 400;
  color: var(--muted-foreground);
  font-size: 13px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted-foreground);
}

/* Status Dots */
.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.connected {
  background: var(--success);
  box-shadow: 0 0 6px hsl(142 71% 45% / 0.4);
  animation: pulse-dot 2s ease-in-out infinite;
}

.status-dot.disconnected {
  background: var(--muted-foreground);
}

.status-text {
  font-size: 11px;
  color: var(--muted-foreground);
}

/* ================================================================
   Content
   ================================================================ */
.content {
  padding: 14px 16px;
  animation: fadeIn 0.2s var(--ease-out);
}

/* ================================================================
   Note Form
   ================================================================ */
.note-form {
  display: flex;
  flex-direction: column;
  animation: slideUp 0.2s var(--ease-out);
}

/* Textarea */
.note-textarea {
  display: block;
  width: 100%;
  min-height: 96px;
  max-height: 200px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--background);
  color: var(--foreground);
  padding: 10px 12px;
  font-size: 14px;
  font-family: var(--font-sans);
  line-height: 1.6;
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}

.note-textarea::placeholder {
  color: var(--muted-foreground);
}

.note-textarea:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 2px hsl(2 78% 53% / 0.15);
}

/* ================================================================
   Source Info
   ================================================================ */
.source-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted-foreground);
  padding: 6px 10px;
  background: var(--secondary);
  border-radius: calc(var(--radius) - 2px);
  margin-top: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-icon {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  color: var(--muted-foreground);
}

/* ================================================================
   Labels
   ================================================================ */
.label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--muted-foreground);
  letter-spacing: 0.01em;
}

.label-hint {
  font-size: 11px;
  color: var(--muted-foreground);
  margin-top: 4px;
  opacity: 0.8;
}

/* ================================================================
   Tags
   ================================================================ */
.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 4px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px 10px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted-foreground);
  font-family: var(--font-sans);
  user-select: none;
}

.tag-chip:hover {
  border-color: hsl(2 78% 53% / 0.5);
  color: var(--foreground);
  background: hsl(2 78% 53% / 0.06);
}

.tag-chip.selected {
  background: var(--primary);
  color: var(--primary-foreground);
  border-color: var(--primary);
}

.tag-chip.selected:hover {
  filter: brightness(1.1);
  background: var(--primary);
  color: var(--primary-foreground);
}

.tag-chip-icon {
  font-size: 11px;
  opacity: 0.6;
}

.tag-input-inline {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px 10px;
  border-radius: 9999px;
  font-size: 12px;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  font-family: var(--font-sans);
}

.tag-input-inline:hover {
  border-color: var(--primary);
  color: var(--foreground);
}

.tag-input-field {
  border: none;
  outline: none;
  background: transparent;
  font-size: 12px;
  font-family: var(--font-sans);
  color: var(--foreground);
  width: 70px;
}

/* ================================================================
   Form Group / Select
   ================================================================ */
.form-group {
  margin-bottom: 12px;
}

.select {
  display: block;
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--background);
  color: var(--foreground);
  padding: 8px 32px 8px 12px;
  font-size: 13px;
  font-family: var(--font-sans);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}

.select:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 2px hsl(2 78% 53% / 0.15);
}

/* ================================================================
   Input
   ================================================================ */
.input {
  display: block;
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--background);
  color: var(--foreground);
  padding: 8px 12px;
  font-size: 13px;
  font-family: var(--font-sans);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}

.input:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 2px hsl(2 78% 53% / 0.15);
}

.input::placeholder {
  color: var(--muted-foreground);
}

/* ================================================================
   Visibility Selector
   ================================================================ */
.visibility-selector {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  font-family: var(--font-sans);
}

.visibility-selector:hover {
  border-color: hsl(2 78% 53% / 0.5);
  color: var(--foreground);
}

/* ================================================================
   Buttons
   ================================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  border: none;
  padding: 8px 16px;
  transition: all var(--duration-fast) var(--ease-out);
}

.btn:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
}

.btn-primary:hover {
  background: hsl(2 78% 48%);
}

.btn-secondary {
  background: var(--secondary);
  color: var(--secondary-foreground);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: hsl(240 3.7% 20%);
}

.btn-ghost {
  background: transparent;
  color: var(--muted-foreground);
  padding: 6px 10px;
}

.btn-ghost:hover {
  background: var(--accent);
  color: var(--foreground);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: calc(var(--radius) - 2px);
}

.btn-full {
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Icon Button */
.btn-icon {
  padding: 6px;
  width: 28px;
  height: 28px;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--muted-foreground);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--duration-fast) var(--ease-out);
  font-family: var(--font-sans);
}

.btn-icon:hover {
  background: var(--accent);
  color: var(--foreground);
}

/* ================================================================
   Action Bar (bottom)
   ================================================================ */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 12px;
  border-top: 1px solid var(--border);
  background: var(--card);
}

.action-bar-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.action-bar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ================================================================
   Badges & Messages
   ================================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 500;
}

.badge-success {
  background: hsl(142 71% 45% / 0.12);
  color: var(--success);
  border: 1px solid hsl(142 71% 45% / 0.2);
}

.badge-error {
  background: hsl(0 62.8% 30.6% / 0.12);
  color: hsl(0 72% 51%);
  border: 1px solid hsl(0 62.8% 30.6% / 0.2);
}

.error {
  padding: 8px 12px;
  margin-top: 8px;
  background: hsl(0 62.8% 30.6% / 0.1);
  color: hsl(0 72% 51%);
  border-radius: var(--radius);
  font-size: 12px;
  border: 1px solid hsl(0 62.8% 30.6% / 0.2);
  animation: fadeIn var(--duration-fast) var(--ease-out);
}

.success {
  padding: 8px 12px;
  margin-bottom: 8px;
  background: hsl(142 71% 45% / 0.1);
  color: var(--success);
  border-radius: var(--radius);
  font-size: 12px;
  border: 1px solid hsl(142 71% 45% / 0.2);
}

/* Inline Banner */
.inline-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--muted-foreground);
}

.inline-banner-icon {
  flex-shrink: 0;
  font-size: 14px;
}

.inline-banner a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.inline-banner a:hover {
  color: hsl(2 78% 60%);
}

/* ================================================================
   Settings
   ================================================================ */
.settings-section {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.settings-section:last-child {
  border-bottom: none;
}

.settings-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--foreground);
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.settings-item-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--foreground);
}

.settings-item-desc {
  font-size: 11px;
  color: var(--muted-foreground);
  margin-top: 1px;
}

.settings-input-group {
  display: flex;
  gap: 6px;
}

.settings-input-group .input {
  flex: 1;
}

/* ================================================================
   Loading Spinner
   ================================================================ */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}

/* ================================================================
   Scrollbar
   ================================================================ */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 9999px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--muted-foreground);
}