/* Common utility classes */
.flex {
  display: flex;
}

.flex-center {
  display: flex;
  align-items: center;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.flex-column {
  display: flex;
  flex-direction: column;
}

.gap-10 {
  gap: 10px;
}

.gap-20 {
  gap: 20px;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: calc(var(--space-5) * -1) calc(var(--space-5) * -1) var(--space-5);
  padding: var(--space-3) var(--space-5);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.header h1,
.page-title {
  margin: 0;
  font-size: var(--text-xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

/* Desktop header: logo left, page title centered, account data right */
.header-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  column-gap: 16px;
  width: 100%;
  min-width: 0;
}

.header-start {
  justify-self: start;
  min-width: 0;
}

.header-end {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo-container {
  width: auto;
  margin: 0;
}

.header-logo-link {
  display: inline-flex;
  align-items: center;
  line-height: 0;
  text-decoration: none;
  color: inherit;
}

.pulse-logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  line-height: 1;
  color: var(--text-primary);
}

.pulse-logo__word {
  font-family: var(--font-sans);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.03em;
  white-space: nowrap;
}

.pulse-logo__word--accent {
  color: var(--accent-color);
}

.pulse-logo__mark {
  width: 36px;
  height: 32px;
  flex: 0 0 auto;
  display: block;
  overflow: hidden;
}

.header-logo {
  height: 32px;
}

.page-title {
  grid-column: 2;
  margin: 0;
  text-align: center;
  white-space: nowrap;
}

/* User info icon and dropdown */
.user-info-container {
  width: 50px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.user-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--accent-color);
  color: var(--text-on-inverted);
  font-weight: 600;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.15s ease;
}

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

.user-icon:active {
  transform: scale(0.98);
}

/* Common dropdown styles */
.dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 12px 15px;
  z-index: var(--z-dropdown);
}

.dropdown::before,
.dropdown::after {
  content: "";
  position: absolute;
}

.dropdown::before {
  top: -6px;
  right: 15px;
  width: 12px;
  height: 12px;
  background: var(--bg-secondary);
  transform: rotate(45deg);
  border-left: 1px solid var(--border-color);
  border-top: 1px solid var(--border-color);
}

.dropdown::after {
  top: -15px;
  left: 0;
  width: 100%;
  height: 15px;
}

/* User info specific styles */
.user-info.dropdown {
  min-width: 220px;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  font-size: 0.9rem;
}

.user-info-container:hover .user-info,
.user-info-container.is-coach-open .user-info {
  display: flex;
}

.user-info-container.is-coach-open {
  z-index: calc(var(--z-dropdown) + 5);
}

.totp-recovery-coach {
  position: absolute;
  top: calc(100% + 12px);
  right: calc(100% + 14px);
  width: 260px;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: calc(var(--z-dropdown) + 6);
  color: var(--text-primary);
}

.totp-recovery-coach::after {
  content: '';
  position: absolute;
  top: 36px;
  right: -8px;
  width: 14px;
  height: 14px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  border-top: 1px solid var(--border-color);
  transform: rotate(45deg);
}

.totp-recovery-coach p {
  margin: 0 0 12px;
  font-size: 0.9rem;
  line-height: 1.4;
}

.totp-recovery-coach .button-primary {
  width: 100%;
}

.reset-2fa-btn.is-coach-target {
  box-shadow: 0 0 0 2px var(--focus-ring);
  animation: totp-coach-pulse 1.4s ease-in-out infinite;
}

@keyframes totp-coach-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 2px var(--focus-ring);
  }
  50% {
    box-shadow: 0 0 0 4px var(--focus-ring);
  }
}

.user-info div {
  font-size: 0.9rem;
  white-space: nowrap;
  padding: 3px 0;
}

.user-info div + div {
  border-top: 1px solid var(--border-color-light);
}

/* Common control styles */
.control-group {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-color);
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Button styles live in components.css (.button-primary / secondary / danger) */

.danger-button {
  background-color: transparent;
  color: var(--danger-color);
  border: 1px solid var(--danger-color);
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s ease;
  width: 100%;
}

.danger-button:hover {
  background-color: var(--danger-color);
  color: var(--text-on-inverted);
}

.logout-form {
  margin: 0;
}

.logout-btn {
  background-color: transparent;
  color: var(--danger-color);
  border: 1px solid var(--danger-color);
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s ease;
  width: 100%;
}

