/* VN Stock Watcher — Design System */

:root {
  /* Colors */
  --color-bg: #FFFFFF;
  --color-surface: #F8F9FC;
  --color-surface-alt: #F1F3F8;
  --color-border: #E2E6EF;
  --color-text-primary: #111827;
  --color-text-secondary: #6B7280;
  --color-brand-blue: #1A3694;
  --color-brand-orange: #F5A020;
  --color-positive: #16A34A;
  --color-negative: #DC2626;
  --color-muted: #9CA3AF;
  --color-status-live: #22C55E;
  --color-status-stale: #F5A020;
  --color-status-closed: #9CA3AF;

  /* Typography */
  --font-ui: 'Inter', system-ui, sans-serif;
  --font-data: 'JetBrains Mono', 'Courier New', monospace;
  --font-size-xl: 20px;
  --font-size-data: 14px;
  --font-size-header: 10px;
  --font-size-status: 13px;
  --font-weight-data: 500;
  --font-weight-label: 600;

  /* Spacing */
  --row-height: 40px;
  --cell-padding: 7px 20px;
  --header-height: 60px;
  --section-gap: 24px;
  --panel-padding: 28px 32px;
  --table-border-radius: 10px;
  --table-max-width: 1100px;
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: var(--font-ui);
  background: var(--color-bg);
  color: var(--color-text-primary);
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
}

/* ─── App Header ─── */
.app-header {
  display: flex;
  align-items: center;
  height: 60px;
  background: var(--color-brand-blue);
  padding: 0 24px;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.logo-mark {
  width: 32px;
  height: 32px;
  background: #F5A020;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 15px;
  color: #FFFFFF;
  flex-shrink: 0;
}

.logo-text {
  font-size: 17px;
  font-weight: 700;
  color: #FFFFFF;
}

.logo-text em {
  color: #F5A020;
  font-style: normal;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  justify-content: center;
}

.status-label {
  font-size: var(--font-size-status);
  color: rgba(255, 255, 255, 0.85);
}

/* ─── Status Indicator dot ─── */
.status-indicator {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-none      { display: none; }
.status-live      { display: inline-block; background: #FFFFFF; }
.status-stale     { display: inline-block; background: var(--color-brand-orange); animation: pulse 1.4s ease-in-out infinite; }
.status-closed    { display: inline-block; background: var(--color-muted); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}

@keyframes cell-flash {
  0%   { background-color: rgba(245, 160, 32, 0.14); }
  100% { background-color: rgba(245, 160, 32, 0);    }
}

.cell-updated {
  animation: cell-flash 0.7s ease-out;
}

/* ─── Header Actions ─── */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ─── Button Hierarchy (UX-DR10) ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1;
  transition: opacity 0.15s;
  white-space: nowrap;
}

/* Primary */
.btn-primary {
  background: var(--color-brand-blue);
  color: #FFFFFF;
}

.btn-primary:hover:not(:disabled) {
  opacity: 0.9;
}

/* Ghost (in header — white border on dark bg) */
.btn-ghost {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #FFFFFF;
}

.btn-ghost:hover:not(:disabled) {
  border-color: rgba(255, 255, 255, 0.5);
}

/* Disabled */
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Connect button in header — orange primary (AC12) */
.btn-connect-header {
  background: #F5A020;
  color: #FFFFFF;
  border: none;
  font-weight: 700;
}

.btn-connect-header:hover:not(:disabled) {
  opacity: 0.9;
}

/* Connecting… state — override global disabled opacity; pulse brightness instead */
@keyframes btn-connecting-pulse {
  0%, 100% { filter: brightness(1); }
  50%       { filter: brightness(1.22); }
}

.btn-connect-header:disabled {
  opacity: 1;
  cursor: not-allowed;
  animation: btn-connecting-pulse 1.2s ease-in-out infinite;
}

/* ─── Main Content ─── */
.main-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 24px;
  height: calc(100vh - var(--header-height));
  overflow: hidden;
}

/* ─── Credential Panel (UX-DR5) ─── */
.panel--hidden, .panel--hidden.credential-panel { display: none; }

/* Full-screen modal overlay */
.credential-panel {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(17, 24, 39, 0.6);
  z-index: 100;
  padding: 24px;
}

/* Centered white card inside the overlay */
.credential-card {
  background: var(--color-bg);
  border-radius: 12px;
  padding: var(--panel-padding);
  max-width: 480px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.cred-panel-header {
  margin-bottom: 16px;
}

/* Back-to-watchlist link button (UX Component 4) */
.btn-ghost-dark {
  background: transparent;
  border: none;
  color: var(--color-brand-blue);
  font-size: 14px;
  font-weight: 600;
  padding: 4px 0;
  cursor: pointer;
  text-decoration: none;
}

.btn-ghost-dark:hover {
  text-decoration: underline;
}

/* No-credential hint (AC2) */
.no-credential-hint {
  color: #6B7280;
  font-size: 13px;
  text-align: center;
  padding: 20px;
  max-width: var(--table-max-width);
  width: 100%;
}

/* Form hint text below input */
.form-hint {
  font-size: 12px;
  color: var(--color-text-secondary);
}

.panel-title {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: 20px;
}

.trust-box {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #EEF2FF;
  border: 1px solid #C7D2FE;
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 28px;
}

.trust-icon {
  font-size: 16px;
  flex-shrink: 0;
  line-height: 1.5;
}

.trust-box p {
  font-size: 14px;
  color: var(--color-text-secondary);
  line-height: 1.5;
}

/* ─── Form Elements ─── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 20px;
}

.form-group label {
  font-size: 14px;
  font-weight: var(--font-weight-label);
  color: var(--color-text-secondary);
}

.form-group input {
  width: 100%;
  padding: 10px 14px;
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--color-text-primary);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus {
  border-color: var(--color-brand-blue);
}

.form-group input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.font-mono {
  font-family: var(--font-data) !important;
}

#credential-form .btn-primary {
  width: 100%;
  padding: 12px;
  margin-top: 4px;
}

.form-error {
  margin-top: 10px;
  font-size: 12px;
  color: var(--color-negative);
}

/* ─── Card Head (AC19) ─── */
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px 8px;
  border-bottom: 1px solid var(--color-border);
}

.card-head-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-primary);
}

