/* ─── HACA Document Manager v1.1.0 — Frontend Styles ──────────────────────── */

:root {
  --haca-accent:       #346550;
  --haca-accent-light: #4a8a6e;
  --haca-accent-hover: #234d3c;
  --haca-accent-pale:  #eaf3ee;
  --haca-card-bg:      #ffffff;
  --haca-bg:           #f5f7f6;
  --haca-border:       #dde5e0;
  --haca-text:         #1a202c;
  --haca-muted:        #64748b;
  --haca-radius:       12px;
  --haca-shadow:       0 2px 12px rgba(52,101,80,0.08);
  --haca-shadow-hover: 0 10px 36px rgba(52,101,80,0.18);
  --haca-transition:   all 0.22s cubic-bezier(0.4,0,0.2,1);
}

/* ── Wrapper ──────────────────────────────────────────────────────────────── */
.haca-docs-wrapper {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--haca-text);
  position: relative;
}

/* ── Search Bar ───────────────────────────────────────────────────────────── */
.haca-docs-search-wrap {
  position: relative;
  margin-bottom: 20px;
}

.haca-docs-search-inner {
  display: flex;
  align-items: center;
  background: #fff;
  border: 2px solid var(--haca-border);
  border-radius: 50px;
  padding: 0 20px 0 0;
  transition: var(--haca-transition);
  box-shadow: 0 2px 8px rgba(52,101,80,0.06);
  overflow: hidden;
}
.haca-docs-search-inner:focus-within {
  border-color: var(--haca-accent);
  box-shadow: 0 4px 18px rgba(52,101,80,0.15);
}

.haca-search-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  background: var(--haca-accent);
  border: none;
  cursor: default;
  flex-shrink: 0;
  border-radius: 50px 0 0 50px;
}
.haca-search-icon-btn svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

.haca-docs-search {
  flex: 1;
  border: none;
  outline: none;
  font-size: 15px;
  color: var(--haca-text);
  background: transparent;
  padding: 14px 12px;
  min-width: 0;
}
.haca-docs-search::placeholder {
  color: #a0aab5;
  font-style: italic;
}

.haca-search-clear {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: #e8edf0;
  color: #64748b;
  font-size: 14px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
  line-height: 1;
  padding: 0;
}
.haca-search-clear:hover { background: #d0d8de; }
.haca-search-clear.visible { display: flex; }

/* ── Filter Tabs ──────────────────────────────────────────────────────────── */
.haca-docs-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}

.haca-filter-btn {
  padding: 8px 18px;
  border-radius: 100px;
  border: 2px solid var(--haca-border);
  background: #fff;
  color: var(--haca-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--haca-transition);
  white-space: nowrap;
  line-height: 1.4;
}
.haca-filter-btn:hover {
  border-color: var(--haca-accent);
  color: var(--haca-accent);
  background: var(--haca-accent-pale);
}
.haca-filter-btn.active {
  background: var(--haca-accent);
  border-color: var(--haca-accent);
  color: #fff;
  box-shadow: 0 3px 10px rgba(52,101,80,0.28);
}
.haca-filter-count {
  opacity: 0.7;
  font-size: 11px;
  font-weight: 400;
}

/* ── Filter Dropdown ──────────────────────────────────────────────────────── */
.haca-docs-filter-dropdown-wrap {
  margin-bottom: 24px;
  position: relative;
  display: inline-block;
  min-width: 260px;
  max-width: 100%;
}

.haca-filter-dropdown-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--haca-muted);
  margin-bottom: 7px;
}

.haca-filter-dropdown-inner {
  position: relative;
  display: flex;
  align-items: center;
}

.haca-filter-select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background: #fff;
  border: 2px solid var(--haca-border);
  border-radius: 10px;
  padding: 13px 46px 13px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--haca-text);
  cursor: pointer;
  outline: none;
  transition: var(--haca-transition);
  box-shadow: 0 2px 8px rgba(52,101,80,0.06);
  line-height: 1.4;
}
.haca-filter-select:hover {
  border-color: var(--haca-accent);
}
.haca-filter-select:focus {
  border-color: var(--haca-accent);
  box-shadow: 0 0 0 3px rgba(52,101,80,0.14);
}

/* Custom chevron */
.haca-filter-dropdown-inner::after {
  content: '';
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--haca-accent);
  pointer-events: none;
  transition: var(--haca-transition);
}

@media (max-width: 600px) {
  .haca-docs-filter-dropdown-wrap { min-width: 100%; display: block; }
}