.logout-btn:hover {
  background-color: var(--danger-color);
  color: var(--text-on-inverted);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Filters */
.filters {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 10px;
}

.filters form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  flex-direction: row;
}

.filters input[type="text"] {
  width: 200px;
}

/* Login page */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  background-color: var(--bg-primary);
  background-image: url("../img/login-bg.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

[data-theme="dark"] body.login-page {
  background-image: url("../img/login-bg-dark.jpg");
}

.login-page .theme-toggle-container {
  margin-top: 25px;
  justify-content: center;
}

.login-brand {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  margin: 0 0 var(--space-5);
}

.login-logo {
  height: 34px;
}

.login-container {
  background: var(--bg-secondary);
  padding: var(--space-8);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  width: 100%;
  max-width: 420px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.login-form .form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.login-form .remember-me {
  display: flex;
  align-items: center;
  margin: 15px 0;
}

/* Keep closed TOTP dialogs out of document flow until showModal() */
.login-page dialog.dialog:not([open]) {
  display: none;
}

#totpSetupPanel,
#totpRecoveryPanel {
  width: 100%;
}

#totpSetupPanel.is-hidden,
#totpRecoveryPanel.is-hidden,
.is-hidden {
  display: none !important;
}

.totp-qr {
  display: flex;
  justify-content: center;
  margin: 0 auto 16px;
  padding: 12px;
  width: fit-content;
  background: #fff;
  border-radius: var(--radius-md);
}

.totp-manual-secret {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.04em;
  word-break: break-all;
  text-align: center;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
}

.totp-otp {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 4px;
}

.totp-otp__digit {
  width: 44px;
  height: 48px;
  box-sizing: border-box;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 600;
  text-align: center;
  line-height: 48px;
  caret-color: var(--accent-color);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.totp-otp__digit:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.totp-otp__sep {
  flex: 0 0 auto;
  color: var(--text-secondary);
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1;
  user-select: none;
}

.dialog .totp-otp__digit {
  background: var(--bg-primary);
}

.totp-verify-switch {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}

.totp-verify-switch__btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-color);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.totp-verify-switch__btn:hover {
  color: var(--accent-hover, var(--accent-color));
}

.totp-verify-switch__btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.totp-otp--recovery {
  gap: 6px;
}

.totp-otp--recovery .totp-otp__digit {
  width: 36px;
  height: 42px;
  font-size: 1.05rem;
  line-height: 42px;
  text-transform: uppercase;
}

.totp-recovery-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  list-style: none;
  margin: 0 0 16px;
  padding: 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 13px;
}

.totp-recovery-list li {
  padding: 8px 6px;
  text-align: center;
  background: var(--bg-secondary);
  border-radius: 4px;
}

.totp-recovery-tools {
  margin-bottom: 8px;
  justify-content: flex-start;
}

/* Dashboard Layout */
.dashboard-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 30px;
  margin-bottom: 40px;
}

