/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg: #f5f5f7;
  --color-surface: #ffffff;
  --color-primary: #007aff;
  --color-primary-hover: #0056cc;
  --color-danger: #ff3b30;
  --color-danger-hover: #cc2f26;
  --color-success: #34c759;
  --color-text: #1d1d1f;
  --color-text-secondary: #86868b;
  --color-border: #d2d2d7;
  --color-border-light: #e5e5ea;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --max-width: 960px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* === Typography === */
h1 { font-size: 1.5rem; font-weight: 600; }
h2 { font-size: 1.25rem; font-weight: 600; }

/* === Layout === */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 16px;
}

/* === Login === */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}

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

.login-card h1 {
  text-align: center;
  margin-bottom: 24px;
}

/* === Forms === */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--color-primary);
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  min-height: 44px;
  gap: 6px;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  width: 100%;
}

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

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

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

.btn-outline {
  background: transparent;
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
}

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

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8125rem;
  min-height: 36px;
}

.btn-block { width: 100%; }

/* === Header === */
.header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border-light);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-title {
  font-weight: 600;
  font-size: 1.0625rem;
}

/* === Tabs === */
.tabs {
  display: flex;
  gap: 0;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border-light);
  padding: 0 16px;
}

.tab {
  padding: 12px 16px;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  min-height: 44px;
  display: flex;
  align-items: center;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}

.tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

/* === Cards === */
.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

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

.card-title {
  font-weight: 600;
  font-size: 1rem;
  word-break: break-word;
}

.card-meta {
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
  margin-bottom: 12px;
}

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

/* === Folders Grid === */
.folders-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 640px) {
  .folders-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 900px) {
  .folders-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* === Share List === */
.share-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border-light);
}

.share-item:last-child {
  border-bottom: none;
}

.share-link {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 0.8125rem;
  color: var(--color-primary);
  word-break: break-all;
  cursor: pointer;
  padding: 4px 0;
}

.share-stats {
  display: flex;
  gap: 16px;
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
}

/* === Badge === */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-active {
  background: #e8f8ed;
  color: var(--color-success);
}

.badge-revoked {
  background: #ffe5e3;
  color: var(--color-danger);
}

/* === Upload Area === */
.upload-area {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s;
  margin-bottom: 12px;
}

.upload-area:hover,
.upload-area.dragover {
  border-color: var(--color-primary);
}

.upload-area input[type="file"] {
  display: none;
}

.upload-area p {
  color: var(--color-text-secondary);
  font-size: 0.875rem;
}

/* === File List === */
.file-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.file-item {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 1;
  background: var(--color-bg);
}

.file-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-item .file-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 4px 6px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 0.6875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* === Share Page (public) === */
.share-page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 16px;
}

.share-page h1 {
  margin-bottom: 16px;
}

.share-page .download-btn {
  margin-bottom: 24px;
}

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

.image-grid .image-item {
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 1;
  cursor: pointer;
  background: var(--color-bg);
}

.image-grid .image-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* === Lightbox === */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.lightbox.active {
  display: flex;
}

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

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  background: none;
  border: none;
  padding: 8px;
  min-height: 44px;
  min-width: 44px;
}

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

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

.modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 400px;
}

.modal h2 {
  margin-bottom: 16px;
}

.modal .form-group:last-of-type {
  margin-bottom: 24px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* === Toast === */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text);
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.875rem;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
}

/* === Error message === */
.error-msg {
  color: var(--color-danger);
  font-size: 0.875rem;
  margin-top: 8px;
  text-align: center;
}

/* === Empty state === */
.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--color-text-secondary);
}

.empty-state p {
  font-size: 0.9375rem;
}

/* === Section header === */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

/* === Create folder inline === */
.create-folder-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.create-folder-row input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
}

.create-folder-row input:focus {
  border-color: var(--color-primary);
}

/* === Progress === */
.progress-bar {
  width: 100%;
  height: 4px;
  background: var(--color-border-light);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
  display: none;
}

.progress-bar.active {
  display: block;
}

.progress-bar .progress-fill {
  height: 100%;
  background: var(--color-primary);
  width: 0%;
  transition: width 0.2s;
}

/* === Loading spinner === */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

.loading {
  text-align: center;
  padding: 40px;
}
