:root {
  --bg: #ffffff;
  --bg-alt: #f8f9fa;
  --surface: #ffffff;
  --surface-hover: #f1f3f4;
  --border: #dadce0;
  --text: #202124;
  --text-muted: #5f6368;
  --accent: #1a73e8;
  --accent-hover: #1765cc;
  --accent-tonal: #e8f0fe;
  --success: #188038;
  --success-tonal: #e6f4ea;
  --error: #d93025;
  --error-tonal: #fce8e6;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-pill: 24px;
  --shadow-1: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
  --shadow-2: 0 1px 3px rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15);

  --track-row-bg: rgba(26, 115, 232, 0.16);
  --track-row-border: #1a73e8;
  --track-col-bg: rgba(230, 124, 0, 0.16);
  --track-col-border: #e67c00;
  --track-value-bg: rgba(24, 128, 56, 0.16);
  --track-value-border: #188038;
}

[data-theme="dark"] {
  --bg: #202124;
  --bg-alt: #17181a;
  --surface: #292a2d;
  --surface-hover: #35363a;
  --border: #3c4043;
  --text: #e8eaed;
  --text-muted: #9aa0a6;
  --accent: #8ab4f8;
  --accent-hover: #aecbfa;
  --accent-tonal: #28324a;
  --success: #81c995;
  --success-tonal: #1e3324;
  --error: #f28b82;
  --error-tonal: #3c2020;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5), 0 1px 3px 1px rgba(0, 0, 0, 0.3);
  --shadow-2: 0 1px 3px rgba(0, 0, 0, 0.5), 0 4px 8px 3px rgba(0, 0, 0, 0.3);

  --track-row-bg: rgba(138, 180, 248, 0.22);
  --track-row-border: #8ab4f8;
  --track-col-bg: rgba(253, 214, 99, 0.22);
  --track-col-border: #fdd663;
  --track-value-bg: rgba(129, 201, 149, 0.22);
  --track-value-border: #81c995;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg-alt);
  color: var(--text);
  font-family: "Google Sans", Roboto, -apple-system, "Segoe UI", Arial, sans-serif;
  transition: background 0.2s ease, color 0.2s ease;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px 32px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.topbar-toggles {
  display: flex;
  gap: 8px;
}

.app-nav {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 3px;
}

.app-nav-link {
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 7px 18px;
  border-radius: var(--radius-pill);
  transition: background 0.15s ease, color 0.15s ease;
}

.app-nav-link:hover {
  background: var(--surface-hover);
}

.app-nav-link.active {
  background: var(--accent-tonal);
  color: var(--accent);
}

.icon-dropdown {
  position: relative;
}

.icon-dropdown-trigger {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 0;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.icon-dropdown-trigger:hover {
  background: var(--surface-hover);
}

.icon-dropdown.open .icon-dropdown-trigger {
  background: var(--accent-tonal);
  border-color: var(--accent);
}

.icon-dropdown-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  font-size: 16px;
  line-height: 1;
}

.icon-dropdown-icon.theme-icon-dark {
  display: none;
}

[data-theme="dark"] .icon-dropdown-icon.theme-icon-light {
  display: none;
}

[data-theme="dark"] .icon-dropdown-icon.theme-icon-dark {
  display: flex;
}

.icon-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 110px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  padding: 4px;
  z-index: 20;
  flex-direction: column;
  gap: 2px;
}

[dir="rtl"] .icon-dropdown-menu {
  right: auto;
  left: 0;
}

.icon-dropdown.open .icon-dropdown-menu {
  display: flex;
}

.icon-dropdown-menu button {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease;
}

[dir="rtl"] .icon-dropdown-menu button {
  text-align: right;
}

.icon-dropdown-menu button:hover {
  background: var(--surface-hover);
}

.icon-dropdown-menu button.active {
  background: var(--accent-tonal);
  color: var(--accent);
}

header {
  margin-bottom: 24px;
}

header h1 {
  font-size: 26px;
  font-weight: 500;
  margin: 0 0 4px;
  letter-spacing: -0.2px;
}

.subtitle {
  color: var(--text-muted);
  margin: 0 0 16px;
  font-size: 14px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.app-header-text h1,
.app-header-text .subtitle {
  margin-bottom: 0;
}

.app-header #run-btn {
  flex-shrink: 0;
}

.config-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-1);
}