@media (max-width: 1024px) {
  .header {
    min-width: 0;
  }

  .header-layout {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "logo title end";
    align-items: center;
    column-gap: 10px;
    width: 100%;
  }

  .header-start {
    grid-area: logo;
    justify-self: start;
    min-width: 0;
  }

  .page-title {
    grid-area: title;
    grid-column: auto;
    margin: 0;
    text-align: left;
    font-size: 1.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-end {
    grid-area: end;
    display: flex;
    justify-self: end;
    gap: 10px;
  }

  .header-logo {
    height: 32px;
  }

  .gmt-clock-simple,
  .header-dfs-balance {
    font-size: 12px;
  }

  .user-info {
    right: 0;
    text-align: left;
  }
}

/* Responsive styles */
@media (max-width: 768px) {
  body {
    padding: 12px 16px;
    overflow-x: auto;
  }
  .content-wrapper {
    padding: 0;
    margin: 0;
  }
  .header {
    margin: -12px -16px 12px -16px;
    padding: 10px 16px;
  }
  .header-layout {
    grid-template-areas:
      "logo title user"
      "meta meta meta";
    row-gap: 8px;
  }
  .header-end {
    display: contents;
  }
  .header-layout .header-clock-dfs {
    grid-area: meta;
    justify-content: flex-start;
    justify-self: stretch;
    gap: 8px 12px;
  }
  .user-info-container {
    grid-area: user;
    justify-self: end;
    align-self: center;
  }
  .totp-recovery-coach {
    top: calc(100% + 140px);
    right: 0;
    width: min(260px, calc(100vw - 32px));
  }
  .totp-recovery-coach::after {
    top: -7px;
    right: 18px;
    border-right: 0;
    border-bottom: 0;
    border-left: 1px solid var(--border-color);
    border-top: 1px solid var(--border-color);
  }
  .page-title {
    font-size: 1.05rem;
  }
  .filters {
    width: 100%;
  }
  .filters form {
    flex-wrap: wrap;
  }
  .filters input[type="text"] {
    width: 100%;
    flex: 1 1 100%;
  }
  .filters select {
    flex: 1 1 calc(50% - 5px);
  }
  .header-controls {
    width: 100%;
    justify-content: space-between;
  }
  .table-container {
    margin: 0;
    border-radius: 4px;
  }
  table th:nth-child(5),
  table td:nth-child(5),
  table th:nth-child(6),
  table td:nth-child(6),
  table th:nth-child(7),
  table td:nth-child(7) {
    display: none;
  }
  .pagination-buttons {
    gap: 6px;
  }
  .pagination-buttons .btn {
    min-width: 36px;
  }
  .pagination-buttons
    .btn:not(.active):not(:first-child):not(:last-child):not(
      .active + .btn
    ):not(.btn + .active) {
    display: none;
  }
  .totp-otp--recovery .totp-otp__digit {
    width: 32px;
    height: 38px;
    font-size: 0.95rem;
    line-height: 38px;
  }
  .login-container {
    margin: 20px;
    padding: 20px;
  }
}

@media (max-width: 480px) {
  body {
    padding: 10px 12px;
  }
  .header {
    margin: -10px -12px 10px -12px;
    padding: 8px 12px;
  }
  .page-title {
    font-size: 1rem;
  }
  .header-logo {
    height: 28px;
  }
  .pagination-buttons {
    gap: 4px;
  }
  .pagination-buttons .btn {
    min-width: 32px;
    height: 32px;
    padding: 0 6px;
    font-size: 12px;
  }
  .pagination-buttons .btn:not(.active):not(:first-child):not(:last-child) {
    display: none;
  }
  .pagination-buttons .btn.active {
    display: flex;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .filters {
    width: 100%;
  }
  .header-controls {
    width: auto;
  }
  .pagination-buttons {
    gap: 6px;
  }
}

.user-info .user-controls.control-group > * {
  width: 100%;
  box-sizing: border-box;
}

.user-info form,
.user-info .logout-form {
  margin: 0;
  display: block;
  width: 100%;
}

.user-info .logout-btn,
.user-info .reset-2fa-btn {
  display: flex;
  width: 100%;
  margin: 0;
  box-sizing: border-box;
}

.user-info .theme-toggle-wrapper,
.user-info .theme-toggle-container {
  width: 100%;
  justify-content: space-between;
}

/* Simple GMT Clock Styles */
.header-clock-dfs {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px 14px;
  min-width: 0;
}

.gmt-clock-simple {
  font-family: var(--font-mono);
  font-size: var(--text-md);
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
}

.header-dfs-balance {
  font-family: var(--font-mono);
  font-size: var(--text-md);
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.header-dfs-balance--ok {
  color: var(--success-color);
}

.header-dfs-balance--warn {
  color: var(--warning-color);
}

.header-dfs-balance--low {
  color: var(--danger-color);
}

.header-dfs-balance--error {
  color: var(--text-secondary);
  font-weight: normal;
}

/*
 * Toolbar + filters islands row (JS: toolbar-filters-layout.js).
 * Wrapper is layout-only — no shared chrome. Children keep their own island styles.
 */
.toolbar-filters-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-3, 12px);
  width: 100%;
  box-sizing: border-box;
  margin-bottom: var(--space-4, 16px);
}

.toolbar-filters-row > .stats-actions-block,
.toolbar-filters-row > .filters,
.toolbar-filters-row > .ml-row-1 {
  margin-bottom: 0;
}

.toolbar-filters-row.is-single-row {
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: stretch;
}

.toolbar-filters-row.is-single-row > .stats-actions-block {
  flex: 0 1 auto;
  min-width: 0;
}

.toolbar-filters-row.is-single-row > .filters,
.toolbar-filters-row.is-single-row > .ml-row-1 {
  flex: 1 1 auto;
  min-width: 0;
}

.toolbar-filters-row.is-stacked {
  flex-direction: column;
}
