/* MyAlbums Design System — 共用基準樣式（FSD 4.4） */

:root {
  --bg: #F5F5F7;
  --surface: #FFFFFF;
  --surface-2: #FAFAFA;
  --border: #E5E5EA;
  --text-primary: #1D1D1F;
  --text-secondary: #6E6E73;
  --accent: #0A84FF;
  --accent-contrast: #FFFFFF;
  --danger: #FF3B30;
  --warning: #FF9F0A;
  --success: #34C759;
  --radius-card: 10px;
  --radius-btn: 6px;
  --radius-modal: 14px;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, .06);
  --shadow-modal: 0 8px 30px rgba(0, 0, 0, .20);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1C1C1E;
    --surface: #2C2C2E;
    --surface-2: #242426;
    --border: #3A3A3C;
    --text-primary: #F5F5F7;
    --text-secondary: #ADADB2;
    --accent: #409CFF;
    --danger: #FF453A;
    --warning: #FFB340;
    --success: #32D74B;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-modal: 0 8px 30px rgba(0, 0, 0, .5);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: -apple-system, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 13px;
  line-height: 18px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.title {
  font-size: 20px;
  line-height: 28px;
  font-weight: 600;
}

.subtitle {
  font-size: 15px;
  line-height: 20px;
  font-weight: 600;
}

.caption {
  font-size: 11px;
  line-height: 14px;
  color: var(--text-secondary);
}

a {
  color: var(--accent);
}

/* ---------- Buttons ---------- */

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-btn);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  transition: opacity .15s ease, background-color .15s ease;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: .5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
}

.btn-secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text-primary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-primary);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

/* ---------- Spinner ---------- */

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .5);
  border-top-color: #fff;
  animation: spin .7s linear infinite;
  flex: none;
}

.spinner-dark {
  border-color: rgba(0, 0, 0, .15);
  border-top-color: var(--accent);
}

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

/* ---------- Forms ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
}

.field input[type="text"],
.field input[type="password"],
.field textarea {
  font-family: inherit;
  font-size: 13px;
  padding: 10px 12px;
  border-radius: var(--radius-btn);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(10, 132, 255, .15);
}

.field-error {
  color: var(--danger);
  font-size: 12px;
}

/* ---------- Login page ---------- */

.login-shell {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  width: 360px;
  max-width: 100%;
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 32px;
  text-align: center;
}

.login-card .title {
  margin-bottom: 4px;
}

.login-card .subtitle {
  font-weight: 400;
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 24px;
}

.login-card form {
  text-align: left;
}

.error-banner {
  background: rgba(255, 59, 48, .1);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius-btn);
  padding: 10px 12px;
  font-size: 12px;
  margin-top: 12px;
  text-align: left;
}

@media (max-width: 600px) {
  .login-card {
    width: calc(100% - 32px);
  }
}

/* ---------- App shell ---------- */

.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 240px;
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  flex: 1;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-btn);
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-family: inherit;
  color: var(--text-primary);
}

.sidebar-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.sidebar-item.is-active {
  background: var(--accent);
  color: #fff;
}

.sidebar-item.is-active .sidebar-item-count {
  color: rgba(255, 255, 255, .8);
}

.sidebar-item-thumb {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: var(--surface-2);
  object-fit: cover;
  flex: none;
}

.sidebar-item-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-item-count {
  font-size: 11px;
  color: var(--text-secondary);
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  gap: 12px;
}

.toolbar-title {
  min-width: 0;
}

.toolbar-title .title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.content-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ---------- PhotoGrid ---------- */

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.photo-card {
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-card);
  overflow: hidden;
  background: var(--surface-2);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  border: none;
  padding: 0;
  position: relative;
}

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

.grid-loadmore {
  display: flex;
  justify-content: center;
  padding: 16px 0;
}

/* ---------- Skeleton ---------- */

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: skeleton-loading 1.4s ease infinite;
  border-radius: var(--radius-card);
}

