/* ============================================================
   TRADEDESK — Component Library
   Enterprise Financial Operations Components
   ============================================================ */

/* ── Button System (Section 42) ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--btn-height);
  padding: 0 14px;
  font-size: 13px;
  font-weight: 550;
  border-radius: var(--radius-btn);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
  line-height: 1;
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

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

/* Primary Button (Blue / Accent for Create, Confirm, Save) */
.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #ffffff;
}

/* Secondary Button (Neutral with subtle border for Cancel, View, Filter) */
.btn-secondary {
  background-color: var(--surface);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-secondary:hover {
  background-color: var(--surface-muted);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

/* Ghost / Tertiary Button (Subtle text button for More, Secondary links) */
.btn-ghost {
  background-color: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}

.btn-ghost:hover {
  background-color: var(--surface-muted);
  color: var(--text-primary);
}

/* Destructive Button */
.btn-danger {
  background-color: var(--danger);
  color: #ffffff;
  border-color: var(--danger);
}

.btn-danger:hover {
  background-color: #b91c1c;
  border-color: #b91c1c;
}

/* Button Sizes */
.btn-sm {
  height: var(--btn-sm-height);
  padding: 0 10px;
  font-size: 12px;
  border-radius: var(--radius-btn);
  gap: 5px;
}

.btn svg,
.btn-sm svg,
.btn-icon svg {
  width: 15px;
  height: 15px;
  max-width: 15px;
  max-height: 15px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

.btn-sm svg {
  width: 13px;
  height: 13px;
  max-width: 13px;
  max-height: 13px;
}

.btn-icon {
  width: var(--btn-height);
  padding: 0;
}

.btn-icon.btn-sm {
  width: var(--btn-sm-height);
}

/* ── Segmented Control / Filter Tabs (Section 14) ── */
.segmented-control {
  display: inline-flex;
  align-items: center;
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.segmented-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  height: 28px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: 4px;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.segmented-btn:hover {
  color: var(--text-primary);
  background-color: rgba(0, 0, 0, 0.03);
}

.segmented-btn.active {
  background-color: var(--surface);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.segmented-badge {
  display: inline-block;
  padding: 1px 5px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 3px;
  background-color: var(--bg-subtle);
  color: var(--text-muted);
}

.segmented-btn.active .segmented-badge {
  background-color: var(--primary-subtle);
  color: var(--primary);
}

/* ── Form Controls (Section 31) ── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  height: var(--input-height);
  padding: 0 12px;
  font-size: 13.5px;
  color: var(--text-primary);
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-subtle);
}

.form-input::placeholder {
  color: var(--text-muted);
  font-size: 13px;
}

.form-input.tabular-num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.form-textarea {
  height: auto;
  min-height: 80px;
  padding: 10px 12px;
  resize: vertical;
}

.form-hint {
  font-size: 11.5px;
  color: var(--text-muted);
}

.form-error {
  font-size: 11.5px;
  color: var(--danger);
  font-weight: 500;
}

/* Grid Layouts for Forms */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

@media (max-width: 768px) {
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }
}

/* ── Financial Tables (Section 16-24, 55, 56) ── */
.table-container {
  width: 100%;
  overflow-x: auto;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}

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

.table thead {
  background-color: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
}

.table th {
  padding: 10px 14px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  white-space: nowrap;
}

.table th.num {
  text-align: right;
}

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

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

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

.table td {
  padding: 10px 14px;
  color: var(--text-primary);
  vertical-align: middle;
}

.table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* Customer Cell Grouping (Section 16 & 17) */
.cell-customer {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cell-customer-top {
  display: flex;
  align-items: center;
  gap: 6px;
}

.cell-customer-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  text-decoration: none;
}

.cell-customer-name:hover {
  color: var(--primary);
}

.cell-customer-id {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-subtle);
  padding: 1px 4px;
  border-radius: 3px;
  border: 1px solid var(--border-subtle);
}

.cell-customer-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Financial P&L Cell (Section 19 & 59) */
.cell-pl {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  font-variant-numeric: tabular-nums;
}

.cell-pl-val {
  font-size: 13.5px;
  font-weight: 600;
}

.cell-pl-pct {
  font-size: 11.5px;
  font-weight: 500;
}

.pl-positive,
.text-positive,
.text-success {
  color: var(--success) !important;
}

.pl-negative,
.text-negative,
.text-danger {
  color: var(--danger) !important;
}

.pl-zero,
.text-zero {
  color: var(--text-muted) !important;
}

/* ── Status Badges (Section 34) ── */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 22px;
  padding: 0 7px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border-radius: var(--radius-badge);
  line-height: 1;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge-success,
.badge-active,
.badge-executed,
.badge-approved,
.badge-buy {
  background-color: var(--success-bg);
  color: var(--success);
  border-color: var(--success-border);
}

.badge-danger,
.badge-inactive,
.badge-rejected,
.badge-cancelled,
.badge-sell {
  background-color: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger-border);
}

.badge-warning,
.badge-pending {
  background-color: var(--warning-bg);
  color: var(--warning);
  border-color: var(--warning-border);
}

.badge-neutral,
.badge-draft {
  background-color: var(--neutral-badge-bg);
  color: var(--neutral-badge);
  border-color: var(--neutral-badge-border);
}

.badge-primary,
.badge-deposit {
  background-color: var(--primary-subtle);
  color: var(--primary);
  border-color: var(--primary-border);
}

/* ── Action Dropdown Menu (Section 24) ── */
.action-dropdown-wrapper {
  position: relative;
  display: inline-block;
}

.action-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background-color: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-dropdown);
  min-width: 170px;
  z-index: var(--z-dropdown);
  display: none;
  padding: 4px;
}

