/**
 * Nasc Financial Literacy PWA — Base Styles
 * Mobile-first, accessibility-focused base styles
 */

/* Reset */
*, *::before, *::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

/* Base HTML */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  color: var(--text-primary);
  background-color: var(--bg-primary);
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height for mobile */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Focus styles for accessibility */
:focus-visible {
  outline: 3px solid var(--plum);
  outline-offset: 2px;
}

/* Skip link for screen readers */
.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  background: var(--plum);
  color: var(--text-inverse);
  padding: var(--space-3) var(--space-4);
  z-index: 1000;
  text-decoration: none;
  font-weight: var(--font-weight-semibold);
}

.skip-link:focus {
  top: 0;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
}

h1 { font-size: var(--font-size-2xl); }
h2 { font-size: var(--font-size-xl); }
h3 { font-size: var(--font-size-lg); }

p {
  margin-block-end: var(--space-4);
}

/* Links */
a {
  color: var(--text-link);
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:hover {
  text-decoration-thickness: 2px;
}

/* Buttons - minimum touch target */
button,
[role="button"],
.btn {
  min-height: var(--touch-target-min);
  min-width: var(--touch-target-min);
  font-family: inherit;
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  border: none;
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-5);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  text-decoration: none;
  transition: background-color 0.2s ease, transform 0.1s ease;
}

button:active,
.btn:active {
  transform: scale(0.98);
}

/* Primary button */
.btn-primary {
  background-color: var(--plum);
  color: var(--text-inverse);
}

.btn-primary:hover {
  background-color: #3a0827;
}

/* Secondary button */
.btn-secondary {
  background-color: var(--grey-200);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background-color: var(--grey-300);
}

/* Income button (green for positive/money in) */
.btn-income {
  background-color: var(--success);
  color: var(--text-inverse);
}

.btn-income:hover {
  background-color: var(--success-dark);
}

/* Spend button (red for negative/money out) */
.btn-spend {
  background-color: var(--danger);
  color: var(--text-inverse);
}

.btn-spend:hover {
  background-color: #a81a20;
}

/* Dashboard Action Buttons */
.dashboard-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.dashboard-actions .btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-4);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
}

/* Form elements */
input, select, textarea {
  font-family: inherit;
  font-size: var(--font-size-base);
  padding: var(--space-3) var(--space-4);
  border: 2px solid var(--grey-300);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  min-height: var(--touch-target-min);
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--plum);
  outline: none;
}

label {
  display: block;
  font-weight: var(--font-weight-medium);
  margin-block-end: var(--space-2);
}

/* Utility classes */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.text-center { text-align: center; }
.text-start { text-align: start; }
.text-end { text-align: end; }

/* App layout */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.app-header {
  position: sticky;
  top: 0;
  min-height: calc(var(--header-height) + env(safe-area-inset-top));
  padding-top: calc(var(--space-2) + env(safe-area-inset-top));
  padding-bottom: var(--space-2);
  background: var(--nasc-red);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-inline-start: var(--space-2);
  padding-inline-end: var(--space-3);
  z-index: 100;
}

.app-header .logo-small {
  height: 36px;
  width: auto;
  /* No filter needed - official logo has correct colors */
}

.app-header .header-title {
  flex: 1;
  color: var(--text-inverse);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  text-align: center;
  line-height: var(--line-height-tight);
  padding-inline: var(--space-2);
}

.app-header .header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.app-header .btn-icon {
  background: transparent;
  border: none;
  color: var(--text-inverse);
  padding: var(--space-2);
  border-radius: var(--radius-full);
  min-width: var(--touch-target-min);
  min-height: var(--touch-target-min);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.app-header .btn-icon:hover {
  background: rgba(255, 255, 255, 0.15);
}

.app-header .btn-icon:active {
  background: rgba(255, 255, 255, 0.25);
}

.app-header .btn-icon svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
}

