:root {
  --bg: #111;
  --bg-card: #1e1e1e;
  --bg-input: #2a2a2a;
  --bg-modal: #242424;
  --border: #333;
  --accent: #e07b00;
  --accent-light: #f59d30;
  --text: #f0f0f0;
  --text-muted: #888;
  --danger: #c0392b;
  --tab-inactive: #2a2a2a;
  --radius: 8px;
  --header-height: 56px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.5px;
  flex: 1;
}

.back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 16px;
  font-weight: 600;
  padding: 8px 4px 8px 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.back-btn::before {
  content: "‹";
  font-size: 22px;
  line-height: 1;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 22px;
  padding: 8px;
  cursor: pointer;
  border-radius: var(--radius);
  min-width: 40px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active {
  background: var(--bg-input);
}

.icon-btn.danger {
  color: var(--danger);
}

/* ── Content area ── */
.content {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

/* ── Search ── */
.search-wrap {
  padding: 0 16px 12px;
}

.search-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
  padding: 10px 14px;
  outline: none;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  border-color: var(--accent);
}

/* ── Location pills ── */
.location-pills {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.location-pills::-webkit-scrollbar {
  display: none;
}

.location-pill {
  flex-shrink: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  cursor: pointer;
  white-space: nowrap;
}

.location-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
  font-weight: 700;
}

/* ── Machine list ── */
.machine-list {
  list-style: none;
}

.machine-row {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  gap: 12px;
  min-height: 64px;
}

.machine-row:active {
  background: var(--bg-card);
}

.machine-row-info {
  flex: 1;
  min-width: 0;
}

.machine-row-name {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.machine-row-location {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.machine-row-chevron {
  color: var(--border);
  font-size: 20px;
  flex-shrink: 0;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 24px;
  font-size: 15px;
  line-height: 1.6;
}

.empty-state p:first-child {
  font-size: 36px;
  margin-bottom: 12px;
}

/* ── Add button (FAB) ── */
.fab {
  position: fixed;
  bottom: 24px;
  right: 50%;
  transform: translateX(calc(50% + min(calc(50vw - 300px), 0px)));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #000;
  border: none;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

.fab:active {
  background: var(--accent-light);
}

/* ── Detail view ── */
.detail-meta {
  padding: 12px 16px;
  color: var(--text-muted);
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

/* ── Tab bar ── */
.tab-bar {
  display: flex;
  border-bottom: 2px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: var(--header-height);
  z-index: 5;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 500;
  padding: 14px 8px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Location selector (inside This Machine tab) ── */
.loc-selector {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.loc-actions {
  display: flex;
  gap: 12px;
}

.loc-action-btn {
  background: none;
  border: none;
  font-size: 13px;
  color: var(--text-muted);
  padding: 0;
  cursor: pointer;
}

.loc-action-btn.danger {
  color: var(--danger);
}

.add-loc-btn {
  color: var(--accent);
  border-color: var(--accent);
}

/* ── Note fields ── */
.tab-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.field-input,
.field-textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  padding: 10px 12px;
  outline: none;
  width: 100%;
  resize: vertical;
}

.field-input:focus,
.field-textarea:focus {
  border-color: var(--accent);
}

.field-textarea {
  min-height: 100px;
  line-height: 1.5;
}

.field-textarea.tall {
  min-height: 160px;
}

/* ── Edit modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

@media (min-height: 500px) {
  .modal-overlay {
    align-items: center;
  }
}

.modal {
  background: var(--bg-modal);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 600px;
  padding: 24px 20px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (min-height: 500px) {
  .modal {
    border-radius: 16px;
    margin: 16px;
    width: calc(100% - 32px);
  }
}

.modal h2 {
  font-size: 18px;
  font-weight: 700;
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 4px;
}

.btn {
  flex: 1;
  padding: 13px;
  border-radius: var(--radius);
  border: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text);
}

.btn-primary {
  background: var(--accent);
  color: #000;
}

.btn-primary:active { background: var(--accent-light); }
.btn-secondary:active { background: var(--border); }