.action-menu.show {
  display: block;
}

.action-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-primary);
  border-radius: 4px;
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
  transition: background-color var(--transition-fast);
}

.action-menu-item:hover {
  background-color: var(--surface-muted);
}

.action-menu-item svg {
  width: 14px;
  height: 14px;
  max-width: 14px;
  max-height: 14px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  flex-shrink: 0;
}

.action-menu-item.danger {
  color: var(--danger);
}

.action-menu-item.danger:hover {
  background-color: var(--danger-bg);
}

.action-menu-divider {
  height: 1px;
  background-color: var(--border-subtle);
  margin: 4px 0;
}

/* ── Restrained Cards & Content Panels (Section 4 & 5) ── */
.card,
.panel {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 18px 20px;
}

/* ── Customer Account Summary Strip (Section 27) ── */
.account-summary-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 16px 20px;
  margin-bottom: 20px;
  divide-x: 1px solid var(--border);
}

.summary-metric-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 16px;
  border-right: 1px solid var(--border);
}

.summary-metric-item:first-child {
  padding-left: 0;
}

.summary-metric-item:last-child {
  padding-right: 0;
  border-right: none;
}

.summary-metric-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.summary-metric-val {
  font-size: 20px;
  font-weight: 650;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.summary-metric-sub {
  font-size: 11.5px;
  color: var(--text-muted);
}

@media (max-width: 768px) {
  .account-summary-strip {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }
  .summary-metric-item {
    border-right: none;
    padding: 0;
  }
}

/* ── Navigation Tabs (Section 28) ── */
.profile-tabs-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
}

.profile-tab-btn {
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.profile-tab-btn:hover {
  color: var(--text-primary);
}

.profile-tab-btn.active {
  color: var(--primary);
  font-weight: 600;
  border-bottom-color: var(--primary);
}

/* ── Split Workflow Layout (Section 29 & 30 for Manual Buy/Sell) ── */
.workflow-split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.9fr);
  gap: 24px;
  align-items: start;
}

@media (max-width: 992px) {
  .workflow-split-layout {
    grid-template-columns: 1fr;
  }
}

.order-calc-panel {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px;
  position: sticky;
  top: calc(var(--header-height) + 20px);
}

.calc-panel-header {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.calc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 13px;
}

.calc-row-label {
  color: var(--text-secondary);
}

.calc-row-val {
  font-weight: 550;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.calc-row.total {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 6px;
  font-size: 15px;
}

.calc-row.total .calc-row-val {
  font-size: 17px;
  font-weight: 700;
  color: var(--primary);
}

.calc-balance-box {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 14px 0;
}

.alert-shortfall {
  background-color: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--danger);
  font-size: 12.5px;
  margin: 12px 0;
  line-height: 1.4;
}

/* ── Activity Timeline (Section 39) ── */
.activity-timeline {
  display: flex;
  flex-direction: column;
}

.timeline-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-subtle);
}

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

.timeline-time {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  width: 52px;
  flex-shrink: 0;
}

.timeline-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.timeline-desc {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.35;
}

.timeline-meta {
  font-size: 11.5px;
  color: var(--text-muted);
}

/* ── Modals & Drawers (Section 53 & 54) ── */
.modal-backdrop,
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  opacity: 0;
  transition: opacity var(--transition-fast);
  padding: 16px;
}

.modal-backdrop.open,
.drawer-backdrop.open {
  opacity: 1;
}

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

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 15px;
  font-weight: 650;
  color: var(--text-primary);
}

.modal-close {
  color: var(--text-muted);
  padding: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

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

.modal-body {
  padding: 18px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  background-color: var(--bg-subtle);
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  background-color: var(--surface-elevated);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-drawer);
  width: 480px;
  max-width: 100vw;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition-normal);
  z-index: var(--z-drawer);
}

.drawer-backdrop.open .drawer {
  transform: translateX(0);
}

.drawer-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-title {
  font-size: 15px;
  font-weight: 650;
  color: var(--text-primary);
}

.drawer-body {
  padding: 18px;
  overflow-y: auto;
  flex: 1;
}

.drawer-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background-color: var(--bg-subtle);
}

/* ── Toast Notifications ── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: var(--z-toast);
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-dropdown);
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  min-width: 260px;
  transform: translateY(10px);
  opacity: 0;
  transition: all var(--transition-fast);
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pagination-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  background-color: var(--surface);
  border-radius: 4px;
  cursor: pointer;
}

.pagination-btn:hover {
  background-color: var(--surface-muted);
  color: var(--text-primary);
}

.pagination-btn.active {
  background-color: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  font-weight: 600;
}

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