.app-main {
  flex: 1;
  padding: var(--space-4);
  padding-block-end: calc(var(--nav-height) + var(--space-4));
  max-width: var(--content-max-width);
  margin-inline: auto;
  width: 100%;
}

/* Screens that hide the red header (add/edit entry, Learning pages, About,
   Worksheets, Summary, Customise categories) must leave room for the phone's
   status bar themselves, or the back button sits under the clock on iPhone */
.app-header[hidden] ~ .app-main {
  padding-block-start: calc(var(--space-4) + env(safe-area-inset-top));
}

.app-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg-primary);
  border-block-start: 1px solid var(--grey-200);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding-inline: var(--space-4);
  z-index: 100;
}

.nav-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2);
  min-width: var(--touch-target-min);
  min-height: var(--touch-target-min);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
}

.nav-link[aria-current="page"] {
  color: var(--nasc-red);
}

.nav-link svg {
  width: 24px;
  height: 24px;
}

/* Cards */
.card {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-md);
}

/* Money display */
.money-display {
  font-size: var(--font-size-3xl);
  font-weight: var(--font-weight-bold);
  text-align: center;
}

.money-display--positive {
  color: var(--success);
}

.money-display--negative {
  color: var(--danger);
}

/* Loading state */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--grey-200);
  border-top-color: var(--nasc-red);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Hide elements by default, show with JS */
[data-screen] {
  display: none;
}

[data-screen].active {
  display: block;
}

/* Landing Page */
.landing-screen {
  padding-block-start: 0;
}

.landing-header {
  background: var(--nasc-red);
  padding: var(--space-5) var(--space-4);
  text-align: center;
  margin-inline: calc(-1 * var(--space-4));
  margin-block-start: calc(-1 * var(--space-4));
}

.landing-logo {
  height: 48px;
  width: auto;
  filter: brightness(0) invert(1);
}

.landing-content {
  padding-block-start: var(--space-5);
}

.landing-hero {
  text-align: center;
  margin-block-end: var(--space-5);
}

.hero-illustration {
  width: 95%;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius-lg);
}

.landing-title {
  text-align: center;
  color: var(--plum);
  margin-block-end: var(--space-3);
}

.landing-description {
  text-align: center;
  color: var(--text-secondary);
  font-size: var(--font-size-lg);
}

.landing-features {
  list-style: none;
  margin-block: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.landing-features li {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--font-size-lg);
}

.landing-features .feature-icon {
  font-size: var(--font-size-xl);
}

.landing-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-block: var(--space-5);
}

.landing-actions .btn {
  width: 100%;
}

.landing-link-account {
  margin-block: var(--space-4);
}

.landing-link-account .btn-outline {
  width: 100%;
  background: transparent;
  border: 2px solid var(--plum);
  color: var(--plum);
}

.landing-link-account .btn-outline:hover {
  background: var(--plum-light);
}

.disclaimer-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  background: var(--grey-100);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  margin-block-start: var(--space-5);
}

.disclaimer-card .disclaimer-icon {
  flex-shrink: 0;
  color: var(--text-secondary);
}

.disclaimer-card p {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin: 0;
}

/* Learning Page */
.learning-screen {
  padding-block-start: 0;
}

.learning-header {
  background: linear-gradient(135deg, var(--plum-light) 0%, var(--cream) 100%);
  padding: var(--space-5) var(--space-4);
  text-align: center;
  margin-inline: calc(-1 * var(--space-4));
  margin-block-start: calc(-1 * var(--space-4));
  margin-block-end: var(--space-5);
}

.learning-illustration {
  max-width: 100%;
  height: auto;
  max-height: 150px;
  object-fit: contain;
  border-radius: var(--radius-md);
  margin-block-end: var(--space-4);
}

.learning-header h1 {
  color: var(--plum);
  margin-block-end: var(--space-2);
}

.learning-header p {
  color: var(--text-secondary);
  margin: 0;
}

.learning-topics {
  margin-block-start: var(--space-5);
}

