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

:root {
  --blue:    #0d4671;
  --blue-dark: #093556;
  --blue-light: #1a5f8f;
  --green:   #035c2c;
  --green-light: #04732f;
  --grey:    #ecf0f1;
  --grey-dark: #bdc3c7;
  --text:    #2c3e50;
  --text-light: #7f8c8d;
  --white:   #ffffff;
  --red:     #e74c3c;
  --shadow:  0 2px 8px rgba(0,0,0,0.12);
  --radius:  8px;
}

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

body {
  font-family: 'Lato', sans-serif;
  background: #f4f6f8;
  color: var(--text);
  min-height: 100vh;
}

h1, h2, h3, h4 { font-family: 'Roboto', sans-serif; }

/* ── Auth ── */
#login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--blue);
}

.login-card {
  background: var(--white);
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.login-card h1 {
  color: var(--blue);
  font-size: 1.6rem;
  margin-bottom: 4px;
}

.login-card .subtitle {
  color: var(--text-light);
  font-size: 0.9rem;
  margin-bottom: 28px;
}

/* ── Layout ── */
#app { display: none; min-height: 100vh; }

header {
  background: var(--blue);
  color: var(--white);
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

header h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.3px; }
header .subtitle { font-size: 0.75rem; opacity: 0.75; }

.header-right { display: flex; align-items: center; gap: 12px; }
.user-name { font-size: 0.85rem; opacity: 0.9; }

nav {
  background: var(--blue-dark);
  display: flex;
  gap: 2px;
  padding: 0 20px;
  overflow-x: auto;
}

nav button {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  padding: 12px 16px;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
}

nav button:hover { color: var(--white); }
nav button.active { color: var(--white); border-bottom-color: var(--green-light); }

main { padding: 20px; max-width: 960px; margin: 0 auto; }

/* ── Cards & Panels ── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.panel-header h2 { font-size: 1.1rem; color: var(--blue); }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 700; color: var(--text); margin-bottom: 6px; }

input[type=text], input[type=email], input[type=password], textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--grey-dark);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--white);
  transition: border-color 0.2s;
  -webkit-appearance: none;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--blue);
}

textarea { resize: vertical; min-height: 80px; }

/* Date input - styled like regular input */
.date-input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--grey-dark);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--white);
  cursor: pointer;
}

.date-input:focus { outline: none; border-color: var(--blue); }

/* ── Pikaday overrides ── */
.pika-single {
  font-family: 'Lato', sans-serif;
  border-radius: var(--radius);
  border: 1px solid var(--grey-dark);
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  z-index: 1000;
}

.pika-button:hover, .pika-button:focus { background: var(--grey); color: var(--text); }
.is-selected .pika-button { background: var(--blue); color: var(--white); border-radius: 4px; }
.pika-prev, .pika-next { color: var(--blue); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary   { background: var(--blue);  color: var(--white); }
.btn-primary:hover { background: var(--blue-light); }
.btn-success   { background: var(--green); color: var(--white); }
.btn-success:hover { background: var(--green-light); }
.btn-danger    { background: var(--red);   color: var(--white); }
.btn-danger:hover  { opacity: 0.85; }
.btn-outline   { background: transparent; border: 1.5px solid var(--blue); color: var(--blue); }
.btn-outline:hover { background: var(--grey); }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; }
.btn-icon { padding: 8px; border-radius: 50%; background: transparent; border: none; cursor: pointer; font-size: 1.1rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Search bar ── */
.search-bar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 16px;
}

@media (max-width: 700px) {
  .search-bar { grid-template-columns: 1fr 1fr; }
  .search-bar .btn { grid-column: span 2; }
}

/* ── Inspection list ── */
.inspection-item {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: box-shadow 0.2s;
  border-left: 4px solid var(--blue);
}

.inspection-item:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.15); }

