:root {
  --bg: #f8f8f8;
  --surface: #ffffff;
  --text: #000000;
  --muted: #666666;
  --border: #000000;
  --border-subtle: #e0e0e0;
  --danger: #d93025;
}

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

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

/* ===========================
   HEADER (Matches Reference)
   =========================== */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
  flex-wrap: wrap;
  gap: 16px;
}

.logo {
  font-family: 'Barriecito', cursive;
  font-size: 2.1rem;
  font-weight: 400;
  color: #000000;
  cursor: pointer;
  user-select: none;
  letter-spacing: 0.5px;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Circular Icon Buttons */
.icon-circle-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1.2px solid var(--border);
  background: transparent;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
  text-decoration: none;
}

.icon-circle-btn:hover {
  background: var(--text);
  color: var(--surface);
}

/* Expandable Search Bar */
.search-wrapper {
  display: flex;
  align-items: center;
  height: 34px;
  width: 34px;
  border-radius: 999px;
  border: 1.2px solid var(--border);
  background: transparent;
  overflow: hidden;
  transition: width 0.28s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.2s ease;
}

.search-wrapper.expanded {
  width: 250px;
  background: var(--surface);
  padding-right: 8px;
}

.search-trigger {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.search-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-size: 0.82rem;
  font-family: inherit;
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.search-wrapper.expanded .search-input {
  opacity: 1;
  pointer-events: auto;
}

.search-clear {
  border: none;
  background: transparent;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0 2px;
}

/* Category Filter Pill */
.category-pill {
  display: inline-flex;
  align-items: center;
  border: 1.2px solid var(--border);
  border-radius: 999px;
  padding: 3px 5px;
  gap: 2px;
}

.pill-tab {
  border: 1.2px solid transparent;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.78rem;
  padding: 4px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pill-tab.active {
  border-color: var(--border);
  font-weight: 500;
}

.pill-tab:hover:not(.active) {
  background: rgba(0, 0, 0, 0.05);
}

/* ===========================
   TRASH BANNER
   =========================== */
.trash-banner {
  margin: 0 32px 16px;
  padding: 12px 18px;
  border: 1.2px solid var(--border);
  border-radius: 12px;
  background: #fff8f6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.88rem;
}

/* ===========================
   CARDS GRID LAYOUT
   =========================== */
.main-container {
  padding: 12px 32px 48px;
}

.materials-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.material-card {
  background: var(--surface);
  border: 1.2px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.material-card:hover {
  transform: translateY(-2px);
  box-shadow: 4px 4px 0px var(--border);
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  font-size: 0.72rem;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-weight: 500;
}

.badge-subject {
  background: var(--text);
  color: var(--surface);
}

.badge-grade {
  background: #f0f0f0;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.35;
  margin-top: 10px;
  word-break: break-word;
}

.card-filename {
  font-size: 0.76rem;
  color: var(--muted);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border-subtle);
  padding-top: 12px;
  font-size: 0.75rem;
  color: var(--muted);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--muted);
  font-size: 0.95rem;
}

/* ===========================
   MODALS
   =========================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 900;
}

.modal-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 6px 6px 0px var(--border);
}

.modal-sm {
  max-width: 400px;
}

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

.modal-tabs {
  display: flex;
  gap: 8px;
}

.modal-tab {
  border: 1.2px solid transparent;
  background: transparent;
  padding: 5px 12px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

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

.modal-title {
  font-size: 1rem;
  font-weight: 600;
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-group input[type="text"],
.form-group select,
.file-input {
  padding: 9px 12px;
  border: 1.2px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.88rem;
  background: var(--surface);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.btn-primary,
.btn-outline,
.btn-outline-sm,
.btn-danger-sm {
  border: 1.2px solid var(--border);
  border-radius: 999px;
  padding: 8px 18px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

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

.btn-outline {
  background: var(--surface);
  color: var(--text);
}

.btn-outline-sm,
.btn-danger-sm {
  padding: 5px 12px;
  font-size: 0.76rem;
  background: var(--surface);
}

.btn-danger-sm {
  border-color: var(--danger);
  color: var(--danger);
}

/* Manage List inside Edit Modal */
.manage-hint {
  font-size: 0.82rem;
  color: var(--muted);
}

.manage-files-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.manage-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.manage-item-input {
  flex: 1;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 0.85rem;
}

/* ===========================
   FULLSCREEN VIEWER
   =========================== */
.fullscreen-viewer {
  position: fixed;
  inset: 0;
  background: var(--surface);
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1.2px solid var(--border);
  gap: 16px;
}

.viewer-back-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1.2px solid var(--border);
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.viewer-back-btn:hover {
  background: var(--text);
  color: var(--surface);
}

.viewer-meta {
  flex: 1;
  min-width: 0;
}

.viewer-title {
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viewer-subtitle {
  font-size: 0.78rem;
  color: var(--muted);
}

.viewer-content {
  flex: 1;
  background: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}

.viewer-content iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.viewer-content img {
  max-width: 95%;
  max-height: 92%;
  object-fit: contain;
}

.viewer-fallback {
  background: var(--surface);
  border: 1.2px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  text-align: center;
  max-width: 420px;
}