/* ============================================================
   MyK-Assist – Design System
   iOS-inspired, refined & functional
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=DM+Mono:wght@400;500&display=swap');

/* ============================================================
   CSS VARIABLEN
   ============================================================ */
:root {
  /* Farben */
  --blue:        #007aff; /* Local grün: #11801b | Int Orange: #7d5609  | Prod Blau #007aff */
  --blue-light:  #e8f2ff; /* Local grün: #a9d6b1 | Int Orange: #e1cea8  | Prod Blau #e8f2ff */
  --blue-dark:   #0062cc; /* Local grün: #003d14 | Int Orange: #2e2004  | Prod Blau #0062cc */
  --green:       #34c759; 
  --green-light: #e8faf0;
  --red:         #ff3b30;
  --red-light:   #fff0ef;
  --orange:      #ff9500;
  --orange-light:#fff5e6;
  --purple:      #af52de;
  --purple-light:#f5eeff;
  --yellow:      #ffd60a;

  /* Neutrale */
  --bg:          #f2f2f7;
  --bg-card:     #ffffff;
  --bg-input:    #f8f8fa;
  --border:      #e5e5ea;
  --border-light:#f0f0f5;

  /* Text */
  --text:        #1c1c1e;
  --text-2:      #3a3a3c;
  --text-3:      #636366;
  --text-4:      #8e8e93;
  --text-inv:    #ffffff;

  /* Typografie */
  --font:        'DM Sans', -apple-system, sans-serif;
  --font-mono:   'DM Mono', monospace;

  /* Abstände */
  --space-xs:    4px;
  --space-sm:    8px;
  --space-md:    16px;
  --space-lg:    24px;
  --space-xl:    32px;
  --space-2xl:   48px;

  /* Radien */
  --r-sm:        8px;
  --r-md:        12px;
  --r-lg:        16px;
  --r-xl:        20px;
  --r-full:      9999px;

  /* Schatten */
  --shadow-sm:   0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:   0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg:   0 8px 24px rgba(0,0,0,0.10), 0 4px 8px rgba(0,0,0,0.04);

  /* Navigation */
  --nav-h:       60px;
  --nav-bg:      rgba(242, 242, 247, 0.85);
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

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

img { max-width: 100%; display: block; }

/* ============================================================
   NAVIGATION
   ============================================================ */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  background: var(--nav-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-md);
  gap: var(--space-sm);
}

.nav-brand {
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
  letter-spacing: -0.3px;
  margin-right: auto;
}

.nav-brand span {
  color: var(--blue);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 6px 12px;
  border-radius: var(--r-full);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-3);
  transition: all 0.15s ease;
  white-space: nowrap;
}

.nav-link:hover {
  background: var(--border-light);
  color: var(--text);
  opacity: 1;
}

.nav-link.active {
  background: var(--blue-light);
  color: var(--blue);
}

.nav-link svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Nav Mobile */
@media (max-width: 600px) {
  .nav-link span { display: none; }
  .nav-link { padding: 8px; }
}

/* ============================================================
   LAYOUT
   ============================================================ */
.page {
  max-width: 680px;
  margin: 0 auto;
  padding: var(--space-lg) var(--space-md);
  padding-bottom: 100px;
}

.page-wide {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-lg) var(--space-md);
  padding-bottom: 100px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
  gap: var(--space-md);
}

.page-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
  line-height: 1.2;
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-4);
  margin-top: 2px;
}

/* ============================================================
   KARTEN
   ============================================================ */
.card {
  background: var(--bg-card);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  border: 1px solid var(--border-light);
}

.card + .card { margin-top: var(--space-sm); }

.card-header {
  display: flex;
  align-items: center;
  padding: var(--space-md) var(--space-md);
  gap: var(--space-sm);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease;
}

.card-header:hover { background: var(--bg-input); }

.card-body {
  padding: var(--space-sm) var(--space-md) var(--space-md);
  border-top: 1px solid var(--border-light);
}

