/* ============================================
   CERATIZIT Carbide Turning Tool Assistant
   Brand: CERATIZIT Brand Cheat Sheet
   Mobile-first responsive design
   ============================================ */

/* --- CSS Variables (CERATIZIT Brand) --- */
:root {
  --red: #d62418;
  --dark-red: #A60A00;
  --grey: #4e4a49;
  --blue: #0061af;
  --grey-7: #F3F3F3;
  --grey-17: #DFDFDF;
  --grey-27: #CBCBCB;
  --grey-37: #B7B7B7;
  --grey-50: #898989;
  --white: #ffffff;
  --black: #000000;

  --font: Arial, Helvetica, sans-serif;
  --body-size: 16px;
  --data-size: 18px;
  --grade-size: 22px;

  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
  --transition: 0.2s ease;

  --touch-min: 44px;
  --max-width: 600px;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: var(--body-size);
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  font-size: var(--body-size);
  line-height: 1.5;
  color: var(--grey);
  background: var(--white);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* --- Typography --- */
h1 {
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--grey);
  line-height: 1.2;
}

h2 {
  font-size: 1.25rem;
  font-weight: bold;
  color: var(--grey);
  line-height: 1.3;
}

h3 {
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--grey);
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover, a:focus {
  text-decoration: underline;
}

/* --- Modal Overlay --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.modal-card h2 {
  margin: 1rem 0 0.5rem;
  color: var(--grey);
}

.modal-card h3 {
  margin-bottom: 0.75rem;
  color: var(--grey);
}

.modal-card p {
  margin-bottom: 1rem;
  color: var(--grey-50);
  font-size: 0.9rem;
}

.modal-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.logo-triangle {
  color: var(--red);
  font-size: 1.5rem;
  line-height: 1;
}

.logo-text {
  font-weight: bold;
  font-size: 1.2rem;
  color: var(--grey);
  letter-spacing: 0.05em;
}

/* --- Access Control --- */
.access-input-group {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.access-input-group input {
  flex: 1;
}

.request-access-link {
  font-size: 0.85rem;
  color: var(--blue);
}

/* --- Loading --- */
.loading-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  box-shadow: var(--shadow-lg);
  max-width: 300px;
  width: 100%;
}

.loading-inline {
  box-shadow: none;
  max-width: none;
  padding: 3rem 1rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--grey-17);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1rem;
}

.spinner-small {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: var(--white);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}

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

/* --- Header --- */
.app-header {
  padding: 0.75rem 1rem;
  border-bottom: 2px solid var(--red);
  background: var(--white);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  max-width: var(--max-width);
  margin: 0 auto;
}

.header-brand .logo-triangle {
  font-size: 1.2rem;
}

.header-brand .logo-text {
  font-size: 1rem;
}

/* --- Views --- */
.view {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.5rem 1rem 2rem;
}

/* --- Landing --- */
.landing-title {
  margin-bottom: 0.5rem;
}

.landing-subtitle {
  color: var(--grey-50);
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

/* --- Input Section --- */
.input-section {
  margin-bottom: 1.5rem;
}

.input-wrapper {
  margin-bottom: 0.5rem;
}

textarea,
.form-input {
  width: 100%;
  padding: 0.75rem;
  border: 1.5px solid var(--grey-27);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: var(--body-size);
  color: var(--grey);
  background: var(--white);
  resize: vertical;
  transition: border-color var(--transition);
}

textarea:focus,
.form-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(0, 97, 175, 0.15);
}

.input-footer {
  display: flex;
  justify-content: flex-end;
}

.char-counter {
  font-size: 0.8rem;
  color: var(--grey-50);
}

.char-counter.over-limit {
  color: var(--red);
  font-weight: bold;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font);
  font-size: var(--body-size);
  font-weight: bold;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: var(--touch-min);
  padding: 0.625rem 1.25rem;
  transition: background var(--transition), opacity var(--transition);
  -webkit-tap-highlight-color: transparent;
}

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

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

.btn-primary {
  background: var(--red);
  color: var(--white);
}

.btn-primary:hover:not(:disabled) {
  background: var(--dark-red);
}

.btn-secondary {
  background: var(--grey-7);
  color: var(--grey);
  border: 1.5px solid var(--grey-27);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--grey-17);
}

