/* ── EasyFile Component Library ── */
/* Classes from SKILL 2.md Layer 2 */

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-family: var(--ef-font);
  font-size: var(--ef-text-14);
  line-height: 1.5;
  color: var(--ef-text);
  background: var(--ef-bg);
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }

a { color: var(--ef-color-primary); text-decoration: none; }
a:hover { color: var(--ef-color-primary-hover); text-decoration: underline; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--ef-space-8);
  border: none;
  border-radius: var(--ef-radius-6);
  font-family: var(--ef-font);
  font-weight: 500;
  cursor: pointer;
  transition: all 150ms;
  text-decoration: none;
  line-height: 1;
}
.btn:focus-visible {
  outline: 2px solid var(--ef-color-focus);
  outline-offset: 2px;
}
.btn:disabled, .btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn svg { width: 15px; height: 15px; stroke-width: 2; }

/* Variants */
.btn-primary { background: var(--ef-color-primary); color: #fff; }
.btn-primary:hover { background: var(--ef-color-primary-hover); color: #fff; text-decoration: none; }

.btn-secondary { background: var(--ef-surface); color: var(--ef-text); border: 1px solid var(--ef-border); }
.btn-secondary:hover { background: var(--ef-surface-2); text-decoration: none; }

.btn-ghost { background: transparent; color: var(--ef-text-muted); }
.btn-ghost:hover { background: var(--ef-surface-2); color: var(--ef-text); text-decoration: none; }

.btn-danger { background: var(--ef-color-danger); color: #fff; }
.btn-danger:hover { background: var(--ef-color-danger-hover); color: #fff; text-decoration: none; }

.btn-icon {
  background: transparent;
  color: var(--ef-text-muted);
  width: 34px;
  height: 34px;
  padding: 0;
}
.btn-icon:hover { background: var(--ef-surface-2); color: var(--ef-text); }

/* Sizes */
.btn-sm { height: 28px; padding: 0 var(--ef-space-8); font-size: var(--ef-text-12); }
.btn-md { height: 34px; padding: 0 var(--ef-space-12); font-size: var(--ef-text-13); }
.btn-lg { height: 42px; padding: 0 var(--ef-space-16); font-size: var(--ef-text-14); }

/* ── Cards ── */
.card {
  background: var(--ef-surface);
  border: 1px solid var(--ef-border);
  border-radius: var(--ef-radius-10);
  box-shadow: var(--ef-shadow-1);
}
.card.pad { padding: var(--ef-space-24); }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--ef-space-4);
  height: 22px;
  padding: 0 var(--ef-space-8);
  border-radius: var(--ef-radius-14);
  font-size: var(--ef-text-11);
  font-weight: 600;
  line-height: 1;
}
.bdot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.b-grn { background: var(--ef-green-bg); color: var(--ef-green-text); }
.b-grn .bdot { background: var(--ef-green); }

.b-ylw { background: var(--ef-yellow-bg); color: var(--ef-yellow-text); }
.b-ylw .bdot { background: var(--ef-yellow); }

.b-red { background: var(--ef-red-bg); color: var(--ef-red-text); }
.b-red .bdot { background: var(--ef-red); }

.b-blu { background: var(--ef-blue-bg); color: var(--ef-blue-text); }
.b-blu .bdot { background: var(--ef-blue); }

.b-gry { background: var(--ef-surface-2); color: var(--ef-text-muted); }
.b-gry .bdot { background: var(--ef-text-muted); }

/* ── Avatars ── */
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--ef-color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--ef-text-11);
  font-weight: 600;
  flex-shrink: 0;
  user-select: none;
}