.learning-topics h2 {
  margin-block-end: var(--space-4);
}

.topic-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.topic-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  background: var(--bg-primary);
  border: 1px solid var(--grey-200);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  text-align: start;
  width: 100%;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.topic-card:hover {
  border-color: var(--plum);
  box-shadow: var(--shadow-md);
}

.topic-icon {
  font-size: var(--font-size-2xl);
  flex-shrink: 0;
}

.topic-content {
  flex: 1;
}

.topic-content strong {
  display: block;
  margin-block-end: var(--space-1);
}

.topic-content p {
  margin: 0;
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

/* ============================================
   Category Manager Screen
   ============================================ */

.category-manager-screen {
  padding: 0 var(--space-4) var(--space-6);
  padding-block-end: calc(var(--nav-height) + var(--space-6) + env(safe-area-inset-bottom, 0px));
}

/* Prevent title wrapping on narrow screens */
.category-manager-screen .screen-header h2 {
  font-size: var(--font-size-md);
}

.cm-type-tabs {
  display: flex;
  gap: var(--space-2);
  margin-block: var(--space-4);
  background: var(--grey-100);
  padding: var(--space-1);
  border-radius: var(--radius-md);
}

.cm-type-tab {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.cm-type-tab.active {
  background: var(--bg-primary);
  color: var(--plum);
  box-shadow: var(--shadow-sm);
}

.cm-section {
  margin-block-end: var(--space-5);
}

.cm-section-title {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-primary);
  margin-block-end: var(--space-1);
}

.cm-section-desc {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  margin-block-end: var(--space-3);
}

/* Instruction line */
.cm-instruction {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  text-align: center;
  margin-block: var(--space-2) var(--space-3);
}

/* Saved notice */
.cm-saved-notice {
  position: fixed;
  inset-block-end: calc(var(--nav-height) + var(--space-4));
  inset-inline-start: 50%;
  transform: translateX(-50%);
  background: var(--plum);
  color: var(--text-inverse);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 50;
}

.cm-saved-notice.visible {
  opacity: 1;
}

/* Category grid (3 across like entry form) */
.cm-category-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  min-height: 60px;
  background: var(--grey-50);
  border-radius: var(--radius-md);
  padding: var(--space-2);
}

/* Category tiles in Category Manager (same .category-btn as entry form) */
.category-manager-screen .category-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-height: 72px;
  padding: var(--space-2);
  background: var(--bg-primary);
  border: 2px solid var(--grey-200);
  border-radius: var(--radius-md);
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.category-manager-screen .category-btn:active {
  cursor: grabbing;
}

.category-manager-screen .category-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: var(--plum);
}

.category-manager-screen .category-icon svg {
  width: 24px;
  height: 24px;
}

.category-manager-screen .category-label {
  font-size: var(--font-size-xs);
  color: var(--text-primary);
  text-align: center;
  word-break: break-word;
}

/* Custom category indicator */
.category-manager-screen .cm-custom-tile {
  position: relative;
}

.category-manager-screen .cm-custom-tile::after {
  content: '';
  position: absolute;
  inset-block-start: 4px;
  inset-inline-end: 4px;
  width: 8px;
  height: 8px;
  background: var(--plum);
  border-radius: 50%;
}

/* Empty section hint */
.cm-empty-hint {
  grid-column: 1 / -1;
  text-align: center;
  padding: var(--space-4);
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  font-style: italic;
}

/* Sortable states */
.cm-sortable-ghost {
  opacity: 0.4;
}

.cm-sortable-chosen {
  border-color: var(--plum) !important;
  box-shadow: var(--shadow-md);
}

.cm-sortable-drag {
  opacity: 1 !important;
  transform: scale(1.05);
}

.cm-reset-container {
  text-align: center;
  margin-block-start: var(--space-4);
  padding-block-start: var(--space-4);
  border-top: 1px solid var(--grey-200);
}

/* Category Manager Dialog */
.cm-dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: var(--space-4);
}