.btn-sm {
  min-height: 36px;
  font-size: 0.875rem;
  padding: 0.4rem 0.75rem;
}

.btn-submit {
  width: 100%;
  margin-top: 0.5rem;
}

.btn-copy {
  width: 100%;
}

.btn-link {
  background: none;
  border: none;
  color: var(--blue);
  font-family: var(--font);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.25rem 0;
  min-height: var(--touch-min);
  display: inline-flex;
  align-items: center;
}

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

.btn-back {
  background: none;
  border: none;
  color: var(--blue);
  font-family: var(--font);
  font-size: 0.95rem;
  cursor: pointer;
  padding: 0.25rem 0;
  min-height: var(--touch-min);
  display: inline-flex;
  align-items: center;
  margin-bottom: 0.75rem;
}

/* --- Mode Buttons --- */
.mode-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.btn-mode {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.875rem 1rem;
  background: var(--white);
  border: 1.5px solid var(--grey-27);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.95rem;
  color: var(--grey);
  cursor: pointer;
  min-height: var(--touch-min);
  text-align: left;
  transition: border-color var(--transition), background var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.btn-mode:hover {
  border-color: var(--blue);
  background: var(--grey-7);
}

.btn-mode:active {
  background: var(--grey-17);
}

.mode-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
  width: 28px;
  text-align: center;
}

.btn-mode:first-child .mode-icon {
  color: var(--red);
}

.btn-mode:nth-child(2) .mode-icon {
  color: var(--blue);
}

.btn-mode:nth-child(3) .mode-icon {
  color: var(--grey);
}

.mode-label {
  font-weight: bold;
}

/* --- Form Elements --- */
.find-form {
  margin-bottom: 1.5rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: bold;
  color: var(--grey);
  margin-bottom: 0.25rem;
}

.form-select {
  width: 100%;
  padding: 0.75rem;
  border: 1.5px solid var(--grey-27);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: var(--body-size);
  color: var(--grey);
  background: var(--white);
  min-height: var(--touch-min);
  cursor: pointer;
  appearance: auto;
}

.form-select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(0, 97, 175, 0.15);
}

.form-input-sm {
  padding: 0.5rem;
  font-size: 0.9rem;
  min-height: 36px;
}

.form-select-sm {
  padding: 0.5rem;
  font-size: 0.9rem;
  min-height: 36px;
  width: auto;
}

/* --- Recent Queries --- */
.recent-section {
  margin-bottom: 1rem;
}

.recent-list {
  list-style: none;
  margin-top: 0.5rem;
}

.recent-list li {
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--grey-7);
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--grey);
  min-height: var(--touch-min);
  display: flex;
  align-items: center;
}

.recent-list li:hover {
  color: var(--blue);
}

.recent-list .recent-mode {
  font-size: 0.75rem;
  font-weight: bold;
  color: var(--grey-50);
  background: var(--grey-7);
  border-radius: 3px;
  padding: 0.15rem 0.4rem;
  margin-right: 0.5rem;
  flex-shrink: 0;
}

/* --- Results --- */
.results-container {
  margin-top: 1rem;
}

/* --- Tier 1: The Answer --- */
.tier {
  margin-bottom: 1.25rem;
}

.tier-1 {
  padding: 1.25rem;
  background: var(--grey-7);
  border-radius: var(--radius);
  border-left: 4px solid var(--red);
}

.tier-1-grade {
  font-size: var(--grade-size);
  font-weight: bold;
  color: var(--grey);
  line-height: 1.2;
}

.tier-1-article {
  font-size: var(--grade-size);
  color: var(--blue);
  font-weight: bold;
  margin-top: 0.25rem;
}

.tier-1-summary {
  font-size: 0.95rem;
  color: var(--grey-50);
  margin-top: 0.5rem;
}

/* --- Tier 2: The Parameters --- */
.tier-2 {
  padding: 1.25rem;
  background: var(--white);
  border: 1.5px solid var(--grey-17);
  border-radius: var(--radius);
}

.tier-heading {
  font-size: 1rem;
  margin-bottom: 0.75rem;
  color: var(--grey);
}

.param-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.625rem;
}