.card-meta {
  font-size: 12px;
  color: #9CA3AF;
}

/* ─── Price Table (UX-DR4) ─── */
#price-table-container {
  width: 100%;
  max-width: var(--table-max-width);
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(26, 54, 148, 0.06);
  overflow: hidden;
}

.price-table__scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.price-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-bg);
}

.price-table thead th {
  padding: var(--cell-padding);
  background: var(--color-bg);
  color: var(--color-brand-blue);
  font-family: var(--font-ui);
  font-size: var(--font-size-header);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 2px solid var(--color-brand-blue);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

/* Sort headers (AC12) */
.sort-header {
  cursor: pointer;
  user-select: none;
}

.sort-icon {
  margin-left: 4px;
  font-size: 0.75em;
  opacity: 0.7;
}

.price-table tbody tr {
  height: var(--row-height);
  border-bottom: 1px solid var(--color-border);
  transition: background 0.1s;
}

.price-table tbody tr:last-child {
  border-bottom: none;
}

.price-table tbody tr:hover {
  background: var(--color-surface);
}

.price-table td {
  padding: var(--cell-padding);
  font-size: var(--font-size-data);
  color: var(--color-text-primary);
}

/* Numeric columns */
.col-price,
.col-volume,
.col-ma20,
.col-ratio,
.col-pct {
  font-family: var(--font-data);
  font-weight: var(--font-weight-data);
  text-align: right;
}

/* Right-align utility used by grouped-view cells */
.r { text-align: right; }

/* Ticker symbol */
.ticker {
  font-family: var(--font-ui);
  font-weight: 700;
  color: var(--color-text-primary);
}

/* % color coding */
.row-positive .pct-cell,
.pos .cell-change {
  color: #16A34A;
  font-weight: 700;
}

.row-negative .pct-cell,
.neg .cell-change {
  color: #DC2626;
  font-weight: 700;
}

.row-neutral .pct-cell,
.flat .cell-change {
  color: var(--color-muted);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 32px;
  color: var(--color-muted);
  font-size: 14px;
}

/* ─── Market-closed ambient dimming (UX-DR9) ─── */
.market-closed td {
  color: var(--color-muted);
  transition: color 0.5s ease;
}

/* ─── Market-closed notice banner ─── */
.market-notice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  margin-bottom: 12px;
  background: rgba(245, 160, 32, 0.10);
  border: 1px solid rgba(245, 160, 32, 0.35);
  border-radius: 6px;
  font-size: 0.875rem;
  color: var(--color-fg);
  line-height: 1.4;
}
.market-notice-icon {
  font-size: 1rem;
  flex-shrink: 0;
  color: #F5A020;
}

