/* ──────────────────────────────────────────────────────────────────────────────
   Klasse 2a – Fotogalerie | Design angelehnt an Schule am Heideweg
   Primärfarbe: Grün | Akzent: Blau #2299dd
   ────────────────────────────────────────────────────────────────────────────── */

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

:root {
  --green:        #3a8535;
  --green-dark:   #2a6226;
  --green-mid:    #4ca044;
  --green-light:  #e8f4e7;
  --green-xlight: #f2f8f1;
  --blue:         #2299dd;
  --blue-dark:    #1577b0;
  --red:          #e53935;

  --bg:           #f0f5ef;
  --card:         #ffffff;
  --text:         #1e2d1f;
  --text-muted:   #5a6e5b;
  --border:       #c5d8c3;
  --border-light: #ddeadc;

  --shadow-sm:    0 1px 4px rgba(0,0,0,.07);
  --shadow:       0 2px 10px rgba(0,0,0,.09);
  --shadow-lg:    0 6px 24px rgba(0,0,0,.14);
  --radius:       12px;
  --radius-sm:    8px;
  --radius-xs:    5px;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background .18s, transform .1s, box-shadow .18s;
  white-space: nowrap;
  line-height: 1;
}
.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--green);
  color: #fff;
}
.btn-primary:hover { background: var(--green-dark); }

.btn-full { width: 100%; padding: 13px; font-size: 16px; }

.btn-outline-white {
  background: transparent;
  color: #fff;
  border: 1.5px solid rgba(255,255,255,.55);
}
.btn-outline-white:hover { background: rgba(255,255,255,.15); border-color: #fff; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 6px 10px;
  font-size: 13px;
}
.btn-ghost:hover { background: var(--border-light); }

.btn-accent {
  background: var(--blue);
  color: #fff;
  padding: 10px 20px;
}
.btn-accent:hover { background: var(--blue-dark); }

.btn-zip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--blue);
  color: #fff;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background .18s;
}
.btn-zip:hover { background: var(--blue-dark); }

/* ── Login ────────────────────────────────────────────────────────────────── */

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    linear-gradient(160deg, var(--green-dark) 0%, var(--green) 50%, var(--blue) 120%);
}

.login-card {
  background: var(--card);
  border-radius: 18px;
  padding: 44px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 64px rgba(0,0,0,.24);
}

.login-logo {
  text-align: center;
  margin-bottom: 36px;
}
.login-school-img {
  width: 120px;
  height: 72px;
  object-fit: cover;
  border-radius: 10px;
  margin-bottom: 14px;
  display: block;
  margin-left: auto;
  margin-right: auto;
}
.login-logo h1 { font-size: 26px; font-weight: 700; color: var(--green-dark); }
.login-logo p { color: var(--text-muted); font-size: 14px; margin-top: 2px; }
.login-subtitle { font-size: 13px; color: var(--border); margin-top: 6px; letter-spacing: .06em; text-transform: uppercase; }

.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-weight: 500; font-size: 14px; margin-bottom: 7px; }

.password-wrapper { position: relative; }
.password-wrapper input { padding-right: 44px; }

.toggle-pw {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  padding: 4px;
  opacity: .6;
  transition: opacity .15s;
}
.toggle-pw:hover { opacity: 1; }

input[type="password"],
input[type="text"] {
  width: 100%;
  padding: 11px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: var(--font);
  transition: border-color .2s, box-shadow .2s;
  outline: none;
  color: var(--text);
}
input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(58,133,53,.14);
}

.btn-text, .btn-spinner { transition: opacity .15s; }

.error-message {
  color: var(--red);
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
  min-height: 20px;
}

/* ── Header ───────────────────────────────────────────────────────────────── */

header {
  background: linear-gradient(135deg, var(--green-dark) 0%, var(--green) 100%);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: 0 2px 12px rgba(0,0,0,.18);
}
.header-content {
  max-width: 1280px;
  margin: 0 auto;
  padding: 13px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.logo-img {
  height: 44px;
  width: 44px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}
.header-titles h1 { font-size: 19px; font-weight: 700; line-height: 1.2; }
.header-titles span { font-size: 12px; opacity: .82; }
.header-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }

.role-badge {
  background: rgba(255,255,255,.2);
  color: #fff;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

/* ── Main / Cards ─────────────────────────────────────────────────────────── */

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-light);
  gap: 12px;
}
.card-header h2 {
  font-size: 17px;
  font-weight: 600;
  color: var(--green-dark);
}
.total-count { font-size: 13px; color: var(--text-muted); }

/* ── Upload Card ──────────────────────────────────────────────────────────── */

.upload-card .card-header { background: var(--green-xlight); }