/* ── Alerts / Banners ── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--ef-space-8);
  padding: var(--ef-space-12);
  border-radius: var(--ef-radius-6);
  border: 1px solid transparent;
}
.alert-title { font-size: var(--ef-text-12); font-weight: 600; }
.alert-msg { font-size: var(--ef-text-11); opacity: 0.8; margin-top: 2px; }

.alert-info { background: var(--ef-blue-bg); border-color: rgba(37,99,235,0.15); }
.alert-info .alert-title, .alert-info .alert-msg { color: var(--ef-blue-text); }
.alert-info svg { color: var(--ef-blue); }

.alert-warn { background: var(--ef-yellow-bg); border-color: rgba(217,119,6,0.15); }
.alert-warn .alert-title, .alert-warn .alert-msg { color: var(--ef-yellow-text); }
.alert-warn svg { color: var(--ef-yellow); }

.alert-error { background: var(--ef-red-bg); border-color: rgba(220,38,38,0.15); }
.alert-error .alert-title, .alert-error .alert-msg { color: var(--ef-red-text); }
.alert-error svg { color: var(--ef-red); }

.alert-success { background: var(--ef-green-bg); border-color: rgba(22,163,74,0.15); }
.alert-success .alert-title, .alert-success .alert-msg { color: var(--ef-green-text); }
.alert-success svg { color: var(--ef-green); }

/* ── Theme Switcher ── */
.theme-toggle-btn {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 9997;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--ef-surface);
  border: 1px solid var(--ef-border);
  box-shadow: var(--ef-shadow-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ef-text-muted);
  cursor: pointer;
}
.theme-toggle-btn:hover { background: var(--ef-surface-2); color: var(--ef-text); }

.theme-panel {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 9998;
  background: var(--ef-surface);
  border: 1px solid var(--ef-border);
  border-radius: var(--ef-radius-10);
  box-shadow: var(--ef-shadow-2);
  padding: var(--ef-space-12);
  width: 220px;
}
.theme-panel h4 {
  font-size: var(--ef-text-11);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ef-text-muted);
  margin-bottom: var(--ef-space-8);
}
.theme-group { margin-bottom: var(--ef-space-12); }
.theme-group:last-child { margin-bottom: 0; }

.theme-opt {
  display: flex;
  align-items: center;
  gap: var(--ef-space-8);
  padding: 5px 8px;
  border-radius: var(--ef-radius-6);
  cursor: pointer;
  font-size: var(--ef-text-12);
  color: var(--ef-text);
  transition: all 100ms;
  margin-bottom: 2px;
}
.theme-opt:hover { background: var(--ef-surface-2); }
.theme-opt.active { background: var(--ef-color-primary-bg); color: var(--ef-color-primary); font-weight: 600; }

.theme-swatch {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid var(--ef-border);
  flex-shrink: 0;
}