.config-bar label {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.config-bar input[type="text"] {
  flex: 1;
  min-width: 220px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
}

.config-bar button {
  background: var(--accent);
  border: none;
  color: white;
  padding: 8px 18px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.config-bar button:hover {
  background: var(--accent-hover);
}

.status-text {
  font-size: 12px;
  color: var(--success);
}

.dropzone-single {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 20px;
}

.dropzone-single:hover {
  background: var(--surface-hover);
}

.dropzone-single.dragover {
  border-color: var(--accent);
  background: var(--accent-tonal);
}

.dropzone-single.filled {
  border-color: var(--success);
  border-style: solid;
}

.dropzone-icon {
  font-size: 28px;
  margin-bottom: 8px;
  opacity: 0.8;
}

.dropzone-label {
  font-weight: 500;
  margin-bottom: 6px;
}

.file-assignment {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.downloads-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}

.downloads-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  box-shadow: var(--shadow-1);
}

.downloads-picker-item {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  text-align: left;
  transition: background 0.15s ease;
}

[dir="rtl"] .downloads-picker-item {
  text-align: right;
}

.downloads-picker-item:hover {
  background: var(--surface-hover);
}

.downloads-picker-item.selected {
  background: var(--accent-tonal);
  border-color: var(--accent);
  color: var(--accent);
}

.file-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  min-width: 160px;
  box-shadow: var(--shadow-1);
}

.file-slot-role {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.file-slot-name {
  font-size: 13px;
  font-weight: 500;
  word-break: break-all;
  text-align: center;
}

#swap-files-btn {
  flex-shrink: 0;
}

.actions {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}

.actions:empty {
  display: none;
}

#run-btn {
  background: var(--accent);
  border: none;
  color: white;
  padding: 10px 26px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.1px;
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}

#run-btn:disabled {
  background: var(--surface-hover);
  color: var(--text-muted);
  cursor: not-allowed;
  box-shadow: none;
}

#run-btn:not(:disabled):hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-2);
  transform: translateY(-1px);
}

#run-btn:not(:disabled):active {
  transform: translateY(0);
  box-shadow: var(--shadow-1);
}

.download-link {
  color: var(--accent);
  font-size: 14px;
  text-decoration: none;
  font-weight: 500;
}

.download-link:hover {
  text-decoration: underline;
}

.progress-section {
  margin-bottom: 24px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.progress-bar-track {
  height: 6px;
  border-radius: 4px;
  background: var(--surface-hover);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.15s ease;
}

.progress-bar-fill.indeterminate {
  width: 40%;
  animation: progress-slide 1.1s ease-in-out infinite;
}

@keyframes progress-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}

.message {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 24px;
}

.message.error {
  background: var(--error-tonal);
  color: var(--error);
}

.message.info {
  background: var(--accent-tonal);
  color: var(--accent);
}

.results h2 {
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 12px;
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.results-header h2 {
  margin-bottom: 0;
}

.config-io-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.config-io-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s ease;
}

.config-io-btn:hover {
  background: var(--surface-hover);
}

.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-family: "Google Sans Mono", "Consolas", "Courier New", monospace;
}

th, td {
  padding: 8px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  white-space: nowrap;
}

th:last-child, td:last-child {
  border-right: none;
}

th {
  background: var(--bg-alt);
  color: var(--text-muted);
  font-weight: 500;
  font-family: "Google Sans", Roboto, sans-serif;
  position: sticky;
  top: 0;
}

tbody tr:nth-child(even) td {
  background: var(--bg-alt);
}

tr:hover td {
  background: var(--accent-tonal) !important;
}

.change-cell {
  cursor: help;
}

.value-old {
  color: var(--text-muted);
}

.value-arrow {
  color: var(--text-muted);
  margin: 0 6px;
}

.value-new {
  color: var(--text);
  font-weight: 500;
}

.delta-positive {
  color: var(--success);
  font-weight: 600;
  cursor: help;
}

.delta-negative {
  color: var(--error);
  font-weight: 600;
  cursor: help;
}

.delta-neutral {
  color: var(--text-muted);
  cursor: help;
}

.app-footer {
  margin-top: auto;
  padding-top: 16px;
  padding-bottom: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

/* Tables and the sheet-picker grid always stay left-to-right, even in
   Hebrew, since spreadsheet cell references (A1, B2, ...) read LTR. */
.table-wrapper,
.table-wrapper table,
#sheet-grid {
  direction: ltr;
}

[dir="rtl"] .table-wrapper th,
[dir="rtl"] .table-wrapper td {
  text-align: left;
}