/* ─── Accessibility ─── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* ─── Watchlist Editor (UX-DR6) ─── */

/* Edit-mode elements hidden by default */
.btn-remove,
.edit-add-row,
.edit-save-bar {
  display: none;
}

/* Show when container has edit mode class */
#price-table-container.table--edit-mode .btn-remove { display: inline-flex; }
#price-table-container.table--edit-mode .edit-add-row { display: flex; align-items: center; gap: 8px; padding: 10px 20px; border-top: 1px solid var(--color-border); }
#price-table-container.table--edit-mode .edit-save-bar { display: flex; }

/* Edit mode row styling */
#price-table-container.table--edit-mode .price-table tbody tr:not(.edit-add-row) {
  background: #FFFBEB;
  border-top: 1px solid #FDE68A;
}

/* Add-ticker row */
.edit-add-cell {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 20px;
}

.edit-ticker-input {
  padding: 8px 12px;
  font-family: var(--font-data);
  font-size: 14px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  outline: none;
  text-transform: uppercase;
  width: 140px;
}

.edit-ticker-input:focus {
  border-color: var(--color-brand-blue);
}

/* Save/Cancel bar */
.edit-save-bar {
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: 0 0 10px 10px;
}

/* Duplicate ticker inline error — sits right of the + Add button inside edit-add-row */
.ticker-duplicate-error {
  color: var(--color-negative);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

/* Button: + Add */
.btn-add {
  background: var(--color-brand-blue);
  color: #FFFFFF;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.btn-add:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Button: × Remove (destructive outline) */
.btn-destructive {
  background: #FFFFFF;
  border: 1px solid #FCA5A5;
  color: #DC2626;
  border-radius: 6px;
  padding: 4px 10px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.btn-destructive:hover:not(:disabled) {
  background: #FEF2F2;
}

/* Actions column — no right-align */
.col-actions {
  width: 100px;
  text-align: center;
}

/* ─── View Tabs (Story 4.1) ─── */
.view-tabs {
  display: flex;
  align-items: stretch;
}

.view-tab {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: #6B7280;
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-family: var(--font-ui);
}

.view-tab:hover { color: #1A3694; }

.view-tab--active {
  color: #1A3694;
  font-weight: 600;
  border-bottom: 2px solid #1A3694;
  cursor: default;
}

/* View-mode tabs (List / Grouped) — pill style to distinguish from watchlist tabs */
.view-tab[data-mode] {
  padding: 6px 14px;
  border-radius: 6px;
  border-bottom: none;
  background: #F3F4F6;
  color: #6B7280;
  margin: 2px 2px;
}
.view-tab[data-mode]:hover { background: #E5E7EB; color: #374151; }
.view-tab[data-mode].view-tab--active {
  background: #1A3694;
  color: #fff;
  border-bottom: none;
  cursor: default;
}

/* ─── Section Header Rows (single-tbody grouped view) ─── */
.section-header-row td {
  background: #FFF8E7 !important;
  padding: 7px 20px !important;
  border-top: 2px solid #FDDFA0 !important;
  border-bottom: 1px solid #FDDFA0;
  cursor: pointer;
  user-select: none;
}

.section-header-row:hover td { background: #FFF0C8 !important; }

.section-chevron {
  font-size: 9px;
  color: #1a3694;
  display: inline-block;
  width: 12px;
  text-align: center;
  transition: transform 0.15s;
}

.section-range { font-size: 12px; font-weight: 600; color: #1A3694; }
.section-count { font-size: 11px; font-weight: 400; color: #9CA3AF; }

.section-empty-row td {
  padding: 16px 20px !important;
  text-align: center;
  color: #9CA3AF !important;
  font-size: 13px;
  font-style: italic;
}

/* ─── Mode Scroll Constraints ─── */

/* Flat view — monitor mode */
.mode-flat .price-table__scroll { max-height: calc(100vh - 210px); overflow-y: auto; }

/* Flat view — edit mode */
.mode-flat .price-table__scroll.edit-scroll { max-height: calc(100vh - 300px); }

/* Grouped view — scrollable area */
.mode-grouped #grouped-view-panel .price-table__scroll {
  max-height: calc(100vh - 160px);
  overflow-y: auto;
}

/* Grouped table — sticky, sortable column headers */
#grouped-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--color-surface);
  cursor: pointer;
  user-select: none;
}

.sort-ind {
  margin-left: 4px;
  font-size: 0.75em;
  color: #9CA3AF;
}

/* Mode visibility toggles */
.mode-flat #grouped-view-panel { display: none; }
.mode-grouped #flat-view-panel { display: none; }

.app-container.mode-flat #flat-view-panel { display: block; }
.app-container.mode-grouped #grouped-view-panel { display: block; }

/* ─── User Management Screen (Story 7.1) ─── */
.user-mgmt-card {
  background: var(--color-bg);
  border-radius: 12px;
  padding: var(--panel-padding);
  max-width: 800px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  margin: 0 auto;
}

.create-account-section {
  margin-bottom: 32px;
}

.create-account-title {
  font-size: 14px;
  font-weight: 600;
  color: #374151;
  margin: 0 0 12px;
}

.user-table-section {
  margin-top: 8px;
}

.user-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.user-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: #1A3694;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 12px;
  border-bottom: 2px solid #E5E7EB;
}

.user-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #F3F4F6;
  color: var(--color-text);
  vertical-align: middle;
}

.status-dot--active {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #16A34A;
  margin-right: 5px;
  vertical-align: middle;
}

.status-dot--inactive {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9CA3AF;
  margin-right: 5px;
  vertical-align: middle;
}

.btn-sm {
  font-size: 12px;
  padding: 3px 8px;
}

.btn-outline {
  background: #FFFFFF;
  border: 1px solid #D1D5DB;
  color: #374151;
  border-radius: 6px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.btn-outline:hover:not(:disabled) {
  background: #F9FAFB;
}

.btn-deactivate {
  background: #FFFFFF;
  border: 1px solid #FCA5A5;
  color: #DC2626;
  border-radius: 6px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  padding: 3px 8px;
}

.btn-deactivate:hover:not(:disabled) {
  background: #FEF2F2;
}

.btn-reactivate {
  background: #FFFFFF;
  border: 1px solid #86EFAC;
  color: #16A34A;
  border-radius: 6px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  padding: 3px 8px;
}

.btn-reactivate:hover:not(:disabled) {
  background: #F0FDF4;
}

.btn-reset-password {
  margin-right: 6px;
}

.permission-select {
  font-family: var(--font-ui);
  font-size: 12px;
  padding: 3px 6px;
  border: 1px solid #D1D5DB;
  border-radius: 4px;
  background: #FFFFFF;
  color: var(--color-text);
  cursor: pointer;
}

/* ─── Login Page ─── */

/* Override body constraints that are tuned for the scrollless main app */
body.login-page {
  height: auto;
  min-height: 100vh;
  overflow: auto;
}

/* Vertically and horizontally center the card */
.login-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--header-height));
  padding: 32px 16px;
  gap: 0;
}

.login-card {
  background: var(--color-bg);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  padding: 40px;
  width: 100%;
  max-width: 400px;
}

.login-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: 28px;
}

/* Full-width submit button inside the login form */
#login-form .btn-primary {
  width: 100%;
  padding: 12px;
  margin-top: 4px;
  font-size: 15px;
  font-weight: 600;
}

