/* ============================================================
   BCD HARD TURNING SYSTEM — Desktop Optimized UI
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  /* Color Palette */
  --sidebar-bg:       #0f172a;
  --sidebar-border:   rgba(255,255,255,0.07);
  --sidebar-hover:    rgba(255,255,255,0.06);
  --sidebar-active:   rgba(79,70,229,0.25);
  --sidebar-text:     #94a3b8;
  --sidebar-text-act: #e2e8f0;
  --sidebar-accent:   #6366f1;

  --bg-body:          #f1f5f9;
  --bg-surface:       #ffffff;
  --bg-elevated:      #ffffff;
  --bg-subtle:        #f8fafc;

  --border-color:     #e2e8f0;
  --border-focus:     #6366f1;

  --text-dark:        #0f172a;
  --text-main:        #1e293b;
  --text-muted:       #64748b;
  --text-light:       #94a3b8;
  --text-dim:         #cbd5e1;

  --color-primary:        #4f46e5;
  --color-primary-hover:  #4338ca;
  --color-primary-light:  rgba(79,70,229,0.08);

  --color-success:        #10b981;
  --color-success-bg:     rgba(16,185,129,0.08);
  --color-success-border: rgba(16,185,129,0.2);

  --color-warning:        #f59e0b;
  --color-warning-bg:     rgba(245,158,11,0.08);

  --color-danger:         #ef4444;
  --color-danger-bg:      rgba(239,68,68,0.08);

  /* Metrics */
  --font-family:    'Inter', system-ui, -apple-system, sans-serif;
  --sidebar-w:      240px;
  --header-h:       58px;
  --radius-sm:      6px;
  --radius-md:      10px;
  --radius-lg:      14px;

  --shadow-xs:   0 1px 2px rgba(0,0,0,0.05);
  --shadow-sm:   0 2px 8px rgba(15,23,42,0.06);
  --shadow-md:   0 4px 16px rgba(15,23,42,0.1);
  --shadow-lg:   0 12px 32px rgba(15,23,42,0.14);
  --shadow-modal:0 24px 48px rgba(15,23,42,0.18);

  --transition: 0.18s cubic-bezier(0.4,0,0.2,1);
}

/* --- Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: var(--font-family);
  background: var(--bg-body);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
.hidden { display: none !important; }

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
.login-wrapper {
  position: fixed; inset: 0; z-index: 1000;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
  display: flex; align-items: center; justify-content: center;
}
.login-wrapper::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 30% 50%, rgba(99,102,241,0.15) 0%, transparent 60%),
              radial-gradient(ellipse at 70% 50%, rgba(16,185,129,0.08) 0%, transparent 60%);
  pointer-events: none;
}

.login-card {
  position: relative;
  width: 100%; max-width: 420px;
  background: rgba(255,255,255,0.04);
  backdrop-filter: blur(24px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 48px 40px;
  box-shadow: 0 32px 64px rgba(0,0,0,0.5);
}

.login-header { text-align: center; margin-bottom: 36px; }
.login-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 56px; height: 56px;
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: #fff; border-radius: 16px; margin-bottom: 20px;
  box-shadow: 0 8px 24px rgba(99,102,241,0.4);
}
.login-title { font-size: 24px; font-weight: 800; color: #f1f5f9; letter-spacing: -0.03em; }
.login-sub { font-size: 14px; color: #64748b; margin-top: 6px; }
.login-form .form-group { margin-bottom: 16px; }
.login-form .form-label { color: #94a3b8; }
.login-form .form-input {
  background: rgba(255,255,255,0.07);
  border-color: rgba(255,255,255,0.12);
  color: #f1f5f9;
}
.login-form .form-input::placeholder { color: #475569; }
.login-form .form-input:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99,102,241,0.2);
  background: rgba(255,255,255,0.1);
}
.login-error {
  font-size: 13px; color: #fca5a5;
  background: rgba(239,68,68,0.15); border: 1px solid rgba(239,68,68,0.3);
  padding: 10px 14px; border-radius: var(--radius-sm);
  margin-bottom: 16px; text-align: center; font-weight: 500;
}

/* ============================================================
   APP SHELL (Sidebar + Header + Main)
   ============================================================ */
#appContent {
  display: flex;
  min-height: 100vh;
}

/* ── SIDEBAR (left nav) ── */
.bottom-nav {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  padding: 0;
  z-index: 150;
  box-shadow: 4px 0 24px rgba(0,0,0,0.12);
}

