/* Mobile-first base styles */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  color: #1a1a1a;
  background: #f5f5f7;
  padding: 0;
  margin: 0;
}

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem;
}

header.app-header {
  background: #ffffff;
  border-bottom: 1px solid #e5e5ea;
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.role-badge {
  font-size: 0.65rem;
  font-weight: 700;
  color: #fff;
  background: #8e8e93;
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.role-super_admin { background: #ff3b30; }
.role-admin       { background: #ff9500; }
.role-user        { background: #007aff; }
.role-guest       { background: #34c759; }

.admin-nav {
  background: #f5f5f7;
  border-bottom: 1px solid #e5e5ea;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
}

.admin-nav .container {
  display: flex;
  gap: 0.1rem;
  align-items: center;
}

.admin-nav a {
  display: inline-block;
  font-size: 0.85rem;
  color: #007aff;
  text-decoration: none;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  font-weight: 500;
}

.admin-nav a:hover,
.admin-nav a:focus {
  background: rgba(0,122,255,0.08);
}

.admin-nav a + a::before {
  content: "";
  display: inline-block;
  width: 3px;
  height: 3px;
  background: #c7c7cc;
  border-radius: 50%;
  margin-right: 0.5rem;
  vertical-align: middle;
}

h1, h2, h3 {
  line-height: 1.25;
  margin-bottom: 0.5rem;
}

nav a {
  color: #007aff;
  text-decoration: none;
  font-size: 0.9rem;
}

nav a + a {
  margin-left: 0.75rem;
}

.card {
  background: #ffffff;
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  border: 1px solid #e5e5ea;
}

.card-title {
  font-weight: 600;
  font-size: 1.05rem;
  margin-bottom: 0.25rem;
}

.card-meta {
  font-size: 0.85rem;
  color: #666;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.5rem 1.25rem;
  border-radius: 10px;
  border: none;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: #007aff;
  color: #fff;
}

.btn-success {
  background: #34c759;
  color: #fff;
}

.btn-danger {
  background: #ff3b30;
  color: #fff;
}

.btn-secondary {
  background: #e5e5ea;
  color: #1a1a1a;
}

.btn-block {
  width: 100%;
  display: flex;
}

.btn + .btn {
  margin-top: 0.5rem;
}

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

.form-group .helper-text {
  display: block;
  font-size: 0.75rem;
  font-weight: 400;
  color: #8e8e93;
  margin-top: 0.25rem;
  line-height: 1.4;
}

.btn-sm {
  min-height: 36px;
  font-size: 0.9rem;
  padding: 0.35rem 0.75rem;
}

.admin-grid {
  display: grid;
  grid-gap: 0.75rem;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

@media (max-width: 480px) {
  .admin-grid { grid-template-columns: 1fr; }
}

/* Ensure tap targets on links inside cards are large */
.card a.btn, .card button {
  margin-top: 0.5rem;
}

label {
  display: block;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="date"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  border: 1px solid #c7c7cc;
  border-radius: 10px;
  background: #ffffff;
  -webkit-appearance: none;
  appearance: none;
}

select {
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg width='24' height='24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M7 10l5 5 5-5z' fill='%23666'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  padding-right: 2rem;
}

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

.status-badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
}

.status-pending { background: #fff3cd; color: #664d03; }
.status-done { background: #d1e7dd; color: #0f5132; }
.status-overdue { background: #f8d7da; color: #842029; }

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: #8e8e93;
}

.date-dual {
  white-space: normal;
}

.signature-canvas {
  width: 100%;
  height: 200px;
  background: #fff;
  border: 1px solid #c7c7cc;
  border-radius: 10px;
  touch-action: none;
}

/* Photo upload / gallery styles */
.photo-preview-list {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: #666;
}
.photo-preview-list .photo-thumb {
  padding: 0.25rem 0;
}
.photo-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.photo-list .photo-item {
  text-align: center;
}
.photo-list .photo-item img,
.photo-gallery img {
  width: 100%;
  max-width: 120px;
  height: auto;
  border-radius: 8px;
  object-fit: cover;
}
.photo-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.photo-gallery a {
  display: inline-block;
}

/* Mobile photo actions (gallery + camera) */
.photo-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}
.photo-actions .btn-action {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.875rem 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  border: 2px dashed #c7c7cc;
  border-radius: 12px;
  background: #fff;
  color: #007aff;
  cursor: pointer;
  text-align: center;
  min-height: 56px;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s;
}
.photo-actions .btn-action:active {
  background: #f5f5f7;
  border-color: #007aff;
}
.photo-actions input[type="file"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.photo-actions label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex: 1;
  width: 100%;
  cursor: pointer;
}

/* Camera button accent */
.photo-actions .btn-camera {
  color: #34c759;
  border-color: #c7c7cc;
}
.photo-actions .btn-camera:active {
  border-color: #34c759;
  background: #f5fff7;
}

/* Translation result inline */
.translation-result {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: #f0f9ff;
  border-left: 3px solid #007aff;
  border-radius: 8px;
}
.translation-text {
  font-size: 1rem;
  color: #1a1a1a;
  margin: 0;
}
.translation-meta {
  font-size: 0.75rem;
  color: #8e8e93;
  margin-top: 0.25rem;
  margin-bottom: 0;
}
.translation-error {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: #fff3cd;
  border-left: 3px solid #ff9500;
  border-radius: 8px;
  color: #664d03;
  font-size: 0.9rem;
}

/* Guest link cards */
.guest-link-card {
  border: 1px solid #e5e5ea;
  border-radius: 10px;
  padding: 0.75rem;
  margin-top: 0.5rem;
  background: #fafafa;
}
.guest-link-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.guest-link-meta {
  font-size: 0.8rem;
  color: #555;
  line-height: 1.4;
}
.guest-link-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.guest-link-actions form {
  flex: 1;
}
.guest-link-actions .btn {
  width: 100%;
}

.field-hint {
  display: block;
  font-size: 0.8rem;
  color: #8e8e93;
  margin-top: 0.25rem;
}

.alert {
  border-radius: 10px;
  padding: 0.75rem;
}
.alert-warning {
  background: #fff3cd;
  color: #664d03;
  border-left: 3px solid #ff9500;
}

.checkbox-group {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.checkbox-option {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: #ffffff;
  border: 1px solid #c7c7cc;
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  min-height: 44px;
  font-size: 1rem;
  cursor: pointer;
  flex: 1;
  justify-content: flex-start;
}

.checkbox-option input[type="checkbox"] {
  width: 22px;
  height: 22px;
  min-height: auto;
  accent-color: #007aff;
}

/* Desktop tweak: show standard file input as fallback when no touch */
/* We keep the buttons for all devices for consistency */

@media (max-width: 480px) {
  .container { padding: 0.75rem; }
  .card { padding: 0.875rem; }
  .photo-list { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }
  .photo-list .photo-item img,
  .photo-gallery img { max-width: 90px; }
  .photo-actions { flex-direction: row; }
  .photo-actions .btn-action { font-size: 0.95rem; padding: 0.75rem 0.25rem; }
}
