:root {
  --petrol: #3BAFB9;
  --petrol-dark: #2E8E96;
  --darkblue: #3D4F66;
  --lightblue: #A8D5DC;
  --lightblue-bg: #E8F2F4;
  --white: #FFFFFF;
  --grey-50: #F7F9FA;
  --grey-100: #EDF1F3;
  --grey-200: #DDE3E8;
  --grey-400: #8995A1;
  --grey-700: #4A5560;
  --error: #D64545;
  --success: #4CAF7C;
  --warning: #E6A100;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  font-family: 'Jost', sans-serif;
  background: var(--grey-50);
  color: var(--darkblue);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}
body { min-height: 100vh; min-height: 100dvh; padding-bottom: env(safe-area-inset-bottom); }

.app-header {
  background: var(--white);
  padding: 14px 20px; padding-top: calc(14px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--grey-100);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
}
.app-header img { height: 30px; max-width: 100%; object-fit: contain; display: block; }
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0; max-width: 70%; }
.copyright { font-size: 10px; color: var(--grey-400); letter-spacing: 0.02em; line-height: 1; }
.header-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--grey-400); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.status-dot.offline { background: var(--warning); }
.status-dot.unconfigured { background: var(--error); }
.offline-banner { background: var(--warning); color: var(--white); padding: 10px 20px; font-size: 13px; text-align: center; font-weight: 500; }

.container { max-width: 600px; margin: 0 auto; padding: 20px; }
h1 { font-size: 24px; font-weight: 500; margin: 0 0 4px; color: var(--darkblue); }
.subtitle { font-size: 14px; color: var(--grey-400); margin: 0 0 24px; font-weight: 300; }

.tabs {
  display: flex; background: var(--white);
  border-radius: 14px; padding: 4px;
  margin-bottom: 20px; border: 1px solid var(--grey-100);
}
.tab {
  flex: 1; padding: 12px 6px; text-align: center;
  font-size: 12px; font-weight: 500; color: var(--grey-400);
  border-radius: 10px; cursor: pointer; transition: all .2s;
  border: none; background: transparent; font-family: inherit;
}
.tab.active { background: var(--petrol); color: var(--white); }

.card { background: var(--white); border-radius: 16px; padding: 20px; margin-bottom: 16px; border: 1px solid var(--grey-100); }
.card-title { font-size: 16px; font-weight: 500; margin: 0 0 16px; color: var(--darkblue); display: flex; align-items: center; justify-content: space-between; }
.card-title .badge { font-size: 11px; background: var(--lightblue-bg); color: var(--darkblue); padding: 3px 8px; border-radius: 8px; font-weight: 500; }

.field { margin-bottom: 14px; }
label { display: block; font-size: 13px; font-weight: 500; color: var(--grey-700); margin-bottom: 6px; }
label .required { color: var(--petrol); }
.label-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.label-row label { margin-bottom: 0; }
input[type="text"], input[type="number"], input[type="datetime-local"], input[type="url"], textarea, select {
  width: 100%; padding: 14px;
  font-size: 16px; font-family: inherit;
  border: 1.5px solid var(--grey-200); border-radius: 12px;
  background: var(--white); color: var(--darkblue);
  transition: border-color .15s;
  -webkit-appearance: none; appearance: none;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--petrol); }
input.invalid, textarea.invalid, select.invalid { border-color: var(--error); }
textarea { min-height: 70px; resize: vertical; }
select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%233D4F66' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 16px center; padding-right: 40px;
}
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.helper-link { background: none; border: none; padding: 0; color: var(--petrol); font-size: 12px; font-weight: 500; cursor: pointer; font-family: inherit; }
.helper-link:hover { text-decoration: underline; }
.help-text { font-size: 12px; color: var(--grey-400); margin-top: 6px; line-height: 1.4; }
.help-text code { background: var(--grey-100); padding: 1px 5px; border-radius: 4px; font-size: 11px; }

.plausi-warn {
  display: flex; align-items: center; gap: 8px;
  background: rgba(230, 161, 0, .12); color: var(--warning);
  padding: 10px 12px; border-radius: 10px; font-size: 12px;
  margin-top: -6px; margin-bottom: 14px;
}