/* Sidebar brand */
.bottom-nav::before {
  content: 'BCD HARD TURNING';
  display: block;
  font-size: 11px;
  font-weight: 800;
  color: #6366f1;
  letter-spacing: 1.5px;
  padding: 24px 24px 20px;
  border-bottom: 1px solid var(--sidebar-border);
  margin-bottom: 12px;
}

.nav-btn {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  margin: 2px 12px;
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  cursor: pointer;
  border-radius: 8px;
  font-family: var(--font-family);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition);
  text-align: left;
}
.nav-btn svg { flex-shrink: 0; opacity: 0.7; transition: opacity var(--transition); }
.nav-btn span { font-size: 14px; font-weight: 500; }
.nav-btn:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-act);
  transform: none;
}
.nav-btn:hover svg { opacity: 1; }
.nav-btn.active {
  background: var(--sidebar-active);
  color: #a5b4fc;
}
.nav-btn.active svg { opacity: 1; color: #a5b4fc; }

/* ── HEADER (top bar) ── */
.app-header {
  position: fixed;
  left: var(--sidebar-w);
  right: 0;
  top: 0;
  height: var(--header-h);
  z-index: 100;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-xs);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 100%; padding: 0 28px;
}
.header-logo { display: flex; align-items: center; gap: 10px; }
.logo-icon-sm { color: var(--color-primary); display: flex; align-items: center; }
.logo-title { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; color: var(--text-dark); }
.header-right { display: flex; align-items: center; gap: 12px; }

.user-badge {
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  background: var(--bg-subtle); padding: 5px 12px;
  border-radius: 99px; border: 1px solid var(--border-color);
}
.btn-logout {
  background: transparent; border: none; cursor: pointer;
  color: var(--text-muted); padding: 6px;
  display: flex; align-items: center; border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.btn-logout:hover { color: var(--color-danger); background: var(--color-danger-bg); }

/* ── MAIN CONTENT AREA ── */
.app-main {
  margin-left: var(--sidebar-w);
  padding-top: calc(var(--header-h) + 32px);
  padding-bottom: 48px;
  padding-left: 32px;
  padding-right: 32px;
  width: 100%;
  max-width: calc(var(--sidebar-w) + 1200px);
}

/* ── TABS ── */
.tab-pane { display: none; animation: fadeIn 0.2s ease-out forwards; }
.tab-pane.active { display: block; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.section-header { margin-bottom: 24px; display: flex; align-items: flex-start; justify-content: space-between; }
.section-title { font-size: 22px; font-weight: 800; letter-spacing: -0.03em; color: var(--text-dark); }
.section-sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ── TAB INPUT: 2-column layout ── */
#tabInput.active {
  display: grid;
  grid-template-columns: 480px 1fr;
  grid-template-rows: auto auto auto;
  gap: 0 28px;
  align-items: start;
}
#tabInput .section-header {
  grid-column: 1 / -1;
  margin-bottom: 20px;
}
#tabInput .card.scanner-card {
  grid-column: 1;
  grid-row: 2;
  margin-bottom: 20px;
}
#tabInput .card.form-card {
  grid-column: 1;
  grid-row: 3;
}

/* Right column: future use or leave empty */

/* History tab: full width grid */
#tabHistory.active .defect-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 20px;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--text-main); margin-bottom: 6px;
}
.form-input {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  font-family: var(--font-family); font-size: 14px; color: var(--text-main);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none; -webkit-appearance: none;
}
.form-input::placeholder { color: var(--text-dim); }
.form-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
}
.form-input:disabled {
  background: var(--bg-subtle);
  color: var(--text-light);
  cursor: not-allowed;
  opacity: 0.6;
}
.form-textarea { resize: vertical; min-height: 72px; }
.select-wrapper { position: relative; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; font-family: var(--font-family); font-size: 14px; font-weight: 600;
  border-radius: var(--radius-md); border: 1px solid transparent; cursor: pointer;
  transition: all var(--transition); text-decoration: none; user-select: none;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: scale(0.98); }
.btn-full { width: 100%; }