.cm-dialog {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  max-width: 320px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}

.cm-dialog-title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  margin-block-end: var(--space-2);
}

.cm-dialog-message {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-block-end: var(--space-4);
}

.cm-dialog-actions {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
}

/* Add your own tile */
.cm-add-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-height: 72px;
  padding: var(--space-2);
  background: var(--plum-light);
  border: 2px dashed var(--plum);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.cm-add-tile:hover {
  background: var(--plum);
}

.cm-add-tile:hover .cm-add-icon,
.cm-add-tile:hover .cm-add-label {
  color: var(--text-inverse);
}

.cm-add-tile.cm-add-tile-disabled {
  cursor: not-allowed;
  border-color: var(--grey-300);
  background: var(--grey-100);
}

.cm-add-tile.cm-add-tile-disabled:hover {
  background: var(--grey-100);
}

.cm-add-tile.cm-add-tile-disabled:hover .cm-add-icon,
.cm-add-tile.cm-add-tile-disabled:hover .cm-add-label {
  color: var(--text-secondary);
}

.cm-add-icon {
  color: var(--plum);
  display: flex;
  align-items: center;
}

.cm-add-icon svg {
  width: 24px;
  height: 24px;
}

.cm-add-label {
  font-size: var(--font-size-xs);
  color: var(--plum);
  font-weight: 500;
  text-align: center;
}

.cm-add-tile-disabled .cm-add-icon,
.cm-add-tile-disabled .cm-add-label {
  color: var(--text-secondary);
}

/* Custom category dialog */
.cm-custom-dialog {
  max-width: 360px;
}

.cm-custom-form {
  margin-block-end: var(--space-4);
}

.cm-form-group {
  margin-block-end: var(--space-4);
}

.cm-form-group label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-primary);
  margin-block-end: var(--space-2);
}

.cm-text-input {
  width: 100%;
  padding: var(--space-3);
  border: 1px solid var(--grey-300);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-base);
  font-family: inherit;
  background: var(--bg-primary);
  color: var(--text-primary);
}

.cm-text-input:focus {
  outline: none;
  border-color: var(--plum);
  box-shadow: 0 0 0 2px var(--plum-light);
}

.cm-char-count {
  display: block;
  text-align: end;
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  margin-block-start: var(--space-1);
}

/* Type selector for new categories */
.cm-type-selector {
  display: flex;
  gap: var(--space-2);
  background: var(--grey-100);
  padding: var(--space-1);
  border-radius: var(--radius-md);
}

.cm-type-option {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.cm-type-option.active {
  background: var(--bg-primary);
  color: var(--plum);
  box-shadow: var(--shadow-sm);
}

/* Icon picker grid */
.cm-icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: var(--space-2);
  max-height: 200px;
  overflow-y: auto;
  padding: var(--space-2);
  background: var(--grey-50);
  border-radius: var(--radius-md);
}

.cm-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.cm-icon-btn:hover {
  border-color: var(--grey-300);
  color: var(--text-primary);
}

.cm-icon-btn.selected,
.cm-icon-btn[aria-pressed="true"] {
  border-color: var(--plum);
  color: var(--plum);
  background: var(--plum-light);
}

.cm-icon-btn svg {
  width: 20px;
  height: 20px;
}

/* Dialog actions with delete button */
.cm-custom-dialog .cm-dialog-actions {
  flex-wrap: wrap;
  gap: var(--space-2);
}

.cm-dialog-actions-right {
  display: flex;
  gap: var(--space-3);
  margin-inline-start: auto;
}

.btn-danger {
  background: var(--error);
  color: var(--text-inverse);
}

.btn-danger:hover {
  background: #c53030;
}

/* =====================================================
   Keep my budget safe (ks-): Settings section and dialogs
   docs/keep-safe.md 4.10. Logical properties throughout, so it mirrors
   in right-to-left languages.
   ===================================================== */

.ks-section.ks-busy {
  opacity: 0.6;
  pointer-events: none;
}