.kpi-section-label { font-size: 11px; font-weight: 500; color: var(--grey-400); text-transform: uppercase; letter-spacing: .8px; margin: 18px 0 10px; }
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi-grid.three { grid-template-columns: 1fr 1fr 1fr; }
.kpi { background: var(--grey-50); border-radius: 12px; padding: 12px; border-left: 3px solid var(--grey-200); }
.kpi.featured { background: linear-gradient(135deg, var(--lightblue-bg), var(--white)); padding: 16px; }
.kpi.featured.solo { grid-column: 1 / -1; }
.kpi-label { font-size: 11px; color: var(--grey-400); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
.kpi-value { font-size: 22px; font-weight: 500; color: var(--darkblue); line-height: 1.1; }
.kpi.featured .kpi-value { font-size: 32px; }
.kpi-sub { font-size: 11px; color: var(--grey-400); margin-top: 2px; }
.kpi.green { border-left-color: var(--success); }
.kpi.yellow { border-left-color: var(--warning); }
.kpi.red { border-left-color: var(--error); }
.kpi.green .kpi-value { color: var(--success); }
.kpi.yellow .kpi-value { color: var(--warning); }
.kpi.red .kpi-value { color: var(--error); }

.defect-row { display: grid; grid-template-columns: 1fr 90px 36px; gap: 8px; align-items: start; margin-bottom: 8px; }
.defect-row select, .defect-row input { padding: 12px; font-size: 14px; }
.defect-remove { background: var(--grey-100); color: var(--grey-700); border: none; border-radius: 10px; height: 48px; cursor: pointer; font-size: 18px; font-weight: 500; transition: background .15s; }
.defect-remove:hover { background: var(--error); color: var(--white); }
.defect-add { background: transparent; color: var(--petrol); border: 1.5px dashed var(--petrol); border-radius: 10px; padding: 10px; width: 100%; font-size: 13px; font-weight: 500; cursor: pointer; font-family: inherit; margin-top: 4px; }

.toggle-field { display: flex; align-items: center; justify-content: space-between; padding: 14px; background: var(--grey-50); border-radius: 12px; margin-bottom: 14px; }
.toggle-field-label { font-size: 14px; font-weight: 500; color: var(--darkblue); }
.toggle-field-label .required { color: var(--petrol); }
.toggle-switch { position: relative; width: 48px; height: 28px; background: var(--grey-200); border-radius: 14px; cursor: pointer; transition: background .2s; }
.toggle-switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; background: var(--white); border-radius: 50%; transition: left .2s; box-shadow: 0 2px 4px rgba(0,0,0,.15); }
.toggle-switch.on { background: var(--petrol); }
.toggle-switch.on::after { left: 23px; }

.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 16px; font-size: 16px; font-weight: 500; font-family: inherit; border: none; border-radius: 12px; cursor: pointer; transition: all .15s; -webkit-appearance: none; }
.btn-primary { background: var(--petrol); color: var(--white); }
.btn-primary:hover { background: var(--petrol-dark); }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { background: var(--grey-200); color: var(--grey-400); cursor: not-allowed; }
.btn-secondary { background: var(--white); color: var(--darkblue); border: 1.5px solid var(--grey-200); }
.btn-secondary:active { background: var(--grey-100); }
.btn-text { background: transparent; color: var(--petrol); padding: 10px; font-size: 14px; }
.btn-large { padding: 18px; font-size: 17px; border-radius: 14px; }
.btn-stop { background: var(--error); color: var(--white); }
.btn-stop:hover { background: #b73838; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(100px);
  background: var(--darkblue); color: var(--white);
  padding: 14px 24px; border-radius: 12px;
  font-size: 14px; font-weight: 500; z-index: 200;
  transition: transform .3s, opacity .3s; opacity: 0;
  box-shadow: 0 10px 30px rgba(61, 79, 102, 0.3);
  max-width: 90vw; text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--error); }
.toast.warning { background: var(--warning); }