.btn-primary {
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: #fff; box-shadow: 0 4px 12px rgba(79,70,229,0.3); border: none;
}
.btn-primary:hover {
  background: linear-gradient(135deg, #4338ca, #4f46e5);
  box-shadow: 0 6px 20px rgba(79,70,229,0.4);
}

.btn-secondary {
  background: var(--bg-subtle); color: var(--text-main);
  border: 1px solid var(--border-color);
}
.btn-secondary:hover { background: #fff; border-color: #cbd5e1; }

.btn-outline {
  background: transparent; color: var(--text-main);
  border: 1px solid var(--border-color);
}
.btn-outline:hover {
  border-color: var(--color-primary); color: var(--color-primary);
  background: var(--color-primary-light);
}

.btn-success {
  background: linear-gradient(135deg, #10b981, #34d399);
  color: #fff; box-shadow: 0 4px 12px rgba(16,185,129,0.3); border: none;
}
.btn-icon {
  background: transparent; border: none; cursor: pointer;
  padding: 6px; color: var(--text-muted); display: flex; align-items: center;
  border-radius: var(--radius-sm); transition: all var(--transition);
}
.btn-icon:hover { background: var(--bg-subtle); color: var(--color-danger); }

/* ============================================================
   SCANNER / SN INPUT
   ============================================================ */
.manual-input-row { display: flex; gap: 8px; }
.scanner-card .manual-input-row input { font-size: 15px; font-weight: 500; }

/* SN Info box */
#snInfo {
  margin-top: 14px; padding: 14px 16px;
  background: linear-gradient(135deg, #f0f4ff, #faf5ff);
  border-radius: var(--radius-md);
  border: 1px solid rgba(99,102,241,0.2);
  display: flex; gap: 20px;
}

/* ============================================================
   HISTORY: STATS + CARDS
   ============================================================ */
.stats-row { display: flex; gap: 16px; margin-bottom: 24px; }
.stat-chip {
  flex: 1; background: var(--bg-surface); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); padding: 20px 24px; display: flex; flex-direction: column;
  box-shadow: var(--shadow-sm); transition: box-shadow var(--transition);
}
.stat-chip:hover { box-shadow: var(--shadow-md); }
.stat-txt {
  font-size: 11px; color: var(--text-muted); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.8px;
}
.stat-num { font-size: 32px; font-weight: 800; line-height: 1; margin-top: 8px; }
.text-primary { color: var(--color-primary); }
.text-success  { color: var(--color-success); }
.text-warning  { color: var(--color-warning); }

.defect-list { display: flex; flex-direction: column; gap: 12px; }
.defect-card {
  background: var(--bg-surface); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); padding: 18px 20px;
  transition: box-shadow var(--transition), border-color var(--transition);
  box-shadow: var(--shadow-sm);
}
.defect-card:hover { box-shadow: var(--shadow-md); border-color: #c7d2fe; }
.defect-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 6px; }
.defect-meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.meta-tag {
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  background: var(--bg-subtle); padding: 3px 10px;
  border-radius: 99px; border: 1px solid var(--border-color);
}
.defect-desc { font-size: 13px; color: var(--text-muted); line-height: 1.4; }

.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-light);
  font-size: 14px; grid-column: 1 / -1;
}

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(15,23,42,0.5); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  transition: opacity var(--transition);
}
.modal-box {
  width: 100%; max-width: 520px;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  overflow: hidden;
  animation: scaleIn 0.22s cubic-bezier(0.16,1,0.3,1);
}
@keyframes scaleIn {
  from { transform: scale(0.95); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 17px; font-weight: 700; color: var(--text-dark); }
.modal-body { padding: 20px 24px; max-height: 70vh; overflow-y: auto; }
.modal-footer {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border-color);
  display: flex; gap: 12px; justify-content: flex-end;
}
.modal-footer .btn { min-width: 100px; }

/* ============================================================
   TOASTS
   ============================================================ */
.toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 400;
  display: flex; flex-direction: column; gap: 8px; width: 320px;
}
.toast {
  background: var(--bg-surface); border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  padding: 12px 16px; border-radius: var(--radius-md);
  font-size: 14px; font-weight: 500;
  animation: toastIn 0.22s ease forwards;
}
@keyframes toastIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
.toast-success { border-left: 3px solid var(--color-success); }
.toast-error   { border-left: 3px solid var(--color-danger); }
.toast-info    { border-left: 3px solid var(--color-primary); }

/* ============================================================
   FILTER / DATE CONTROLS
   ============================================================ */
.filter-row { display: flex; gap: 8px; margin-bottom: 16px; }
.filter-btn {
  padding: 6px 14px; border: 1px solid var(--border-color); border-radius: 99px;
  background: var(--bg-surface); color: var(--text-muted);
  font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: all var(--transition);
}
.filter-btn.active { background: var(--text-dark); color: #fff; border-color: var(--text-dark); }
