/* Material Hub - Material Management Services PWA */

:root {
  --primary: #1a237e;
  --primary-light: #534bae;
  --surface: #f5f5f5;
  --surface-elevated: #ffffff;
  --text: #212121;
  --text-secondary: #757575;
  --success: #2e7d32;
  --radius: 12px;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  margin: 0;
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--surface);
  color: var(--text);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

/* ── Header ── */

.app-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  padding: 2rem 1.5rem;
  padding-top: max(2rem, env(safe-area-inset-top));
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.app-header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
}

.tagline {
  margin: 0.25rem 0 0;
  opacity: 0.9;
  font-size: 0.95rem;
}

.header-icon-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s;
  flex-shrink: 0;
}

.header-icon-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* ── Home Grid ── */

.app-main {
  padding: 1.5rem;
  padding-bottom: max(5rem, calc(env(safe-area-inset-bottom) + 4.5rem));
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.home-grid.hidden {
  display: none;
}

.grid-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1.75rem 1rem;
  background: var(--surface-elevated);
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s, box-shadow 0.12s;
}

.grid-tile:active {
  transform: scale(0.97);
}

.grid-tile:hover {
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}

.grid-tile:last-child:nth-child(odd) {
  grid-column: 1 / -1;
  max-width: 50%;
  justify-self: center;
}

.tile-icon {
  width: 48px;
  height: 48px;
  color: var(--primary);
}

.tile-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}

/* ── Bottom Navigation ── */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface-elevated);
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  justify-content: center;
  padding: 0.5rem 0;
  padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
  z-index: 100;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
}

.bottom-nav.hidden {
  display: none;
}

.bottom-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.4rem 1.5rem;
  touch-action: manipulation;
  min-height: 44px;
}

.bottom-nav-btn:hover {
  opacity: 0.7;
}

/* ── Tab Panels ── */

.tab-panel {
  background: var(--surface-elevated);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

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

.tab-panel h2 {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
}

.tab-panel p {
  margin: 0;
  color: var(--text-secondary);
}

/* ── Status ── */

.status {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.badge {
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
}

.badge.online {
  background: rgba(46, 125, 50, 0.15);
  color: var(--success);
}

.badge.offline {
  background: rgba(158, 158, 158, 0.2);
  color: var(--text-secondary);
}

.install-prompt.hidden {
  display: none;
}

/* ── Buttons ── */

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.75rem 1.25rem;
  min-height: 44px;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-primary:hover {
  background: var(--primary-light);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface);
  color: var(--primary);
  border: 1px solid rgba(26, 35, 126, 0.3);
  padding: 0.6rem 1rem;
  min-height: 44px;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-secondary:hover {
  background: rgba(26, 35, 126, 0.06);
}

/* ── Forms ── */

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

.form-group label {
  display: block;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.75rem 0.75rem;
  min-height: 44px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
  touch-action: manipulation;
}

.form-group textarea {
  min-height: 88px;
  resize: vertical;
}

.form-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23757575' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

.form-output {
  display: block;
  padding: 0.5rem 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.input-with-action {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.input-with-action input {
  flex: 1;
  min-width: 120px;
}

.scan-preview {
  margin-top: 0.5rem;
  position: relative;
}

.scan-preview video,
.scan-preview canvas,
.scan-preview img {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid #ddd;
}

.scan-preview .scan-actions {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.5rem;
}

.raw-in-session.hidden {
  display: none;
}

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

/* ── Settings ── */

.settings-section {
  margin-bottom: 1.5rem;
}

.settings-section h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.settings-add {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.settings-add input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
}

.settings-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.settings-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid #eee;
}

.settings-item:last-child {
  border-bottom: none;
}

.settings-remove {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0 0.5rem;
  line-height: 1;
}

.settings-remove:hover {
  color: #c62828;
}

.settings-empty {
  padding: 0.5rem 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.settings-hint {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.settings-hint a {
  color: var(--primary);
}

/* ── Grades ── */

.grades-container.hidden {
  display: none;
}

.grade-batch-group {
  margin-bottom: 1.25rem;
  padding: 1rem;
  background: rgba(26, 35, 126, 0.04);
  border-radius: var(--radius);
  border: 1px solid rgba(26, 35, 126, 0.12);
}

.grade-batch-group label {
  display: block;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.grade-batch-group select,
.grade-batch-group input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  margin-bottom: 0.75rem;
}

.grade-batch-group input:last-of-type {
  margin-bottom: 0;
}

/* ── Responsive ── */

@media (min-width: 600px) {
  .app-header {
    padding: 2.5rem 2rem;
  }

  .app-main {
    max-width: 640px;
    margin: 0 auto;
  }

  .home-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .grid-tile:last-child:nth-child(odd) {
    max-width: 100%;
  }
}