/* ── Data Tables ── */
.dt { width: 100%; border-collapse: collapse; }
.dt th, .dt td {
  height: 40px;
  padding: 0 var(--ef-space-12);
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--ef-border);
  font-size: var(--ef-text-13);
}
.dt th {
  font-size: var(--ef-text-11);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--ef-text-muted);
  background: var(--ef-surface);
  position: sticky;
  top: 0;
  cursor: default;
  user-select: none;
  white-space: nowrap;
}
.dt th.sortable { cursor: pointer; }
.dt th.sortable:hover { color: var(--ef-text); }
.dt th .sort-icon { display: inline-block; width: 14px; margin-left: 4px; opacity: 0.3; }
.dt th.sort-asc .sort-icon, .dt th.sort-desc .sort-icon { opacity: 1; color: var(--ef-color-primary); }
.dt tbody tr { transition: background 100ms; }
.dt tbody tr:hover { background: var(--ef-surface-2); }
.dt td.mono { font-family: 'SF Mono', 'Cascadia Code', monospace; font-size: var(--ef-text-11); }
.dt td.truncate { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dt td.actions { text-align: right; white-space: nowrap; }
.dt .empty-row td { text-align: center; color: var(--ef-text-muted); padding: var(--ef-space-24); }

/* ── Form Controls ── */
.fg { margin-bottom: var(--ef-space-16); }
.fl {
  display: block;
  font-size: var(--ef-text-12);
  font-weight: 600;
  color: var(--ef-text);
  margin-bottom: var(--ef-space-4);
}
.fi, .fi-select {
  width: 100%;
  height: 34px;
  padding: 0 var(--ef-space-12);
  border: 1px solid var(--ef-border);
  border-radius: var(--ef-radius-6);
  background: var(--ef-surface);
  color: var(--ef-text);
  font-family: var(--ef-font);
  font-size: var(--ef-text-13);
  transition: border-color 150ms, box-shadow 150ms;
}
.fi:focus, .fi-select:focus {
  outline: none;
  border-color: var(--ef-color-primary);
  box-shadow: 0 0 0 3px var(--ef-color-primary-bg);
}
.fi::placeholder { color: var(--ef-text-muted); opacity: 0.6; }
.fi-select { appearance: none; 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='%236b7280' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
textarea.fi { height: auto; min-height: 80px; padding: var(--ef-space-8) var(--ef-space-12); resize: vertical; }
.fi-error { border-color: var(--ef-red); }
.fi-error:focus { box-shadow: 0 0 0 3px var(--ef-red-bg); }
.fi-hint { font-size: var(--ef-text-11); color: var(--ef-text-muted); margin-top: 2px; }

/* ── Modals ── */
.modal-ov {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms, visibility 200ms;
}
.modal-ov.open { opacity: 1; visibility: visible; }
.modal-box {
  width: 440px;
  max-width: 95vw;
  max-height: 90vh;
  background: var(--ef-surface);
  border-radius: var(--ef-radius-10);
  box-shadow: var(--ef-shadow-2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-box.wide { width: 600px; }
.modal-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--ef-space-16) var(--ef-space-24);
  border-bottom: 1px solid var(--ef-border);
}
.modal-hdr h3 {
  font-size: var(--ef-text-14);
  font-weight: 700;
  color: var(--ef-text);
  margin: 0;
}
.modal-bd {
  padding: var(--ef-space-24);
  overflow-y: auto;
  flex: 1;
}
.modal-ft {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--ef-space-8);
  padding: var(--ef-space-16) var(--ef-space-24);
  border-top: 1px solid var(--ef-border);
}

/* ── KPI Cards ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--ef-space-16);
  margin-bottom: var(--ef-space-24);
}
.kpi-card {
  background: var(--ef-surface);
  border: 1px solid var(--ef-border);
  border-radius: var(--ef-radius-10);
  padding: var(--ef-space-16);
  box-shadow: var(--ef-shadow-1);
}
.kpi-label {
  font-size: var(--ef-text-11);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--ef-text-muted);
  margin-bottom: var(--ef-space-4);
}
.kpi-value {
  font-size: var(--ef-text-24);
  font-weight: 700;
  color: var(--ef-text);
  line-height: 1.2;
}

/* ── Filter Bar ── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--ef-space-8);
  margin-bottom: var(--ef-space-16);
  flex-wrap: wrap;
}
.filter-bar .fi, .filter-bar .fi-select {
  width: auto;
  min-width: 160px;
  margin-bottom: 0;
}
.filter-bar .fi-search {
  flex: 1;
  min-width: 200px;
}

/* ── Pagination ── */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--ef-space-12) 0;
  font-size: var(--ef-text-12);
  color: var(--ef-text-muted);
}
.pager-buttons {
  display: flex;
  gap: var(--ef-space-4);
}
.pager-buttons button {
  height: 28px;
  min-width: 28px;
  padding: 0 var(--ef-space-8);
  border: 1px solid var(--ef-border);
  border-radius: var(--ef-radius-6);
  background: var(--ef-surface);
  color: var(--ef-text);
  font-size: var(--ef-text-12);
  cursor: pointer;
  transition: all 100ms;
}
.pager-buttons button:hover { background: var(--ef-surface-2); }
.pager-buttons button.active { background: var(--ef-color-primary); color: #fff; border-color: var(--ef-color-primary); }
.pager-buttons button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Loading Spinner ── */
.loading-row td { text-align: center; padding: var(--ef-space-24); color: var(--ef-text-muted); }
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--ef-border);
  border-top-color: var(--ef-color-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: var(--ef-space-8);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Accessibility ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