.param-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.375rem 0;
  border-bottom: 1px solid var(--grey-7);
}

.param-label {
  font-size: 0.85rem;
  color: var(--grey-50);
  flex-shrink: 0;
}

.param-value {
  font-size: var(--data-size);
  font-weight: bold;
  color: var(--grey);
  text-align: right;
}

.param-value .param-unit {
  font-size: 0.8rem;
  font-weight: normal;
  color: var(--grey-50);
}

.param-value .param-range {
  font-size: 0.85rem;
  font-weight: normal;
  color: var(--grey-50);
  display: block;
}

/* --- RPM Calculator --- */
.rpm-calc {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--grey-17);
}

.rpm-calc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.rpm-calc-row label {
  font-size: 0.85rem;
  color: var(--grey-50);
  flex-shrink: 0;
}

.rpm-input-group {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.rpm-input-group input {
  width: 80px;
}

.rpm-result {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: var(--grey-7);
  border-radius: var(--radius-sm);
  font-size: var(--data-size);
  font-weight: bold;
  color: var(--grey);
  text-align: center;
}

.rpm-warning {
  color: var(--red);
  font-size: 0.85rem;
  font-weight: normal;
  display: block;
  margin-top: 0.25rem;
}

.tier-2-note {
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--grey-50);
  font-style: italic;
}

.tier-2-note::first-letter {
  color: var(--red);
}

/* --- Tier 3: The Reasoning --- */
.tier-3 {
  border: 1.5px solid var(--grey-17);
  border-radius: var(--radius);
  overflow: hidden;
}

.tier-3-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.25rem;
  background: var(--grey-7);
  border: none;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: bold;
  color: var(--grey);
  cursor: pointer;
  min-height: var(--touch-min);
}

.tier-3-toggle:hover {
  background: var(--grey-17);
}

.toggle-arrow {
  transition: transform var(--transition);
  font-size: 0.8rem;
}

.toggle-arrow.open {
  transform: rotate(180deg);
}

.tier-3-content {
  padding: 1.25rem;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--grey);
}

.tier-3-content h4 {
  font-size: 0.9rem;
  font-weight: bold;
  color: var(--grey);
  margin: 1rem 0 0.25rem;
}

.tier-3-content h4:first-child {
  margin-top: 0;
}

.tier-3-content ul {
  padding-left: 1.25rem;
  margin: 0.25rem 0 0.5rem;
}

.tier-3-content li {
  margin-bottom: 0.25rem;
}

.tier-3-content li::marker {
  color: var(--red);
}

.reasoning-tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  margin-right: 0.25rem;
}

.tag-verified {
  background: #e8f5e9;
  color: #2e7d32;
}

.tag-inferred {
  background: #fff3e0;
  color: #ef6c00;
}

.tag-uncertain {
  background: #ffebee;
  color: var(--red);
}

/* Application range display */
.application-range {
  margin-top: 0.75rem;
  padding: 0.625rem;
  background: var(--grey-7);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.application-range strong {
  color: var(--grey);
}

/* Catalogue reference */
.catalogue-ref {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--grey-50);
  font-style: italic;
}

/* --- Confidence Warning --- */
.confidence-warning {
  padding: 1rem;
  background: #fff3e0;
  border: 1.5px solid #ffb74d;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
}

.confidence-warning p {
  font-size: 0.9rem;
  color: #e65100;
  margin: 0;
}

/* --- Feedback --- */
.feedback-section {
  text-align: center;
  margin-bottom: 1rem;
  padding: 1rem;
  background: var(--grey-7);
  border-radius: var(--radius);
}

.feedback-prompt {
  font-size: 0.9rem;
  color: var(--grey-50);
  margin-bottom: 0.75rem;
}

.feedback-buttons {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 0.5rem;
}

.btn-feedback {
  background: none;
  border: 2px solid var(--grey-27);
  border-radius: 50%;
  width: 52px;
  height: 52px;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--transition), background var(--transition);
}

.btn-feedback:hover {
  border-color: var(--blue);
  background: var(--grey-7);
}

.btn-feedback.selected {
  border-color: var(--blue);
  background: rgba(0, 97, 175, 0.1);
}

#feedback-text-section {
  margin-top: 0.75rem;
}

