/* ── Reset & base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --primary: #1a73e8;
  --primary-dark: #1558b0;
  --danger: #d32f2f;
  --danger-dark: #b71c1c;
  --secondary-bg: #f1f3f4;
  --text: #202124;
  --text-muted: #5f6368;
  --border: #dadce0;
  --card-radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,.12);
  --shadow-hover: 0 4px 16px rgba(0,0,0,.2);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: #fff;
  overflow-x: hidden;
}

/* ── Screens ───────────────────────────────────────────────────────── */
.screen { width: 100%; min-height: 100dvh; }
.overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #fff;
  overflow-y: auto;
}

/* ── Buttons ───────────────────────────────────────────────────────── */
button { cursor: pointer; border: none; font-size: 0.95rem; border-radius: 8px; transition: background .15s, opacity .15s; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  padding: 10px 20px;
  font-weight: 600;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary {
  background: var(--secondary-bg);
  color: var(--text);
  padding: 10px 20px;
}
.btn-secondary:hover { background: var(--border); }

.btn-danger {
  background: var(--danger);
  color: #fff;
  padding: 10px 20px;
  font-weight: 600;
}
.btn-danger:hover { background: var(--danger-dark); }

.icon-btn {
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  padding: 8px 12px;
  border-radius: 6px;
}
.icon-btn:hover { background: rgba(0,0,0,.08); }

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

/* ── Inputs ────────────────────────────────────────────────────────── */
input[type="password"],
input[type="text"],
input[type="file"] {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
  background: #fff;
}
input:focus { border-color: var(--primary); }
input[type="file"] { padding: 10px; }

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  margin-top: 14px;
}

.error {
  color: var(--danger);
  font-size: 0.875rem;
  margin-top: 8px;
}

/* ── Login Screen ──────────────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--secondary-bg);
}

.login-box {
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 40px 32px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-logo { margin-bottom: 16px; }

.login-box h1 {
  font-size: 1.6rem;
  margin-bottom: 28px;
  color: var(--text);
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#login-form .btn-primary { width: 100%; padding: 12px; font-size: 1rem; }

/* ── App Header ────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 10;
}
.app-header h1 { font-size: 1.3rem; }

/* ── Sync Banner ───────────────────────────────────────────────────── */
.sync-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  background: #e8f0fe;
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 500;
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--primary);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty State ───────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}

/* ── Card Grid ─────────────────────────────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 16px;
}

.card-item {
  background: var(--secondary-bg);
  border-radius: var(--card-radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  -webkit-tap-highlight-color: transparent;
}
.card-item:hover, .card-item:active { transform: scale(0.98); box-shadow: var(--shadow-hover); }

.card-item img {
  width: 100%;
  aspect-ratio: 3/2;
  object-fit: cover;
  display: block;
}

.card-item .card-placeholder {
  width: 100%;
  aspect-ratio: 3/2;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 2rem;
}

.card-item .card-label {
  padding: 8px 10px;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

/* ── Detail Screen ─────────────────────────────────────────────────── */
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  gap: 12px;
}

.detail-actions {
  display: flex;
  gap: 8px;
}

.detail-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: calc(100dvh - 60px);
  background: #fff;
  padding-bottom: env(safe-area-inset-bottom);
}

.detail-image {
  width: 100%;
  max-height: calc(100dvh - 120px);
  object-fit: contain;
  display: block;
}

.detail-title {
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  padding: 16px 20px;
  text-align: center;
}

/* ── Modal ─────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.modal-box {
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 28px 24px calc(24px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  overflow-y: auto;
}

.modal-box h2 {
  font-size: 1.2rem;
  margin-bottom: 4px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.modal-actions button { flex: 1; }

#image-preview-wrap {
  margin-top: 12px;
  border-radius: 8px;
  overflow: hidden;
  border: 1.5px solid var(--border);
}
#image-preview {
  width: 100%;
  max-height: 200px;
  object-fit: contain;
  display: block;
}

/* ── Responsive ────────────────────────────────────────────────────── */
@media (min-width: 600px) {
  .card-grid { grid-template-columns: repeat(3, 1fr); padding: 20px; gap: 20px; }
  .modal-backdrop { align-items: center; padding: 24px; }
  .modal-box { border-radius: 16px; }
}

@media (min-width: 960px) {
  .card-grid { grid-template-columns: repeat(4, 1fr); }
  .app-header { padding: 16px 32px; }
}