#upload-body { padding: 20px 22px; }

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s, transform .15s;
  outline: none;
}
.drop-zone:hover,
.drop-zone:focus {
  border-color: var(--green);
  background: var(--green-light);
}
.drop-zone.drag-over {
  border-color: var(--green);
  background: var(--green-light);
  transform: scale(1.01);
  box-shadow: 0 0 0 4px rgba(58,133,53,.12);
}
.drop-icon { font-size: 50px; margin-bottom: 14px; }
.drop-main { font-size: 16px; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.drop-hint { font-size: 13px; color: var(--text-muted); }

.upload-progress { margin-top: 16px; }
.progress-track {
  background: var(--border-light);
  border-radius: 6px;
  height: 8px;
  overflow: hidden;
  margin-bottom: 10px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--blue));
  border-radius: 6px;
  width: 0;
  transition: width .3s ease;
}
.progress-text {
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
}

/* ── Gallery ──────────────────────────────────────────────────────────────── */

.gallery-card { padding: 0; }
.gallery-card .card-header { padding: 18px 22px 16px; }

#gallery { padding: 0 22px 22px; }

.gallery-loading {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.gallery-loading p { margin-top: 14px; font-size: 15px; }

.gallery-empty {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}
.empty-icon { font-size: 44px; margin-bottom: 14px; }
.gallery-empty p { font-size: 15px; margin-bottom: 4px; }
.empty-hint { font-size: 13px; }

/* ── Date Sections ────────────────────────────────────────────────────────── */

.date-section {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 12px;
  position: relative;
}
.date-section:last-child { margin-bottom: 0; }

.date-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--green-xlight);
  cursor: pointer;
  user-select: none;
  transition: background .15s;
  gap: 12px;
  flex-wrap: wrap;
}
.date-header:hover { background: var(--green-light); }
.date-header.open { border-bottom: 1px solid var(--border-light); }

.date-header-left {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.date-title-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.date-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.event-label-input {
  font-size: 13px;
  font-family: var(--font);
  color: var(--text);
  border: none;
  border-bottom: 1.5px dashed var(--border);
  background: transparent;
  outline: none;
  padding: 2px 2px;
  width: 260px;
  max-width: 100%;
  transition: border-color .18s;
}
.event-label-input:focus { border-bottom-color: var(--green); }
.event-label-input::placeholder { color: var(--border); font-style: italic; }

.event-label-text {
  font-size: 13px;
  color: var(--green-dark);
  font-style: italic;
}

.chevron {
  display: inline-block;
  color: var(--green);
  font-size: 11px;
  transition: transform .2s;
  flex-shrink: 0;
}
.date-header.open .chevron { transform: rotate(90deg); }

.date-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--green-dark);
}
.photo-count {
  background: var(--green-light);
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.date-content {
  display: none;
  padding: 18px;
  background: #fff;
}
.date-content.open { display: block; }

/* ── Image Grid ───────────────────────────────────────────────────────────── */

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.image-card {
  background: #fff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: box-shadow .2s, transform .2s;
  display: flex;
  flex-direction: column;
}
.image-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-3px);
}

.image-thumb-wrap {
  position: relative;
  overflow: hidden;
  background: var(--bg);
}
.image-thumb-wrap::after {
  content: '';
  display: block;
  padding-top: 75%; /* 4:3 ratio */
}
.image-thumb-wrap img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
  transition: opacity .2s, transform .3s;
}
.image-thumb-wrap img:hover { opacity: .9; transform: scale(1.04); }

.btn-delete-img {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(229,57,53,.85);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .2s, background .18s;
  z-index: 2;
  line-height: 1;
}
.image-card:hover .btn-delete-img { opacity: 1; }
.btn-delete-img:hover { background: rgba(183,28,28,.95); }

/* Touch devices: no hover → always show delete button */
@media (hover: none) {
  .btn-delete-img { opacity: 1; }
}

.delete-confirm-overlay {
  position: absolute;
  inset: 0;
  background: rgba(183,28,28,.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  z-index: 3;
}
.delete-confirm-overlay p {
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}
.delete-confirm-btns { display: flex; gap: 8px; }
.btn-confirm-yes {
  background: #fff;
  color: var(--red);
  border: none;
  padding: 6px 14px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-confirm-yes:hover { background: #f5f5f5; }
.btn-confirm-no {
  background: transparent;
  color: #fff;
  border: 1.5px solid rgba(255,255,255,.7);
  padding: 6px 14px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-confirm-no:hover { background: rgba(255,255,255,.15); }

.image-comment-area {
  padding: 10px 12px 12px;
  flex: 1;
}

.comment-textarea {
  width: 100%;
  min-height: 56px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 7px 9px;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  resize: vertical;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
  background: var(--bg);
  line-height: 1.45;
}
.comment-textarea:focus {
  border-color: var(--green);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(58,133,53,.1);
}
.comment-textarea::placeholder { color: var(--text-muted); font-style: italic; }

.comment-saved-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green-mid);
  margin-left: 6px;
  opacity: 0;
  transition: opacity .3s;
}
.comment-saved-dot.visible { opacity: 1; }

.comment-text-display {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.45;
  padding: 2px 0;
}

/* ── Viewer Modal ─────────────────────────────────────────────────────────── */

.viewer-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.93);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.viewer-btn {
  background: rgba(255,255,255,.12);
  color: #fff;
  border: none;
  cursor: pointer;
  transition: background .18s;
  font-family: var(--font);
  outline: none;
}
.viewer-btn:hover { background: rgba(255,255,255,.28); }
.viewer-btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.viewer-close-btn {
  position: absolute;
  top: 14px;
  right: 18px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 17px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 54px;
  height: 54px;
  border-radius: 50%;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}
.viewer-nav span { font-size: 36px; line-height: 1; }
.viewer-nav:disabled { opacity: .2; cursor: not-allowed; }
.viewer-nav:disabled:hover { background: rgba(255,255,255,.12); }
.viewer-prev-btn { left: 18px; }
.viewer-next-btn { right: 18px; }

.viewer-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 80px 12px;
  overflow: hidden;
  position: relative;
}

