/* OBU Installer — mobile-first responsive styles. No framework. */

:root {
  --bg:          #0f1115;
  --surface:     #171a21;
  --surface-2:   #1f232c;
  --border:      #2a2f3a;
  --text:        #e5e7eb;
  --text-muted:  #9ca3af;
  --primary:     #3b82f6;
  --primary-2:   #2563eb;
  --danger:      #ef4444;
  --success:     #10b981;
  --warn:        #f59e0b;
  --radius:      8px;
  --shadow:      0 4px 16px rgba(0, 0, 0, 0.25);
  --tap-min:     44px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 0.5rem 0; line-height: 1.2; font-weight: 600; }
h1 { font-size: clamp(1.5rem, 4vw, 2rem); }
h2 { font-size: clamp(1.25rem, 3vw, 1.625rem); }
h3 { font-size: 1.125rem; }

.muted { color: var(--text-muted); }
.error { color: var(--danger); }
code { background: var(--surface-2); padding: 0.1rem 0.35rem; border-radius: 4px; font-size: 0.9em; }

/* ─── Inputs & buttons — touch-friendly ─────────────────── */

input[type="text"],
input[type="password"],
input[type="email"],
input[type="file"],
select,
textarea {
  width: 100%;
  min-height: var(--tap-min);
  padding: 0.65rem 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* >=16px prevents iOS Safari auto-zoom on focus */
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

button {
  min-height: var(--tap-min);
  min-width: var(--tap-min);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

button.primary {
  background: var(--primary);
  border-color: var(--primary-2);
  color: white;
  font-weight: 600;
}
button.primary:hover { background: var(--primary-2); }

button.ghost { background: transparent; }
button.ghost:hover { background: var(--surface-2); }

button.danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
button.danger:hover { background: rgba(239, 68, 68, 0.1); }

button:disabled { opacity: 0.5; cursor: not-allowed; }

.ghost-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-min);
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}
.ghost-link:hover { background: var(--surface-2); text-decoration: none; }

/* File-picker button that looks like a regular button. */
.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-min);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
}
.file-button:hover { background: var(--surface); }

label {
  display: block;
  margin: 0.75rem 0 0.3rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* ─── Login page ─────────────────────────────────────────── */

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.login-card h1 { margin-bottom: 0.25rem; }
.login-card form { margin-top: 1rem; }
.login-card button[type="submit"] {
  width: 100%;
  margin-top: 1.25rem;
  background: var(--primary);
  border-color: var(--primary-2);
  color: white;
  font-weight: 600;
}
.login-card .hint { margin-top: 1.25rem; font-size: 0.85rem; }
.login-card .error { margin-top: 0.75rem; font-size: 0.9rem; }

/* ─── App shell ─────────────────────────────────────────── */

.app-page {
  min-height: 100vh;
  padding-bottom: calc(64px + env(safe-area-inset-bottom)); /* leave room for mobile bottom nav */
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-weight: 700; font-size: 1.1rem; }

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Desktop tab bar — hidden on small screens (mobile-nav takes over). */
.tabs { display: none; }

.app-main {
  padding: 1rem;
  max-width: 1200px;
  margin: 0 auto;
}

.tab-panel[hidden] { display: none; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

/* ─── Inline forms ──────────────────────────────────────── */

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.inline-form.stack { flex-direction: column; align-items: stretch; }
.inline-form input, .inline-form select { flex: 1 1 180px; min-width: 0; }
.inline-form .form-buttons { display: flex; gap: 0.5rem; width: 100%; }
.inline-form .error { flex-basis: 100%; }

/* ─── Data tables ───────────────────────────────────────── */

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table th {
  background: var(--surface-2);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: rgba(255, 255, 255, 0.02); }

.data-table .actions-col { width: 1%; white-space: nowrap; }
.data-table td .row-actions {
  display: flex;
  gap: 0.25rem;
  justify-content: flex-end;
}

.data-table td .row-actions button {
  min-width: var(--tap-min);
  padding: 0.4rem 0.65rem;
}

.device-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0;
}

/* Mobile: tables collapse to stacked cards using data-label attributes. */
@media (max-width: 767px) {
  .data-table, .data-table thead, .data-table tbody,
  .data-table tr, .data-table th, .data-table td {
    display: block;
  }
  .data-table thead { display: none; }

  .data-table tr {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
  }
  .data-table tr:last-child { border-bottom: none; }

  .data-table td {
    padding: 0.35rem 0;
    border: none;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
  }

  .data-table td::before {
    content: attr(data-label);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    flex-shrink: 0;
  }

  .data-table td.actions-col,
  .data-table td .row-actions { justify-content: flex-end; width: 100%; }
  .data-table td.actions-col::before { display: none; }
}

/* ─── Templates tab layout ───────────────────────────────── */

.templates-layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr; /* stacked on mobile */
}

.tile-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.tile-list li button {
  width: 100%;
  text-align: left;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.tile-list li button[aria-selected="true"] {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.08);
}
.tile-list .tile-type {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.code-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  overflow: auto;
  max-height: 60vh;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text);
  white-space: pre;
}

/* ─── Modal / full-screen sheet on mobile ────────────────── */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: grid;
  place-items: stretch;
  z-index: 100;
  padding: 0;
}

.modal[hidden] { display: none; }

.modal-body {
  background: var(--surface);
  padding: 1.25rem;
  overflow: auto;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.modal-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 1rem;
}

.modal-buttons button { flex: 1 1 auto; }

/* Desktop: modal becomes a centered card rather than full-screen. */
@media (min-width: 768px) {
  .modal {
    place-items: center;
    padding: 2rem;
  }
  .modal-body {
    max-width: 640px;
    width: 100%;
    max-height: 85vh;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
  }
  .modal-buttons { justify-content: flex-end; }
  .modal-buttons button { flex: 0 0 auto; }
}

#csv-details {
  font-size: 0.9rem;
  max-height: 40vh;
  overflow: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
}

#csv-details table { width: 100%; border-collapse: collapse; }
#csv-details th, #csv-details td {
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.85rem;
}

/* ─── Mobile bottom nav ──────────────────────────────────── */

.mobile-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}

.mnav-btn {
  flex: 1;
  min-height: 56px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-weight: 500;
  border-radius: 0;
}

.mnav-btn[aria-selected="true"] {
  color: var(--primary);
  box-shadow: inset 0 2px 0 0 var(--primary);
}

/* ─── Desktop breakpoint (≥ 768px) ───────────────────────── */

@media (min-width: 768px) {
  .mobile-nav { display: none; }

  .app-page { padding-bottom: 2rem; }

  .tabs {
    display: flex;
    gap: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1rem;
  }

  .tabs .tab {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 1rem 1.25rem;
    color: var(--text-muted);
    font-weight: 500;
    min-height: 56px;
  }
  .tabs .tab[aria-selected="true"] {
    color: var(--text);
    box-shadow: inset 0 -2px 0 0 var(--primary);
  }
  .tabs .tab:hover { color: var(--text); }

  .app-main { padding: 1.5rem; }

  .templates-layout {
    grid-template-columns: 260px 1fr;
  }

  /* Give inputs a sensible desktop max-width when used in forms. */
  .inline-form.stack input,
  .inline-form.stack select {
    max-width: 420px;
  }
}

@media (min-width: 1200px) {
  .app-main { padding: 2rem; }
}

/* Touch-only devices: always show row action buttons (no hover reveal). */
@media (hover: none) {
  .data-table td .row-actions { opacity: 1 !important; }
}