@keyframes skeleton-loading {
  0% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0 50%;
  }
}

.skeleton-row {
  height: 44px;
  margin: 0 0 8px;
}

.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.skeleton-card {
  aspect-ratio: 1 / 1;
}

/* ---------- Empty / Error state ---------- */

.state-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  padding: 48px 16px;
  color: var(--text-secondary);
}

.state-block .state-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--border);
}

.state-block.state-error .state-icon {
  border-color: var(--danger);
}

.state-block p {
  max-width: 320px;
}

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  width: 480px;
  max-width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius-modal);
  box-shadow: var(--shadow-modal);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

.modal-close {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 18px;
  line-height: 1;
  padding: 4px;
}

@media (max-width: 600px) {
  .modal {
    width: calc(100% - 32px);
  }
}

/* ---------- Upload list ---------- */

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-card);
  padding: 32px 16px;
  text-align: center;
  color: var(--text-secondary);
  cursor: pointer;
}

.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--accent);
  color: var(--accent);
}

.upload-list {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.upload-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
}

.upload-item-thumb {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--surface-2);
  flex: none;
}

.upload-item-info {
  flex: 1;
  min-width: 0;
}

.upload-item-name {
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-item-meta {
  font-size: 11px;
  color: var(--text-secondary);
}

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  flex: none;
}

.badge-waiting {
  background: var(--surface-2);
  color: var(--text-secondary);
}

.badge-resizing,
.badge-uploading {
  background: rgba(10, 132, 255, .12);
  color: var(--accent);
}

.badge-success {
  background: rgba(52, 199, 89, .15);
  color: var(--success);
}

.badge-error {
  background: rgba(255, 59, 48, .15);
  color: var(--danger);
}

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width .2s ease;
}

.upload-summary {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}

/* ---------- Toast ---------- */

.toast-region {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.toast {
  background: var(--surface);
  color: var(--text-primary);
  border-radius: var(--radius-btn);
  box-shadow: var(--shadow-modal);
  padding: 10px 14px;
  font-size: 13px;
  border-left: 3px solid var(--accent);
  min-width: 200px;
  max-width: 320px;
}

.toast-success {
  border-left-color: var(--success);
}

.toast-error {
  border-left-color: var(--danger);
}

/* ---------- Lightbox ---------- */

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  flex-direction: column;
  z-index: 150;
}

.lightbox-overlay[hidden] {
  display: none;
}

.lightbox-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  color: #fff;
  background: rgba(0, 0, 0, .4);
}

.lightbox-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 0;
}

.lightbox-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, .4);
  color: #fff;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
}

.lightbox-nav.prev {
  left: 16px;
}

.lightbox-nav.next {
  right: 16px;
}

.lightbox-caption {
  position: absolute;
  left: 16px;
  bottom: 16px;
  color: rgba(255, 255, 255, .7);
  font-size: 11px;
}

.lightbox-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 12px;
  background: rgba(0, 0, 0, .4);
}

.lightbox-btn {
  background: rgba(255, 255, 255, .12);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  cursor: pointer;
  font-size: 16px;
}

.lightbox-btn:focus-visible {
  outline: 2px solid #fff;
}

.lightbox-topbar,
.lightbox-controls {
  transition: opacity .3s ease;
}

.lightbox-overlay.is-idle .lightbox-topbar,
.lightbox-overlay.is-idle .lightbox-controls {
  opacity: 0;
  pointer-events: none;
}

/* ---------- Sidebar drawer (tablet/mobile) ---------- */

.sidebar-toggle {
  display: none;
}

@media (max-width: 1024px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 90;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow-modal);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: inline-flex;
  }
}

@media (max-width: 600px) {
  .toolbar {
    padding: 12px 16px;
  }

  .content-scroll {
    padding: 16px;
  }

  .photo-grid,
  .skeleton-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
