/* ==========================================================================
   Advanced Word Counter – Professional Stylesheet
   Modern, accessible, responsive, light/dark themes
   ========================================================================== */

:root {
  /* Brand / Accent Colors */
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: rgba(37, 99, 235, 0.08);
  --color-primary-bg: #eff6ff;

  /* Light Theme (default) */
  --bg-body: #f8fafc;
  --bg-surface: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-editor: #ffffff;
  --bg-card: #f1f5f9;
  --bg-input: #f1f5f9;
  --border-color: #e2e8f0;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-on-primary: #ffffff;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-full: 9999px;
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --max-content-width: 1440px;
  --sidebar-width: 360px;
}

[data-theme="dark"] {
  --bg-body: #0f172a;
  --bg-surface: #1e293b;
  --bg-sidebar: #1e293b;
  --bg-editor: #0f172a;
  --bg-card: #334155;
  --bg-input: #1e293b;
  --border-color: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  --color-primary-bg: rgba(37, 99, 235, 0.15);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background-color 0.3s, color 0.3s;
  min-height: 100vh;
}

/* Skip Link */
.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  background: var(--color-primary);
  color: white;
  padding: 0.5rem 1rem;
  z-index: 1000;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  transition: top 0.2s;
}
.skip-link:focus {
  top: 0;
}

/* Layout */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: var(--max-content-width);
  margin: 0 auto;
  overflow: hidden;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  flex-shrink: 0;
  gap: 1rem;
}

.toolbar__title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.toolbar__icon {
  color: var(--color-primary);
}

.toolbar__actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.toolbar__divider {
  width: 1px;
  height: 1.5rem;
  background-color: var(--border-color);
  margin: 0 0.25rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  user-select: none;
}

.btn:hover {
  background-color: var(--bg-card);
  color: var(--text-primary);
}

.btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.btn--icon {
  padding: 0.5rem;
  border-radius: var(--radius-md);
}

.btn--primary {
  background-color: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.btn--primary:hover {
  background-color: var(--color-primary-hover);
  color: white;
}

.btn--outline {
  border: 1px solid var(--border-color);
  background: transparent;
}

.btn--outline:hover {
  background-color: var(--bg-card);
}

.btn--sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

.btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* Content Wrapper (editor + sidebar) */
.content-wrapper {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Editor Section */
.editor-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 1.25rem;
  gap: 1rem;
  background-color: var(--bg-body);
}

/* Chips */
.action-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 0.375rem 0.75rem;
  background-color: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chip:hover {
  background-color: var(--color-primary-bg);
  color: var(--color-primary);
  border-color: var(--color-primary);
}

/* Goal Tracker */
.goal-tracker {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 0.75rem 1rem;
}

.goal-tracker__info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.goal-tracker__label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.goal-tracker__input {
  width: 90px;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.8125rem;
}

.goal-tracker__progress-text {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-left: auto;
}

.goal-tracker__bar {
  height: 6px;
  background-color: var(--bg-card);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.goal-tracker__fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--color-primary), #7c3aed);
  transition: width 0.3s;
  border-radius: var(--radius-full);
}

/* Editor */
.editor-wrapper {
  position: relative;
  background: var(--bg-editor);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  flex: 1;
  min-height: 250px;
}

.editor {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 250px;
  padding: 1rem;
  border: none;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  line-height: 1.7;
  color: var(--text-primary);
  resize: none;
  outline: none;
}

.editor::placeholder {
  color: var(--text-muted);
}

.editor__live-indicator {
  position: absolute;
  bottom: 0.5rem;
  right: 0.75rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  pointer-events: none;
}

/* Highlight Bar */
.highlight-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 0.5rem 0.75rem;
  flex-wrap: wrap;
}

.highlight-bar__label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.highlight-bar__input {
  flex: 1;
  min-width: 120px;
  padding: 0.375rem 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: inherit;
}

.highlight-bar__count {
  font-size: 0.8125rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Highlight Preview Overlay */
.highlight-preview {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem;
  position: relative;
  max-height: 200px;
  overflow-y: auto;
}

.highlight-preview__content {
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.6;
}

.highlight-preview__content mark {
  background-color: #fde047;
  color: #000;
  border-radius: 2px;
  padding: 0 2px;
}

[data-theme="dark"] .highlight-preview__content mark {
  background-color: #eab308;
  color: #000;
}

.highlight-preview__close {
  position: absolute;
  top: 0.25rem;
  right: 0.5rem;
  background: transparent;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-muted);
}

/* Editor Footer */
.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.editor-footer__left, .editor-footer__right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.auto-save-indicator {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

/* Dropdown */
.dropdown {
  position: relative;
  display: inline-flex;
}

.dropdown__menu {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 160px;
  padding: 0.25rem;
  display: none;
  z-index: 20;
}

.dropdown--active .dropdown__menu {
  display: block;
}

.dropdown__item {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: none;
  border: none;
  text-align: left;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.dropdown__item:hover {
  background-color: var(--bg-card);
}

/* Statistics Sidebar */
.stats-sidebar {
  width: var(--sidebar-width);
  border-left: 1px solid var(--border-color);
  background-color: var(--bg-sidebar);
  overflow-y: auto;
  flex-shrink: 0;
  transition: background-color 0.3s;
}

.stats-sidebar__inner {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.stats-sidebar__heading {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.stat-card--primary {
  background: var(--color-primary-bg);
  border: 1px solid var(--color-primary);
}

.stat-card__value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
}

.stat-card__label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.3;
}

.stat-card__label small {
  font-weight: 400;
  color: var(--text-muted);
}

/* Stats Section */
.stats-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.stats-section__title {
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.stats-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.stat-inline {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.stat-inline__value {
  font-weight: 700;
  color: var(--text-primary);
}

.stat-inline__label {
  color: var(--text-muted);
}

/* Readability Card */
.readability-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  text-align: center;
}

.readability-card__score {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-primary);
}

.readability-card__label {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.readability-card__scale {
  height: 6px;
  background: var(--bg-input);
  border-radius: var(--radius-full);
  margin-top: 0.5rem;
  overflow: hidden;
}

.readability-card__scale-fill {
  height: 100%;
  background: linear-gradient(90deg, #ef4444, #eab308, #22c55e);
  width: 0%;
  border-radius: var(--radius-full);
  transition: width 0.3s;
}

.readability-card__range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.625rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Word extremes */
.word-extreme {
  font-family: var(--font-mono);
  word-break: break-all;
}

/* Duplicate words list */
.duplicate-list, .keyword-density-list {
  font-size: 0.8125rem;
}

.duplicate-list__empty, .keyword-density-list__empty {
  color: var(--text-muted);
  font-style: italic;
}

.duplicate-item, .keyword-item {
  display: flex;
  justify-content: space-between;
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--border-color);
}

.duplicate-item:last-child, .keyword-item:last-child {
  border-bottom: none;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 1000;
}

.toast {
  background: var(--text-primary);
  color: var(--bg-body);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: 0.875rem;
  animation: slideIn 0.3s ease;
  max-width: 320px;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Responsive */
@media (max-width: 1024px) {
  .content-wrapper {
    flex-direction: column;
  }
  .stats-sidebar {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border-color);
    max-height: 45vh;
  }
  .editor-section {
    max-height: 55vh;
  }
}

@media (max-width: 640px) {
  .toolbar {
    padding: 0.5rem 1rem;
  }
  .editor-section {
    padding: 0.75rem;
  }
  .stats-grid {
    grid-template-columns: 1fr;
  }
}