.viewer-img-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
}
#viewer-image {
  max-width: 100%;
  max-height: calc(100vh - 180px);
  object-fit: contain;
  border-radius: var(--radius-xs);
  display: block;
  transition: opacity .2s;
}
#viewer-image.loading { opacity: 0; }

.viewer-img-loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewer-bar {
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.viewer-bar-left {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
}
.viewer-counter { font-size: 12px; color: rgba(255,255,255,.55); }
.viewer-date { font-size: 15px; font-weight: 500; color: #fff; }
.viewer-comment-text {
  font-size: 13px;
  color: rgba(255,255,255,.75);
  font-style: italic;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Spinner ──────────────────────────────────────────────────────────────── */

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.spinner-white {
  border-color: rgba(255,255,255,.2);
  border-top-color: rgba(255,255,255,.85);
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ────────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--green-dark);
  color: #fff;
  padding: 10px 22px;
  border-radius: 22px;
  font-size: 14px;
  z-index: 9999;
  pointer-events: none;
  transition: transform .3s cubic-bezier(.34,1.56,.64,1);
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ── Create Folder Card ───────────────────────────────────────────────────── */

.create-folder-card .card-header { background: var(--green-xlight); }

#create-folder-body { padding: 20px 22px; }

.create-folder-fields {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.create-folder-fields .form-group {
  flex: 1;
  min-width: 180px;
  margin-bottom: 0;
}
.create-folder-fields .btn {
  flex-shrink: 0;
  align-self: flex-end;
  margin-bottom: 0;
}

input[type="date"] {
  width: 100%;
  padding: 11px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: var(--font);
  transition: border-color .2s, box-shadow .2s;
  outline: none;
  color: var(--text);
}
input[type="date"]:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(58,133,53,.14);
}

/* ── Folder Delete Button & Overlay ──────────────────────────────────────── */

.btn-delete-folder {
  background: transparent;
  color: rgba(255,255,255,.75);
  border: 1.5px solid rgba(255,255,255,.4);
  padding: 5px 10px;
  border-radius: var(--radius-xs);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background .18s, color .18s, border-color .18s;
  white-space: nowrap;
  font-family: var(--font);
}
.btn-delete-folder:hover {
  background: rgba(229,57,53,.85);
  color: #fff;
  border-color: transparent;
}

.folder-delete-overlay {
  position: absolute;
  inset: 0;
  background: rgba(183,28,28,.93);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: var(--radius-sm);
}
.folder-delete-dialog {
  text-align: center;
  color: #fff;
  padding: 20px 28px;
}
.folder-delete-dialog p { font-size: 14px; margin-bottom: 6px; }
.folder-delete-dialog strong { font-weight: 700; }
.folder-delete-warning { font-size: 12px; opacity: .8; margin-bottom: 14px !important; }

/* ── Per-Folder Upload Zone ───────────────────────────────────────────────── */

.folder-upload-zone-wrapper {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px dashed var(--border-light);
}

.drop-zone-inline {
  padding: 28px 20px;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .image-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }
}

@media (max-width: 640px) {
  main { padding: 14px; gap: 14px; }
  .header-content { padding: 11px 16px; }
  .logo-img { height: 36px; width: 36px; }
  .header-titles h1 { font-size: 17px; }
  .role-badge { display: none; }
  .create-folder-fields { flex-direction: column; }
  .create-folder-fields .form-group { min-width: 0; }
  .btn-delete-folder { font-size: 11px; padding: 4px 8px; }

  .card-header { padding: 14px 16px; }
  #create-folder-body { padding: 14px 16px; }
  #gallery { padding: 0 16px 16px; }

  .date-header { padding: 12px 14px; }
  .date-header-right { width: 100%; }
  .btn-zip { width: 100%; justify-content: center; }

  .date-content { padding: 12px; }
  .image-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }

  .viewer-stage { padding: 50px 50px 10px; }
  .viewer-prev-btn { left: 8px; }
  .viewer-next-btn { right: 8px; }
  .viewer-nav { width: 42px; height: 42px; }
  .viewer-nav span { font-size: 28px; }
  .viewer-bar { padding: 12px 16px; }
  .viewer-bar-right .btn-accent { font-size: 13px; padding: 9px 14px; }
}

@media (max-width: 380px) {
  .login-card { padding: 32px 24px; }
  .image-grid { grid-template-columns: repeat(2, 1fr); }
}