.history-item { padding: 14px; background: var(--grey-50); border-radius: 10px; margin-bottom: 8px; font-size: 13px; border-left: 3px solid var(--petrol); }
.history-item.pending { border-left-color: var(--warning); }
.history-item.failed { border-left-color: var(--error); }
.history-meta { display: flex; justify-content: space-between; color: var(--grey-400); font-size: 11px; margin-bottom: 4px; }
.history-summary { color: var(--darkblue); font-weight: 500; }
.history-detail { color: var(--grey-700); font-size: 12px; margin-top: 2px; line-height: 1.4; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--grey-400); font-size: 14px; }

.settings-summary { display: flex; align-items: center; justify-content: space-between; padding: 14px; background: var(--lightblue-bg); border-radius: 12px; cursor: pointer; margin-bottom: 16px; }
.settings-summary-text { font-size: 13px; color: var(--darkblue); }
.settings-summary-text strong { font-weight: 500; }
.settings-summary-action { font-size: 13px; color: var(--petrol); font-weight: 500; }

.quick-context { background: var(--lightblue-bg); border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; }
.quick-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick-row-3 { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 0.7fr); }
.quick-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.quick-field label { font-size: 11px; color: var(--grey-400); font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }
.quick-actions { display: flex; justify-content: flex-end; margin-top: 10px; }
.btn-sm { padding: 6px 18px; font-size: 13px; width: auto; min-width: 80px; }
.quick-field input, .quick-field select { width: 100%; box-sizing: border-box; padding: 8px 10px; border: 1px solid var(--grey-100); background: var(--white); border-radius: 8px; font-size: 14px; color: var(--darkblue); font-family: inherit; }
.quick-field input:focus, .quick-field select:focus { outline: none; border-color: var(--petrol); }
.quick-field input[readonly] { background: var(--grey-50); color: var(--grey-400); cursor: default; }
input[readonly], input[readonly]:focus { background: var(--grey-50); color: var(--grey-400); cursor: default; border-color: var(--grey-100); }

/* Stopwatch mode switch (Cycle Time / Downtime) */
.timer-mode-switch {
  display: inline-flex; background: var(--grey-50);
  border-radius: 10px; padding: 4px; gap: 4px;
  margin: 0 auto 8px; align-self: center;
  display: flex; justify-content: center; width: fit-content;
}
.timer-mode-btn {
  background: transparent; border: none;
  padding: 8px 18px; font-size: 14px; color: var(--grey-400);
  border-radius: 6px; font-weight: 500; font-family: inherit;
  cursor: pointer;
}
.timer-mode-btn.active {
  background: var(--white); color: var(--darkblue);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.timer-mode-switch.locked .timer-mode-btn { opacity: 0.4; cursor: not-allowed; }

/* Per-row type selector in the combined entries list — compact, fixed width */
.entry-type-select {
  font-size: 12px; padding: 4px 6px;
  border: 1px solid var(--grey-200); border-radius: 6px;
  background: var(--white); color: var(--darkblue);
  font-family: inherit; font-weight: 500;
  width: 90px; max-width: 90px; flex: 0 0 90px;
}
/* Duration input: wide enough to comfortably show + edit a 5-6 digit number */
.run-duration-input {
  width: 80px; min-width: 80px;
  padding: 4px 8px;
  border: 1px solid var(--grey-200); border-radius: 6px;
  font-size: 15px; font-weight: 500; color: var(--darkblue);
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: inherit;
}
.run-duration-input:focus { outline: none; border-color: var(--petrol); }
.run-card.type-downtime { border-left: 3px solid var(--warning); }
.run-card.type-cycle    { border-left: 3px solid var(--petrol);  }

/* Cycle context fields are auto-filled from the Capture tab — show them as visibly locked */
.locked-from-capture {
  background: var(--grey-50) !important;
  color: var(--grey-700) !important;
  cursor: default !important;
  border-color: var(--grey-100) !important;
  opacity: 0.85;
}
select.locked-from-capture { appearance: none; -webkit-appearance: none; background-image: none; padding-right: 10px; }
.quick-status { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(0,0,0,0.06); font-size: 12px; color: var(--darkblue); cursor: pointer; }
.quick-detail { color: var(--grey-400); flex: 1; text-align: right; font-size: 11px; }

.hidden { display: none !important; }


/* Context lock — capture/cycle/history hidden until user fills quick context + presses Load */
.context-lock-banner {
  display: none;
  background: #FFF3CD;
  color: #856404;
  border: 1px solid #FFE69C;
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 14px;
  text-align: center;
}
.context-locked .context-lock-banner { display: block; }
.context-locked .tab:not([data-tab="settings"]) { opacity: 0.4; pointer-events: none; }
.context-locked #tab-capture, .context-locked #tab-cycle, .context-locked #tab-history {
  opacity: 0.35;
  pointer-events: none;
  user-select: none;
}
.time-override { background: var(--grey-50); padding: 12px; border-radius: 10px; margin-top: 8px; }