#feedback-text-section textarea {
  margin-bottom: 0.5rem;
}

/* --- Copy --- */
.copy-fallback {
  margin-top: 0.75rem;
}

.copy-fallback textarea {
  font-family: monospace;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--grey);
  background: var(--grey-7);
}

/* --- Recovery --- */
.recovery-link {
  text-align: center;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--grey-17);
}

.recovery-link a {
  font-size: 0.9rem;
}

/* --- Error --- */
.error-text {
  color: var(--red);
  font-size: 0.85rem;
}

.error-card {
  text-align: center;
  padding: 2rem 1rem;
}

.error-card p {
  font-size: 1rem;
  color: var(--grey);
  margin-bottom: 1.25rem;
}

.error-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* --- Ambiguity Modal --- */
.ambiguity-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.ambiguity-options .btn {
  text-align: left;
  justify-content: flex-start;
}

/* --- Material Picker --- */
.picker-groups {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.picker-groups .btn {
  text-align: left;
  font-size: 0.85rem;
  padding: 0.75rem;
}

.picker-iso-entry {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--grey-17);
  text-align: left;
}

.picker-iso-entry label {
  display: block;
  font-size: 0.85rem;
  color: var(--grey-50);
  margin-bottom: 0.25rem;
}

.picker-iso-entry input {
  margin-bottom: 0.5rem;
}

/* --- Article Results Table --- */
.article-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-top: 0.75rem;
}

.article-table th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: bold;
  color: var(--grey-50);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.5rem;
  border-bottom: 2px solid var(--grey-27);
  background: var(--grey-7);
}

.article-table td {
  padding: 0.5rem;
  border-bottom: 1px solid var(--grey-7);
  vertical-align: top;
}

.article-table tr:hover td {
  background: var(--grey-7);
}

.article-number {
  font-weight: bold;
  color: var(--blue);
  font-size: 0.9rem;
}

/* --- Competitor Results --- */
.competitor-result {
  padding: 1.25rem;
  background: var(--grey-7);
  border-radius: var(--radius);
  border-left: 4px solid var(--blue);
  margin-bottom: 1rem;
}

.competitor-brand {
  font-size: 0.8rem;
  color: var(--grey-50);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.25rem;
}

.competitor-original {
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--grey);
}

.competitor-arrow {
  text-align: center;
  font-size: 1.5rem;
  color: var(--grey-37);
  margin: 0.5rem 0;
}

.competitor-match {
  font-size: var(--grade-size);
  font-weight: bold;
  color: var(--red);
}

.competitor-reasoning {
  font-size: 0.9rem;
  color: var(--grey);
  margin-top: 0.75rem;
  line-height: 1.5;
}

.competitor-bridge {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--grey-27);
  font-size: 0.9rem;
}

/* Did-you-mean for partial matches */
.did-you-mean {
  padding: 1rem;
  background: var(--grey-7);
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.did-you-mean p {
  font-size: 0.9rem;
  color: var(--grey);
  margin-bottom: 0.75rem;
}

.did-you-mean-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Not found state */
.not-found {
  text-align: center;
  padding: 2rem 1rem;
}

.not-found p {
  color: var(--grey-50);
  margin-bottom: 1rem;
}

/* --- Footer --- */
.app-footer {
  text-align: center;
  padding: 1.5rem 1rem;
  border-top: 1px solid var(--grey-17);
  margin-top: 2rem;
}

.app-footer p {
  font-size: 0.75rem;
  color: var(--grey-50);
  margin-bottom: 0.25rem;
}

/* --- Toast notification --- */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--grey);
  color: var(--white);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: bold;
  z-index: 2000;
  animation: toast-in 0.3s ease, toast-out 0.3s ease 1.7s forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* --- Responsive: Tablet+ --- */
@media (min-width: 480px) {
  :root {
    --grade-size: 24px;
    --data-size: 20px;
  }

  .mode-buttons {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .btn-mode {
    flex: 1 1 calc(50% - 0.375rem);
  }

  .error-actions {
    flex-direction: row;
    justify-content: center;
  }
}

@media (min-width: 768px) {
  .view {
    padding: 2rem 1.5rem 3rem;
  }

  .param-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem 1.5rem;
  }
}