/* ── Result Count ─────────────────────────────────────────────────────────── */
.haca-docs-count {
  font-size: 13px;
  color: var(--haca-muted);
  margin-bottom: 18px;
  padding: 8px 14px;
  background: var(--haca-accent-pale);
  border-radius: 6px;
  border-left: 3px solid var(--haca-accent);
  display: inline-block;
}
.haca-docs-count:empty { display: none; }
.haca-docs-count strong {
  color: var(--haca-accent);
  font-weight: 700;
}

/* ── View Toggle Bar ──────────────────────────────────────────────────────── */
.haca-docs-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  gap: 12px;
  flex-wrap: wrap;
}
.haca-docs-toolbar .haca-docs-count {
  margin-bottom: 0;
}
.haca-view-toggle {
  display: flex;
  align-items: center;
  background: #fff;
  border: 1.5px solid var(--haca-border);
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
}
.haca-view-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 34px;
  border: none;
  background: transparent;
  color: var(--haca-muted);
  cursor: pointer;
  transition: var(--haca-transition);
  padding: 0;
}
.haca-view-btn:first-child {
  border-right: 1.5px solid var(--haca-border);
}
.haca-view-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}
.haca-view-btn:hover {
  background: var(--haca-accent-pale);
  color: var(--haca-accent);
}
.haca-view-btn.active {
  background: var(--haca-accent);
  color: #fff;
}

/* ── Document Grid ────────────────────────────────────────────────────────── */
.haca-docs-grid {
  display: grid;
  grid-template-columns: repeat(var(--haca-cols, 3), 1fr);
  gap: 22px;
}
@media (max-width: 960px) { .haca-docs-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .haca-docs-grid { grid-template-columns: 1fr; } }

/* ── Document Card ────────────────────────────────────────────────────────── */
.haca-doc-card {
  background: var(--haca-card-bg);
  border: 1.5px solid var(--haca-border);
  border-radius: var(--haca-radius);
  cursor: pointer;
  transition: var(--haca-transition);
  box-shadow: var(--haca-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  outline: none;
}
.haca-doc-card:hover,
.haca-doc-card:focus {
  box-shadow: var(--haca-shadow-hover);
  border-color: var(--haca-accent);
  transform: translateY(-4px);
}
.haca-doc-card:focus { outline: 2px solid var(--haca-accent); outline-offset: 2px; }

/* Card Header */
.haca-doc-card-header {
  background: linear-gradient(135deg, var(--haca-accent) 0%, var(--haca-accent-light) 100%);
  padding: 20px 18px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.haca-doc-icon {
  width: 46px;
  height: 46px;
  background: rgba(255,255,255,0.18);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
/* FIX: icons must be white */
.haca-doc-icon svg {
  width: 24px;
  height: 24px;
  fill: #ffffff;
}

.haca-doc-header-meta { flex: 1; min-width: 0; }
.haca-doc-card-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.6);
  margin-bottom: 5px;
  display: block;
}
.haca-doc-ext-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.25);
  padding: 3px 10px;
  border-radius: 5px;
  letter-spacing: 0.5px;
}

/* Card Body */
.haca-doc-card-body {
  padding: 18px 18px 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.haca-doc-card-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--haca-text);
  line-height: 1.45;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.haca-doc-excerpt {
  font-size: 13px;
  color: var(--haca-muted);
  line-height: 1.6;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

/* Category Tags */
.haca-doc-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.haca-doc-cat-tag {
  font-size: 11px;
  font-weight: 500;
  background: var(--haca-accent-pale);
  color: var(--haca-accent);
  padding: 3px 9px;
  border-radius: 4px;
  border: 1px solid rgba(52,101,80,0.18);
}

/* FIX: Card Meta / Date area - proper horizontal layout, NO broken wrapping */
.haca-doc-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 12px;
  margin-top: auto;
  border-top: 1px solid var(--haca-border);
}
.haca-doc-date {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--haca-muted);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* FIX: date icon — small, clean, uses accent color */
.haca-doc-date-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  fill: var(--haca-accent);
  opacity: 0.7;
}
.haca-doc-date-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.haca-doc-size-badge {
  font-size: 11px;
  font-weight: 600;
  background: var(--haca-bg);
  color: var(--haca-muted);
  padding: 3px 9px;
  border-radius: 5px;
  border: 1px solid var(--haca-border);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── LIST VIEW ────────────────────────────────────────────────────────────── */
.haca-docs-grid.list-view {
  display: flex;
  flex-direction: column;
  gap: 10px;
  grid-template-columns: unset;
}

.haca-docs-grid.list-view .haca-doc-card {
  flex-direction: row;
  align-items: stretch;
  border-radius: 10px;
  transform: none !important;
  padding: 0;
  min-height: 0;
}
.haca-docs-grid.list-view .haca-doc-card:hover {
  transform: translateX(3px) !important;
}

/* Left green icon strip */
.haca-docs-grid.list-view .haca-doc-card-header {
  width: 52px;
  min-width: 52px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px 0 0 10px;
  flex-shrink: 0;
}
.haca-docs-grid.list-view .haca-doc-icon {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: rgba(255,255,255,0.2);
}
.haca-docs-grid.list-view .haca-doc-icon svg {
  width: 15px;
  height: 15px;
}
.haca-docs-grid.list-view .haca-doc-header-meta {
  display: none;
}

/* List body — two-row layout: title on top, meta below */
.haca-docs-grid.list-view .haca-doc-card-body {
  flex: 1;
  flex-direction: column;
  align-items: flex-start;
  padding: 11px 16px;
  gap: 6px;
  min-width: 0;
}

/* Title — allow 2 lines, never truncate to 1 */
.haca-docs-grid.list-view .haca-doc-card-name {
  font-size: 14px;
  font-weight: 600;
  -webkit-line-clamp: 2;
  flex: none;
  width: 100%;
  margin: 0;
  line-height: 1.4;
}

/* Meta row — category, type, date, size all in one flex row */
.haca-list-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  width: 100%;
}