.timer-display { text-align: center; padding: 24px 0 18px; }
.timer-value { font-size: 64px; font-weight: 300; color: var(--darkblue); font-variant-numeric: tabular-nums; letter-spacing: -1.5px; line-height: 1; margin-bottom: 10px; font-family: 'Jost', sans-serif; }
.timer-value.running { color: var(--petrol); }
.timer-status { font-size: 11px; color: var(--grey-400); text-transform: uppercase; letter-spacing: 1px; font-weight: 500; }
.timer-status.running { color: var(--petrol); }

.run-card { background: var(--grey-50); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; border-left: 3px solid var(--success); }
.run-card.excluded { border-left-color: var(--grey-200); background: var(--white); }
.run-card.excluded .run-duration { text-decoration: line-through; color: var(--grey-400); }
.run-card.excluded .run-num { color: var(--grey-400); }
.run-header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.run-num { font-size: 12px; color: var(--grey-700); font-weight: 500; min-width: 30px; }
.run-duration { font-size: 17px; font-weight: 500; color: var(--darkblue); font-variant-numeric: tabular-nums; flex: 1; }
.run-time { font-size: 11px; color: var(--grey-400); margin-right: 4px; }
.run-include-wrap { display: flex; align-items: center; gap: 6px; }
.run-include-label { font-size: 11px; color: var(--grey-400); text-transform: uppercase; letter-spacing: .5px; }
.run-toggle { width: 36px; height: 20px; background: var(--grey-200); border-radius: 10px; position: relative; cursor: pointer; transition: background .2s; }
.run-toggle::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: var(--white); border-radius: 50%; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.run-toggle.on { background: var(--success); }
.run-toggle.on::after { left: 18px; }
.run-remove { background: transparent; border: none; color: var(--grey-400); font-size: 18px; cursor: pointer; padding: 2px 6px; line-height: 1; }
.run-remove:hover { color: var(--error); }
.run-comment { width: 100%; padding: 8px 10px; font-size: 13px; border: 1px solid var(--grey-200); border-radius: 8px; background: var(--white); font-family: inherit; color: var(--darkblue); }
.run-comment::placeholder { color: var(--grey-400); }
.run-card.excluded .run-comment { background: var(--grey-50); }

.photo-input-wrapper {
  position: relative; display: flex; align-items: center; gap: 12px;
  padding: 14px; background: var(--grey-50);
  border: 1.5px dashed var(--grey-200); border-radius: 12px;
  cursor: pointer;
}
.photo-input-wrapper input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photo-icon {
  width: 48px; height: 48px; border-radius: 10px;
  background: var(--lightblue-bg);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; color: var(--petrol);
}
.photo-icon img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; }
.photo-text { font-size: 13px; color: var(--grey-700); flex: 1; }
.photo-text strong { color: var(--darkblue); display: block; margin-bottom: 2px; font-weight: 500; }
.photo-clear {
  position: relative; z-index: 2;
  background: var(--white); border: 1px solid var(--grey-200);
  color: var(--error); font-size: 12px; cursor: pointer;
  padding: 6px 12px; border-radius: 8px; font-family: inherit;
  flex-shrink: 0;
}
.photo-clear:hover { background: var(--grey-50); }
/* When a photo is attached, show a clear "attached" state */
.photo-input-wrapper.has-photo {
  background: var(--lightblue-bg); border-style: solid; border-color: var(--petrol);
}
.photo-input-wrapper.has-photo .photo-icon {
  width: 56px; height: 56px;
}