.ks-explain {
  font-size: var(--font-size-base);
  color: var(--text-primary);
  line-height: var(--line-height-normal);
  margin-block-end: var(--space-3);
}

.ks-paused {
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  background: var(--warning-light);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-block: var(--space-2);
}

/* Something attached: the value, partly hidden, and its buttons */
.ks-detail {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--bg-primary);
  border: 1px solid var(--grey-200);
  border-radius: var(--radius-md);
  margin-block-end: var(--space-2);
}

.ks-detail-text {
  min-width: 0;
  flex: 1 1 140px;
}

.ks-detail-value {
  font-size: var(--font-size-base);
  color: var(--text-secondary);
  margin: 0;
  overflow-wrap: anywhere;
}

.ks-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.ks-detail-btn {
  font-size: var(--font-size-base);
  padding: var(--space-2) var(--space-4);
  min-height: var(--touch-target-min);
}

.ks-detail-btn.ks-remove {
  background-color: transparent;
  border: 1px solid var(--grey-300);
  color: var(--danger);
}

/* Numbers, addresses and codes always read left to right, in any language */
.ks-ltr {
  direction: ltr;
  unicode-bidi: isolate;
}

[dir="rtl"] .ks-detail-value.ks-ltr {
  text-align: end;
}

/* Dialogs: start near the top so the keyboard does not cover the buttons */
.ks-dialog-overlay {
  align-items: flex-start;
  overflow-y: auto;
  padding-block-start: max(var(--space-6), env(safe-area-inset-top));
}

.ks-dialog {
  max-width: 360px;
}

.ks-dialog-message {
  font-size: var(--font-size-base);
  color: var(--text-primary);
  line-height: var(--line-height-normal);
}

.ks-field {
  margin-block-end: var(--space-4);
}

.ks-field label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-primary);
  margin-block-end: var(--space-2);
}

.ks-input,
.ks-select {
  width: 100%;
  min-height: var(--touch-target-min);
  font-size: var(--font-size-lg);
}

.ks-select {
  padding: var(--space-3);
  border: 1px solid var(--grey-300);
  border-radius: var(--radius-sm);
  font-family: inherit;
  background: var(--bg-primary);
  color: var(--text-primary);
}

.ks-select:focus {
  outline: none;
  border-color: var(--plum);
  box-shadow: 0 0 0 2px var(--plum-light);
}

[dir="rtl"] .ks-input.ks-ltr {
  text-align: right;
}

.ks-code-input,
[dir="rtl"] .ks-code-input.ks-ltr {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-semibold);
  letter-spacing: 0.3em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.ks-error,
.ks-note {
  font-size: var(--font-size-base);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-block-end: var(--space-4);
}

.ks-error {
  color: var(--danger);
  background: var(--danger-light);
}

.ks-note {
  color: var(--text-primary);
  background: var(--success-light);
}

/* One clear main button, full width, with the quieter choices under it */
.ks-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.ks-actions .btn {
  width: 100%;
}

.ks-actions .btn:disabled,
.ks-detail-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.ks-cancel {
  min-height: var(--touch-target-min);
  align-self: center;
}

/* First screen: the quieter second button under "Continue" */
.ks-quiet-btn {
  width: 100%;
  margin-block-start: var(--space-3);
  background-color: transparent;
  color: var(--plum);
  border: 1px solid var(--plum);
  font-size: var(--font-size-base);
}

.ks-quiet-btn:hover {
  background-color: var(--plum-light);
}

/* The "please wait" message has no buttons */
.ks-dialog[aria-busy="true"] .ks-actions:empty {
  display: none;
}

/* RTL adjustments - using logical properties throughout */
[dir="rtl"] .app-header {
  flex-direction: row-reverse;
}

/* The hidden attribute always wins. Several buttons and rows set display: flex,
   which used to override it (the Delete button on a new entry, for one). */
[hidden] {
  display: none !important;
}