.inspection-item .factory { font-weight: 700; color: var(--blue); font-size: 1rem; }
.inspection-item .dates   { font-size: 0.85rem; color: var(--text-light); margin: 2px 0; }
.inspection-item .meta    { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.inspection-item .badge   { background: var(--grey); color: var(--text); font-size: 0.78rem; padding: 3px 8px; border-radius: 12px; }
.inspection-item .inspector { font-size: 0.82rem; color: var(--text-light); }

/* ── Detail view ── */
.detail-header { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.po-card {
  border: 1.5px solid var(--grey);
  border-radius: 6px;
  padding: 14px;
  margin-bottom: 10px;
}

.po-card .po-number { font-weight: 700; color: var(--blue); font-size: 1rem; }
.po-card .issues    { margin-top: 6px; font-size: 0.9rem; color: var(--text); white-space: pre-wrap; }

/* ── Photos ── */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-thumb .del-btn {
  position: absolute;
  top: 4px; right: 4px;
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  border-radius: 50%;
  width: 22px; height: 22px;
  font-size: 12px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}

.photo-thumb:hover .del-btn { display: flex; }

/* ── PO form rows ── */
.po-row {
  display: grid;
  grid-template-columns: 120px 1fr auto;
  gap: 8px;
  align-items: start;
  margin-bottom: 10px;
}

@media (max-width: 500px) {
  .po-row { grid-template-columns: 1fr auto; }
  .po-row textarea { grid-column: span 2; }
}

/* ── Upload area ── */
.upload-area {
  border: 2px dashed var(--grey-dark);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  color: var(--text-light);
  transition: all 0.2s;
  margin-top: 8px;
}

.upload-area:hover { border-color: var(--blue); color: var(--blue); background: var(--grey); }
.upload-area input { display: none; }

/* ── Admin table ── */
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th { background: var(--grey); padding: 10px 12px; text-align: left; font-weight: 700; color: var(--text); }
td { padding: 10px 12px; border-bottom: 1px solid var(--grey); }
tr:last-child td { border-bottom: none; }
.table-actions { display: flex; gap: 6px; }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--white);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
}

.modal h3 { margin-bottom: 16px; color: var(--blue); }

/* ── Photo lightbox ── */
#lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 300;
  align-items: center;
  justify-content: center;
}

#lightbox.open { display: flex; }
#lightbox img { max-width: 88vw; max-height: 82vh; border-radius: 4px; object-fit: contain; }
#lightbox .close {
  position: absolute;
  top: 16px; right: 16px;
  color: white; font-size: 2rem;
  cursor: pointer; background: none; border: none;
  z-index: 10;
}

.lightbox-arrow {
  position: absolute;
  top: 50%; transform: translateY(-50%);
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  font-size: 2.5rem;
  width: 48px; height: 64px;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  z-index: 10;
}
.lightbox-arrow:hover { background: rgba(255,255,255,0.3); }
.lightbox-prev { left: 12px; }
.lightbox-next { right: 12px; }

.lightbox-counter {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,0.8);
  font-size: 0.9rem;
  background: rgba(0,0,0,0.4);
  padding: 4px 12px;
  border-radius: 12px;
}

/* ── Alerts ── */
.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.alert-error   { background: #fdecea; color: var(--red); border: 1px solid #f5c6cb; }
.alert-success { background: #eafaf1; color: var(--green); border: 1px solid #c3e6cb; }

/* ── Pagination ── */
.pagination { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.pagination button { padding: 6px 12px; border: 1.5px solid var(--grey-dark); background: var(--white); border-radius: 4px; cursor: pointer; font-size: 0.85rem; }
.pagination button.active { background: var(--blue); color: var(--white); border-color: var(--blue); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Loading ── */
.spinner { text-align: center; padding: 40px; color: var(--text-light); font-size: 0.9rem; }

/* ── Responsive ── */
@media (max-width: 480px) {
  main { padding: 12px; }
  .card { padding: 14px; }
  .login-card { padding: 28px 20px; }
  header h1 { font-size: 0.95rem; }
}

/* ── Floating Action Button ── */
.fab {
  position: fixed;
  bottom: 28px;
  right: 24px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--green);
  color: white;
  font-size: 2rem;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.15s;
  line-height: 1;
}
.fab:hover { background: var(--green-light); transform: scale(1.08); }
.fab:active { transform: scale(0.95); }

/* ── Login logo ── */
.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}
.login-logo-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--blue);
  color: white;
  font-family: 'Roboto', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(13,70,113,0.3);
}

/* ── Header logo ── */
.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.header-logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: rgba(255,255,255,0.15);
  color: white;
  font-family: 'Roboto', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.po-card .po-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  flex-wrap: wrap;
  gap: 8px;
}

.po-photos { margin-top: 10px; }

.no-photos {
  color: var(--text-light);
  font-size: 0.85rem;
  font-style: italic;
  padding: 4px 0;
}

.issues.no-issues { color: var(--text-light); font-size: 0.88rem; }

.date-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
