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

html { color-scheme: light; }

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #e0e7ff;
  --success: #22c55e;
  --success-light: #dcfce7;
  --error: #ef4444;
  --error-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
  --transition: 150ms ease;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Base ── */
html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ── */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header .logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}

.app-header .logo svg { color: var(--primary); }

.app-header .badge {
  font-size: 0.65rem;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 2px 7px;
  border-radius: 99px;
  letter-spacing: .04em;
}

main {
  max-width: 680px;
  margin: 2rem auto;
  padding: 0 1rem 4rem;
}

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.75rem;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-title svg { color: var(--primary); flex-shrink: 0; }

/* ── Form elements ── */
.field { margin-bottom: 1rem; }
.field:last-child { margin-bottom: 0; }

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 0.35rem;
}

label .required { color: var(--error); margin-left: 2px; }

input[type="text"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  outline: none;
}

input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}

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

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.5rem;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* ── Toggle switch ── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}

.toggle-label svg { color: var(--text-3); }

.switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; }

.switch-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 99px;
  cursor: pointer;
  transition: background var(--transition);
}

.switch input:checked ~ .switch-track { background: var(--primary); }

.switch-track::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 18px;
  height: 18px;
  background: white;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.switch input:checked ~ .switch-track::after { transform: translateX(20px); }

/* ── Drop zone ── */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  position: relative;
}

.dropzone:hover,
.dropzone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}

.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.dropzone-icon { color: var(--text-3); margin-bottom: 0.75rem; }
.dropzone-text { font-size: 0.9375rem; font-weight: 500; color: var(--text-2); }
.dropzone-hint { font-size: 0.8125rem; color: var(--text-3); margin-top: 0.25rem; }

/* ── File list ── */
.file-list { margin-top: 0.75rem; display: flex; flex-direction: column; gap: 0.5rem; }

.file-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.875rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

.file-item-icon { color: var(--primary); flex-shrink: 0; }
.file-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.file-item-size { color: var(--text-3); white-space: nowrap; font-size: 0.8125rem; }

.file-item-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-3);
  padding: 2px;
  display: flex;
  border-radius: 4px;
  flex-shrink: 0;
  transition: color var(--transition), background var(--transition);
}

.file-item-remove:hover { color: var(--error); background: var(--error-light); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: var(--font);
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
  pointer-events: none;
}

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

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1.5px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-success {
  background: var(--success);
  color: white;
}

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

.btn-full { width: 100%; }
.btn-lg { padding: 0.8rem 1.5rem; font-size: 1rem; }

/* ── Progress ── */
.progress-bar-wrap {
  background: var(--surface-2);
  border-radius: 99px;
  height: 8px;
  overflow: hidden;
  flex: 1;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  transition: width 200ms ease;
}

.progress-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.progress-label { font-size: 0.8125rem; color: var(--text-2); min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-pct { font-size: 0.8125rem; font-weight: 600; color: var(--text-2); min-width: 3rem; text-align: right; }

/* ── Alerts & status ── */
.alert {
  display: flex;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  align-items: flex-start;
}

.alert-success { background: var(--success-light); color: #166534; }
.alert-error { background: var(--error-light); color: #991b1b; }
.alert-warning { background: var(--warning-light); color: #92400e; }
.alert-info { background: var(--primary-light); color: #3730a3; }

.alert svg { flex-shrink: 0; margin-top: 1px; }

/* ── URL result box ── */
.url-box {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
}

.url-box-text {
  flex: 1;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.8125rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0.35rem 0.5rem;
  word-break: break-all;
}

/* ── Share info (download page) ── */
.share-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1rem;
}

.meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.meta-item .meta-key {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-3);
}

.meta-item .meta-value {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text);
}

/* ── Download file list ── */
.dl-file-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 0.5rem;
}

.dl-file-info { flex: 1; min-width: 0; }
.dl-file-name { font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-file-size { font-size: 0.8125rem; color: var(--text-3); margin-top: 2px; }

/* ── Expiry badge ── */
.expiry-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 99px;
}

.expiry-ok { background: var(--success-light); color: #166534; }
.expiry-soon { background: var(--warning-light); color: #92400e; }
.expiry-expired { background: var(--error-light); color: #991b1b; }

/* ── Spinner ── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255,255,255,.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
.spinner-dark {
  border-color: rgba(99,102,241,.2);
  border-top-color: var(--primary);
}

/* ── Utility ── */
.hidden { display: none !important; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.text-muted { color: var(--text-3); font-size: 0.875rem; }
.text-center { text-align: center; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

/* ── Header nav ── */
#header-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.header-link {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-2);
  text-decoration: none;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
}
.header-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.header-link.active { color: var(--primary); background: var(--primary-light); }

.header-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: 0.5rem;
  padding-left: 0.75rem;
  border-left: 1px solid var(--border);
}

.header-username {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

.role-badge {
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--primary);
  color: white;
  padding: 1px 7px;
  border-radius: 99px;
  letter-spacing: .04em;
  text-transform: uppercase;
}

/* ── Table ── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface-2); }

/* ── Share row card ── */
.share-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.share-row-info { flex: 1; min-width: 0; }
.share-row-name { font-weight: 600; font-size: .9375rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-row-meta { font-size: .8rem; color: var(--text-3); margin-top: 3px; }
.share-row-actions { display: flex; align-items: center; gap: .5rem; flex-shrink: 0; }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-3);
}
.empty-state svg { margin-bottom: .75rem; opacity: .4; }
.empty-state p { font-size: .9375rem; }

/* ── Confirm dialog ── */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 1rem;
}
.dialog-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.75rem;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}
.dialog-title { font-size: 1rem; font-weight: 700; margin-bottom: .5rem; }
.dialog-body { font-size: .9rem; color: var(--text-2); margin-bottom: 1.25rem; line-height: 1.6; }
.dialog-actions { display: flex; gap: .75rem; justify-content: flex-end; }

.btn-danger { background: var(--error); color: white; }
.btn-danger:hover { background: #dc2626; }

/* ── Footer ── */
.app-footer {
  margin-top: 3rem;
  padding: 1.25rem 1rem;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: .8125rem;
  color: var(--text-3);
}
.app-footer .footer-sep {
  margin: 0 .5rem;
  opacity: .5;
}
.app-footer .footer-version {
  font-variant-numeric: tabular-nums;
}

/* ── Dark theme ── */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --border: #475569;
  --text: #f1f5f9;
  --text-2: #94a3b8;
  --text-3: #64748b;
  --primary-light: #1e1b4b;
  --success-light: #052e16;
  --error-light: #450a0a;
  --warning-light: #431407;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.6);
}

html[data-theme="dark"] .alert-success  { color: #4ade80; }
html[data-theme="dark"] .alert-error    { color: #f87171; }
html[data-theme="dark"] .alert-warning  { color: #fbbf24; }
html[data-theme="dark"] .alert-info     { color: #a5b4fc; }
html[data-theme="dark"] .expiry-ok      { color: #4ade80; }
html[data-theme="dark"] .expiry-soon    { color: #fbbf24; }
html[data-theme="dark"] .expiry-expired { color: #f87171; }

/* Smooth transition when switching themes */
html.theme-transition *,
html.theme-transition *::before,
html.theme-transition *::after {
  transition: background-color 200ms ease, color 200ms ease, border-color 200ms ease !important;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  main { margin: 1rem auto; }
  .card { padding: 1.25rem; }
  .field-row { grid-template-columns: 1fr; }
  .share-meta { grid-template-columns: 1fr; }
}