/* Category tags in list */
.haca-docs-grid.list-view .haca-doc-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex-shrink: 0;
}
.haca-docs-grid.list-view .haca-doc-cat-tag {
  font-size: 10px;
  padding: 2px 7px;
  white-space: nowrap;
}

/* Hide excerpt in list view */
.haca-docs-grid.list-view .haca-doc-excerpt {
  display: none;
}

/* Footer in list — part of meta row, no border, no padding */
.haca-docs-grid.list-view .haca-doc-card-footer {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
  flex-shrink: 0;
  gap: 6px;
  display: contents; /* children participate in meta row flex */
}
.haca-docs-grid.list-view .haca-doc-date {
  font-size: 11px;
  white-space: nowrap;
  flex-shrink: 0;
}
.haca-docs-grid.list-view .haca-doc-size-badge {
  white-space: nowrap;
  font-size: 10px;
  padding: 2px 7px;
  flex-shrink: 0;
}

/* Ext badge */
.haca-list-ext-badge {
  display: none;
  font-size: 10px;
  font-weight: 700;
  color: var(--haca-accent);
  background: var(--haca-accent-pale);
  border: 1px solid rgba(52,101,80,0.18);
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: 0.4px;
  white-space: nowrap;
  flex-shrink: 0;
}
.haca-docs-grid.list-view .haca-list-ext-badge {
  display: inline-block;
}

/* ── Mobile list view — clean stacked layout ──────────────────────────────── */
@media (max-width: 640px) {
  .haca-docs-grid.list-view .haca-doc-card-header {
    width: 44px;
    min-width: 44px;
  }
  .haca-docs-grid.list-view .haca-doc-card-body {
    padding: 10px 12px;
    gap: 5px;
  }
  .haca-docs-grid.list-view .haca-doc-card-name {
    font-size: 13px;
  }
  .haca-list-meta-row {
    gap: 5px;
  }
  .haca-docs-grid.list-view .haca-doc-cat-tag {
    font-size: 9px;
    padding: 2px 5px;
  }
  .haca-docs-grid.list-view .haca-doc-date {
    font-size: 10px;
  }
  .haca-docs-grid.list-view .haca-doc-size-badge {
    font-size: 10px;
  }
  .haca-list-ext-badge {
    font-size: 9px;
    padding: 2px 5px;
  }
}

/* ── Loading State ────────────────────────────────────────────────────────── */
.haca-docs-loading {
  grid-column: 1/-1;
  text-align: center;
  padding: 70px 20px;
  color: var(--haca-muted);
}
.haca-spinner {
  width: 42px;
  height: 42px;
  border: 3px solid var(--haca-border);
  border-top-color: var(--haca-accent);
  border-radius: 50%;
  animation: haca-spin 0.75s linear infinite;
  margin: 0 auto 16px;
}
@keyframes haca-spin { to { transform: rotate(360deg); } }
.haca-docs-loading p { font-size: 14px; margin: 0; }