/* Inline error shown on failed login */
.login-error {
  color: #DC2626;
  font-size: 12px;
  margin-bottom: 12px;
  min-height: 18px;
}

/* Session-expired banner above the card */
.session-expired-banner {
  background: #FEF3C7;
  color: #92400E;
  border-radius: 6px;
  padding: 10px 16px;
  font-size: 13px;
  margin-bottom: 16px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

/* ─── User Management Page ─── */

/* Allow the long user table to scroll instead of being clipped */
body.user-mgmt-page {
  height: auto;
  min-height: 100vh;
  overflow: auto;
}

body.user-mgmt-page .main-content {
  height: auto;
  overflow: visible;
  padding: 24px;
  justify-content: flex-start;
}

/* Horizontal (inline) create-account form — matches prototype space-saving layout */
.usermgmt-create {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  padding: 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  margin-bottom: 0;
}

.usermgmt-create .form-group {
  margin-bottom: 0;
  flex-shrink: 0;
}

.usermgmt-create .form-group label {
  font-size: 12px;
  font-weight: 500;
  color: #374151;
}

.usermgmt-create .form-group input,
.usermgmt-create .form-group select {
  padding: 7px 10px;
  font-size: 13px;
  width: auto;
}

#new-username  { width: 130px; }
#new-password  { width: 160px; }
#new-permission { width: 120px; }

.usermgmt-create .btn-primary {
  padding: 8px 16px;
  font-size: 13px;
  white-space: nowrap;
  flex-shrink: 0;
}