/* List Card – für Pläne, Maschinen etc. */
.list-card {
  background: var(--bg-card);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  padding: var(--space-md);
  gap: var(--space-md);
  transition: all 0.15s ease;
}

.list-card + .list-card { margin-top: var(--space-sm); }

.list-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.list-card-info { flex: 1; min-width: 0; }

.list-card-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-card-sub {
  font-size: 13px;
  color: var(--text-4);
  margin-top: 2px;
}

.list-card-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

/* ============================================================
   BADGES & PILLS
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 10px;
  border-radius: var(--r-full);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-gray   { background: var(--border); color: var(--text-3); }
.badge-blue   { background: var(--blue-light); color: var(--blue); }
.badge-green  { background: var(--green-light); color: var(--green); }
.badge-red    { background: var(--red-light); color: var(--red); }
.badge-orange { background: var(--orange-light); color: var(--orange); }
.badge-purple { background: var(--purple-light); color: var(--purple); }

/* Active / Inactive Pill */
.pill-active   { background: var(--green-light); color: var(--green); font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: var(--r-full); }
.pill-inactive { background: var(--border); color: var(--text-4); font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: var(--r-full); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--r-md);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

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

.btn-primary {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}
.btn-primary:hover { background: var(--blue-dark); opacity: 1; }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover { background: var(--bg-input); opacity: 1; }

.btn-ghost {
  background: transparent;
  color: var(--blue);
  padding: 8px 12px;
}
.btn-ghost:hover { background: var(--blue-light); opacity: 1; }

.btn-danger {
  background: var(--red-light);
  color: var(--red);
}
.btn-danger:hover { background: var(--red); color: #fff; opacity: 1; }

.btn-success {
  background: var(--green-light);
  color: var(--green);
}
.btn-success:hover { background: var(--green); color: #fff; opacity: 1; }

.btn-warning {
  background: var(--orange-light);
  color: var(--orange);
}
.btn-warning:hover { background: var(--orange); color: #fff; opacity: 1; }

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--r-md);
  flex-shrink: 0;
}

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

.btn-full { width: 100%; }

.btn-lg {
  padding: 15px 24px;
  font-size: 17px;
  border-radius: var(--r-lg);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
  border-radius: var(--r-sm);
}

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

/* ============================================================
   FORMULARE
   ============================================================ */
.form-group { margin-bottom: var(--space-md); }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-3);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.form-input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  font-family: var(--font);
  font-size: 16px;
  color: var(--text);
  background: var(--bg-card);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-appearance: none;
}

.form-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

.form-input.error {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.12);
}

.form-input::placeholder { color: var(--text-4); }

.form-select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  font-family: var(--font);
  font-size: 16px;
  color: var(--text);
  background: var(--bg-card);
  outline: none;
  cursor: pointer;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  transition: border-color 0.15s ease;
}

.form-select:focus { border-color: var(--blue); }

.form-textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  font-family: var(--font);
  font-size: 15px;
  color: var(--text);
  background: var(--bg-card);
  outline: none;
  resize: vertical;
  min-height: 80px;
  transition: border-color 0.15s ease;
}

.form-textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

.form-hint {
  font-size: 12px;
  color: var(--text-4);
  margin-top: 4px;
}

.form-error {
  font-size: 12px;
  color: var(--red);
  margin-top: 4px;
}

/* Inline Zahl-Input (für Einstellungen) */
.input-inline {
  width: 80px;
  height: 36px;
  padding: 0 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  color: var(--blue);
  text-align: center;
  background: var(--bg-card);
  outline: none;
  transition: border-color 0.15s ease;
}

.input-inline:focus { border-color: var(--blue); }
.input-inline.error { border-color: var(--red); background: var(--red-light); color: var(--red); }

/* Checkbox */
.checkbox-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
}

input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--blue);
  cursor: pointer;
  flex-shrink: 0;
}

/* ============================================================
   FELDER-LISTE (Maschinen-Settings)
   ============================================================ */
.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 0;
  border-bottom: 1px solid var(--border-light);
}

.field-row:last-child { border-bottom: none; }