/* ── Empty State ──────────────────────────────────────────────────────────── */
.haca-docs-empty {
  grid-column: 1/-1;
  text-align: center;
  padding: 70px 20px;
  color: var(--haca-muted);
}
.haca-docs-empty svg {
  width: 56px;
  height: 56px;
  fill: #c8d8d0;
  margin: 0 auto 16px;
  display: block;
}
.haca-docs-empty p { font-size: 15px; margin: 0; }

/* ── Pagination ───────────────────────────────────────────────────────────── */
.haca-docs-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin-top: 36px;
  flex-wrap: wrap;
}
.haca-page-btn {
  padding: 9px 16px;
  min-width: 40px;
  border-radius: 8px;
  border: 1.5px solid var(--haca-border);
  background: #fff;
  color: var(--haca-text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--haca-transition);
}
.haca-page-btn:hover:not(:disabled) {
  border-color: var(--haca-accent);
  color: var(--haca-accent);
  background: var(--haca-accent-pale);
}
.haca-page-btn.active {
  background: var(--haca-accent);
  border-color: var(--haca-accent);
  color: #fff;
  font-weight: 700;
}
.haca-page-btn:disabled { opacity: 0.38; cursor: not-allowed; }

/* ── Modal Overlay ────────────────────────────────────────────────────────── */
.haca-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,25,18,0.65);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 999999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.haca-modal-overlay.haca-open { display: flex; }

.haca-modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 540px;
  box-shadow: 0 28px 90px rgba(10,25,18,0.35);
  overflow: hidden;
  animation: haca-modal-in 0.3s cubic-bezier(0.34,1.56,0.64,1) both;
}
@keyframes haca-modal-in {
  from { transform: scale(0.88) translateY(24px); opacity: 0; }
  to   { transform: scale(1) translateY(0);       opacity: 1; }
}

/* Modal Header */
.haca-modal-header {
  background: linear-gradient(135deg, var(--haca-accent) 0%, var(--haca-accent-light) 100%);
  padding: 26px 24px 22px;
  position: relative;
  display: flex;
  gap: 16px;
  align-items: flex-start;
}
.haca-modal-doc-icon {
  width: 58px;
  height: 58px;
  background: rgba(255,255,255,0.18);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
/* FIX: modal icon must be white */
.haca-modal-doc-icon svg {
  width: 30px;
  height: 30px;
  fill: #ffffff;
}
.haca-modal-header-text { flex: 1; min-width: 0; padding-right: 28px; }
.haca-modal-title {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  margin: 0 0 10px;
  line-height: 1.35;
}
.haca-modal-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.haca-modal-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  padding: 4px 11px;
  border-radius: 20px;
  white-space: nowrap;
}
.haca-modal-badge svg {
  width: 12px;
  height: 12px;
  fill: rgba(255,255,255,0.85);
  flex-shrink: 0;
}

.haca-modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,0.18);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  transition: background 0.18s;
  padding: 0;
  line-height: 1;
}
.haca-modal-close:hover { background: rgba(255,255,255,0.32); }

/* Modal Body */
.haca-modal-body {
  padding: 28px 28px 32px;
}
.haca-modal-excerpt {
  font-size: 14px;
  color: var(--haca-muted);
  line-height: 1.7;
  margin: 0 0 24px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--haca-border);
}
.haca-modal-excerpt:empty { display: none; }
.haca-modal-actions { display: flex; flex-direction: column; gap: 12px; }

/* Modal Buttons */
.haca-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 15px 24px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none !important;
  transition: var(--haca-transition);
  width: 100%;
  box-sizing: border-box;
}
.haca-btn svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  fill: currentColor;
}
.haca-btn-primary {
  background: var(--haca-accent);
  color: #fff !important;
  box-shadow: 0 4px 18px rgba(52,101,80,0.28);
}
.haca-btn-primary:hover {
  background: var(--haca-accent-hover);
  box-shadow: 0 6px 24px rgba(52,101,80,0.36);
  transform: translateY(-1px);
}
.haca-btn-secondary {
  background: var(--haca-bg);
  color: var(--haca-text) !important;
  border: 2px solid var(--haca-border);
}
.haca-btn-secondary:hover {
  background: #e4ede8;
  border-color: #b0c9bb;
  transform: translateY(-1px);
}

.haca-modal-no-file {
  text-align: center;
  color: var(--haca-muted);
  font-size: 14px;
  padding: 16px 0 0;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .haca-modal-body { padding: 20px 18px 24px; }
  .haca-modal-header { padding: 20px 18px 18px; }
  .haca-docs-filters { gap: 6px; }
  .haca-filter-btn { font-size: 12px; padding: 7px 14px; }
  .haca-section-title { font-size: 18px; }
}
