:root {
  --bg: #f7f8fb;
  --card: #ffffff;
  --muted: #666;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --border: #e6e9ef;
  --text: #111;
  --text-light: #4b5563;
  --success: #16a34a;
  --warning: #ea580c;
}

* {
  box-sizing: border-box;
}

body {
  font-family: Inter, system-ui, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  line-height: 1.6;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* Header */
.site-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  position: sticky;
  top: 0;
  z-index: 100;
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
}

.brand {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
}

.brand a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s;
}

.brand a:hover {
  color: var(--accent-hover);
}

.nav {
  display: flex;
  gap: 8px;
}

.nav a {
  color: var(--text-light);
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 6px;
  transition: all 0.2s;
  font-weight: 500;
}

.nav a:hover {
  background: #f3f4f6;
  color: var(--accent);
}

/* Main Content */
main.container {
  padding-top: 32px;
  padding-bottom: 48px;
}

h2 {
  font-size: 32px;
  font-weight: 700;
  margin: 0 0 24px 0;
  color: var(--text);
}

h3 {
  font-size: 20px;
  font-weight: 600;
  margin: 24px 0 16px 0;
  color: var(--text);
}

p {
  margin: 12px 0;
  color: var(--text-light);
}

/* Cards */
.card {
  background: var(--card);
  padding: 24px;
  border-radius: 12px;
  margin: 16px 0;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.card-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 12px 0;
  color: var(--text);
}

/* Buttons */
.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  display: inline-block;
  text-decoration: none;
  line-height: 1.4;
}

.btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(37, 99, 235, 0.2);
}

.btn:active {
  transform: translateY(0);
}

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

.btn.ghost:hover {
  background: #f0f5ff;
  border-color: var(--accent);
  box-shadow: none;
}

.btn.small {
  padding: 6px 12px;
  font-size: 13px;
}

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

.btn.danger:hover {
  background: var(--danger-hover);
  box-shadow: 0 4px 8px rgba(220, 38, 38, 0.2);
}

/* Actions Bar */
.actions {
  margin-bottom: 20px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* Tables */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  margin-top: 16px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.table th,
.table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid #f3f4f6;
}

.table th {
  background: #f9fafb;
  font-weight: 600;
  color: var(--text);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover {
  background: #fafbfc;
}

.table td form {
  display: inline;
  margin-left: 8px;
}

.table td form:first-child {
  margin-left: 0;
}

/* Forms */
.form {
  max-width: 640px;
}

.form label {
  display: block;
  margin-bottom: 16px;
  font-weight: 500;
  color: var(--text);
  font-size: 14px;
}

.form input[type="checkbox"] {
  width: auto;
  margin-right: 6px;
  cursor: pointer;
}

.form-input,
input[type="text"],
input[type="password"],
input[type="file"],
textarea,
select {
  padding: 10px 12px;
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  transition: all 0.2s;
  background: var(--card);
  font-family: inherit;
}

.form-input:focus,
input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

select.form-input {
  cursor: pointer;
}

/* Links */
.link {
  color: var(--accent);
  text-decoration: none;
  margin-right: 8px;
  font-weight: 500;
  transition: color 0.2s;
}

.link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

a {
  color: var(--accent);
  transition: color 0.2s;
}

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

/* Alerts */
.alert {
  background: #fef2f2;
  padding: 12px 16px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  margin-bottom: 16px;
  color: var(--danger);
  font-size: 14px;
}

/* Progress Bar */
.progress {
  background: #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
  height: 16px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.progress > div {
  height: 100%;
  background: linear-gradient(90deg, var(--accent) 0%, #3b82f6 100%);
  width: 0;
  transition: width 0.3s ease;
  box-shadow: 0 0 8px rgba(37, 99, 235, 0.4);
}

/* Preview */
.preview {
  margin-top: 20px;
  padding: 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.preview img,
.preview video,
.preview iframe {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

/* Upload Grid */
.upload-grid {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 20px;
  align-items: start;
}

.upload-left,
.upload-right {
  min-width: 0;
}

/* Utility Classes */
.muted {
  color: var(--muted);
  font-size: 14px;
}

/* File Tree & S3 Browser */
#s3Breadcrumbs,
#s3UploadBreadcrumbs {
  font-size: 14px;
  padding: 8px 0;
}

#s3Breadcrumbs a,
#s3UploadBreadcrumbs a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

#s3Breadcrumbs a:hover,
#s3UploadBreadcrumbs a:hover {
  text-decoration: underline;
}

#uploadStatus {
  background: #f9fafb;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

#uploadPercent {
  text-align: center;
  font-weight: 500;
  margin-top: 8px;
}

/* Tab Buttons */
#tabCached,
#tabS3 {
  transition: all 0.2s;
}

/* Status Messages */
#s3Message,
#status {
  font-size: 14px;
  color: var(--text-light);
  font-weight: 500;
}

/* Quick Stats */
.card p {
  color: var(--text-light);
  font-size: 15px;
  margin: 8px 0;
}

.card p:first-of-type {
  margin-top: 0;
}

/* User Permissions Checkboxes */
.form label:has(input[type="checkbox"]) {
  display: inline-flex;
  align-items: center;
  margin-right: 12px;
  margin-bottom: 8px;
  font-weight: 400;
  cursor: pointer;
}

/* Table inline forms for user management */
.table td label {
  display: inline-flex;
  align-items: center;
  margin-right: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-light);
}

.table td label input[type="checkbox"] {
  margin-right: 2px;
}

/* Welcome Page */
main.container > p {
  font-size: 16px;
  line-height: 1.7;
}

/* Responsive Design */
@media (max-width: 900px) {
  .upload-grid {
    grid-template-columns: 1fr;
  }

  .site-header .container {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  .nav {
    width: 100%;
  }

  .nav a {
    flex: 1;
    text-align: center;
  }

  h2 {
    font-size: 28px;
  }

  .container {
    padding: 16px;
  }
}

@media (max-width: 600px) {
  .actions {
    flex-direction: column;
    align-items: stretch;
  }

  .actions .btn,
  .actions form {
    width: 100%;
  }

  .actions form button {
    width: 100%;
  }

  .table {
    font-size: 13px;
  }

  .table th,
  .table td {
    padding: 8px 10px;
  }
}

/* Loading States */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.loading {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Focus Styles for Accessibility */
.btn:focus-visible,
.link:focus-visible,
.nav a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Smooth Scrolling */
html {
  scroll-behavior: smooth;
}

/* Empty State */
.table tbody:empty::after {
  content: "No items to display";
  display: block;
  text-align: center;
  padding: 32px;
  color: var(--muted);
  font-style: italic;
}