.field-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.field-label-text {
  font-size: 15px;
  color: var(--text);
}

.field-limit {
  font-size: 11px;
  color: var(--text-4);
  font-family: var(--font-mono);
}

/* Hervorgehobene Gewichts-Felder */
.field-row.weight {
  background: var(--blue-light);
  margin: 0 calc(-1 * var(--space-md));
  padding: 11px var(--space-md);
  border-radius: 0;
}

.field-row.weight .field-label-text { font-weight: 600; }

/* ============================================================
   ALERTS & NACHRICHTEN
   ============================================================ */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-md);
  border-radius: var(--r-md);
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: var(--space-md);
}

.alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }

.alert-info    { background: var(--blue-light); color: var(--blue); }
.alert-success { background: var(--green-light); color: #1a7a3a; }
.alert-warning { background: var(--orange-light); color: #b85c00; }
.alert-error   { background: var(--red-light); color: var(--red); }

/* ============================================================
   TABELLEN
   ============================================================ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  text-align: left;
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-4);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 12px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-2);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-input); }

/* ============================================================
   STATS / KENNZAHLEN
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--r-lg);
  padding: var(--space-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
  text-align: center;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
  line-height: 1;
}

.stat-label {
  font-size: 12px;
  color: var(--text-4);
  margin-top: 4px;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  text-align: center;
  padding: var(--space-2xl) var(--space-lg);
  color: var(--text-4);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: var(--space-md);
  opacity: 0.5;
}

.empty-state-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-3);
  margin-bottom: var(--space-sm);
}

.empty-state-text {
  font-size: 14px;
  line-height: 1.6;
}

/* ============================================================
   FIXED FOOTER (für Speichern-Buttons etc.)
   ============================================================ */
.sticky-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(242, 242, 247, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  padding: var(--space-md);
  z-index: 50;
}

/* ============================================================
   DRAG HANDLE
   ============================================================ */
.drag-handle {
  cursor: grab;
  color: var(--text-4);
  padding: 4px;
  touch-action: none;
  flex-shrink: 0;
}

.drag-handle:active { cursor: grabbing; }

.drag-handle svg { width: 18px; height: 18px; }

/* ============================================================
   DIVIDER
   ============================================================ */
.divider {
  height: 1px;
  background: var(--border-light);
  margin: var(--space-md) 0;
}

/* ============================================================
   LOADING SPINNER
   ============================================================ */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

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

/* ============================================================
   TOGGLE SWITCH
   ============================================================ */
.toggle {
  position: relative;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: var(--r-full);
  cursor: pointer;
  transition: background 0.2s ease;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 27px;
  height: 27px;
  left: 2px;
  top: 2px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  transition: transform 0.2s ease;
}

.toggle input:checked + .toggle-slider { background: var(--blue); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ============================================================
   UTILITY KLASSEN
   ============================================================ */
.flex        { display: flex; }
.flex-col    { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm      { gap: var(--space-sm); }
.gap-md      { gap: var(--space-md); }
.flex-1      { flex: 1; }
.min-w-0     { min-width: 0; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-sm     { font-size: 13px; }
.text-xs     { font-size: 11px; }
.text-muted  { color: var(--text-4); }
.text-blue   { color: var(--blue); }
.text-green  { color: var(--green); }
.text-red    { color: var(--red); }
.font-bold   { font-weight: 700; }
.font-medium { font-weight: 500; }
.mono        { font-family: var(--font-mono); }
.truncate    { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mt-sm       { margin-top: var(--space-sm); }
.mt-md       { margin-top: var(--space-md); }
.mt-lg       { margin-top: var(--space-lg); }
.mb-sm       { margin-bottom: var(--space-sm); }
.mb-md       { margin-bottom: var(--space-md); }
.mb-lg       { margin-bottom: var(--space-lg); }
.hidden      { display: none !important; }
.sr-only     { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 480px) {
  .page, .page-wide { padding: var(--space-md) var(--space-sm); }
  .page-title { font-size: 24px; }
  .list-card-title { font-size: 16px; }
}
