/*
 * CIDA visual system.
 *
 * All colours are hex or rgb() on purpose — oklch() silently fails to render in
 * the Telegram in-app browser and older Safari, producing invisible text, and
 * this archive is opened from a phone more often than a desktop.
 */

:root {
  --bg: #0b0e13;
  --bg-raise: #11151c;
  --bg-card: #141922;
  --bg-hover: #1a212c;
  --border: #232b38;
  --border-bright: #2f3a4b;
  --text: #e8ecf2;
  --text-dim: #97a3b6;
  --text-faint: #64717f;
  --accent: #4a9eff;
  --accent-dim: #2b5f99;
  --danger: #e5484d;
  --ok: #46a758;
  --radius: 10px;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

button, input, select { font-family: inherit; font-size: inherit; }

/* ---------------------------------------------------------------- gate */

.gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 50% -10%, #16202e 0%, transparent 60%),
    var(--bg);
  z-index: 100;
}

.gate-card {
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.gate-mark {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.42em;
  color: var(--accent);
  margin-bottom: 26px;
}

.gate-title {
  font-size: 25px;
  line-height: 1.32;
  font-weight: 600;
  margin: 0 0 12px;
  letter-spacing: -0.015em;
}

.gate-sub {
  color: var(--text-faint);
  font-size: 13px;
  margin: 0 0 30px;
}

#gate-form { display: flex; flex-direction: column; gap: 10px; }

#gate-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-align: center;
  letter-spacing: 0.3em;
  font-family: var(--mono);
  outline: none;
  transition: border-color 0.15s;
}

#gate-input:focus { border-color: var(--accent-dim); }

#gate-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: #061018;
  border: 0;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

#gate-btn:hover { opacity: 0.9; }
#gate-btn:disabled { opacity: 0.5; cursor: default; }

.gate-error {
  min-height: 20px;
  margin-top: 14px;
  color: var(--danger);
  font-size: 13px;
}

.gate-foot {
  margin-top: 42px;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* ---------------------------------------------------------------- shell */

.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px;
  background: var(--bg-raise);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 15px;
  letter-spacing: 0.22em;
  color: var(--accent);
  flex-shrink: 0;
}

.brand-divider { width: 1px; height: 18px; background: var(--border-bright); flex-shrink: 0; }

.brand-full {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions { display: flex; gap: 8px; flex-shrink: 0; }

.btn {
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border-bright);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.btn:hover { background: var(--bg-hover); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #061018;
  font-weight: 600;
}

.btn-primary:hover { background: #5aa8ff; }
.btn-ghost { color: var(--text-dim); }

/* ---------------------------------------------------------------- stats */

.stats {
  display: flex;
  gap: 28px;
  flex-wrap: wrap;
  padding: 18px 22px 4px;
}

.stat-label {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 4px;
}

.stat-value { font-family: var(--mono); font-size: 19px; font-weight: 500; }

/* ---------------------------------------------------------------- toolbar */

.toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  padding: 16px 22px;
}

.search-wrap { position: relative; flex: 1 1 260px; min-width: 200px; }

#search {
  width: 100%;
  padding: 11px 14px;
  padding-right: 74px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  outline: none;
  font-size: 14px;
  transition: border-color 0.15s;
}

#search:focus { border-color: var(--accent-dim); }

.search-count {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  pointer-events: none;
}

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.filters select {
  padding: 11px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  outline: none;
  cursor: pointer;
  font-size: 13px;
  max-width: 190px;
}

.filters select:focus { border-color: var(--accent-dim); }

.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.vbtn {
  padding: 10px 13px;
  background: var(--bg-card);
  border: 0;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.vbtn.active { background: var(--bg-hover); color: var(--accent); }

/* ---------------------------------------------------------------- results */

.results { padding: 6px 22px 40px; flex: 1; }

.results.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
  gap: 12px;
}

.results.list { display: flex; flex-direction: column; gap: 6px; }

.doc {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.doc:hover {
  border-color: var(--border-bright);
  background: var(--bg-hover);
  transform: translateY(-1px);
}

.doc-top { display: flex; align-items: center; gap: 10px; min-width: 0; }

.doc-ext {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.08em;
  padding: 4px 7px;
  border-radius: 4px;
  background: #1d2836;
  color: var(--accent);
  text-transform: uppercase;
  flex-shrink: 0;
}

.doc-ext.pdf  { background: #33201f; color: #ff7b72; }
.doc-ext.docx { background: #1b2740; color: #6ea8ff; }
.doc-ext.jpg, .doc-ext.png, .doc-ext.jpeg { background: #1f3327; color: #79d18b; }
.doc-ext.xlsx { background: #1d3025; color: #62c37a; }
.doc-ext.mp4  { background: #2b2338; color: #b98bff; }
.doc-ext.zip  { background: #33301f; color: #e3c76a; }

.doc-name {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  word-break: break-word;
  flex: 1;
  min-width: 0;
}

.doc-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 11px;
  color: var(--text-faint);
  font-family: var(--mono);
}

.doc-cat {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #1a222e;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* list variant */
.results.list .doc { flex-direction: row; align-items: center; padding: 11px 14px; gap: 12px; }
.results.list .doc-top { flex: 1; }
.results.list .doc-meta { flex-shrink: 0; }

.empty { padding: 60px 22px; text-align: center; color: var(--text-faint); font-size: 14px; }

/* ---------------------------------------------------------------- footer */

.footer {
  padding: 20px 22px 30px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: center;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.footer-sep { opacity: 0.5; }

/* ---------------------------------------------------------------- modal */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 10, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
}

.modal-card {
  width: 100%;
  max-width: 460px;
  background: var(--bg-raise);
  border: 1px solid var(--border-bright);
  border-radius: 14px;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 { margin: 0; font-size: 15px; font-weight: 600; }

.modal-x {
  background: transparent;
  border: 0;
  color: var(--text-faint);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }

.modal-foot {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.drop {
  border: 1px dashed var(--border-bright);
  border-radius: var(--radius);
  padding: 30px 18px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.drop:hover, .drop.over { border-color: var(--accent-dim); background: #131a24; }
.drop-icon { font-size: 22px; color: var(--accent); margin-bottom: 8px; }
#drop-text { font-size: 13px; color: var(--text-dim); word-break: break-all; }

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

.field span {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.field select {
  padding: 11px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  outline: none;
}

.upload-status { font-size: 12px; min-height: 18px; color: var(--text-dim); font-family: var(--mono); }
.upload-status.ok { color: var(--ok); }
.upload-status.err { color: var(--danger); }

/* ---------------------------------------------------------------- viewer */

.viewer {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 300;
  display: flex;
  flex-direction: column;
}

.viewer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 18px;
  background: var(--bg-raise);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.viewer-title {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.viewer-actions { display: flex; gap: 8px; flex-shrink: 0; }

.viewer-body { flex: 1; overflow: auto; background: #05070a; }
.viewer-body iframe { width: 100%; height: 100%; border: 0; display: block; }

.viewer-body img {
  max-width: 100%;
  max-height: 100%;
  display: block;
  margin: auto;
  padding: 16px;
}

.viewer-body video { max-width: 100%; max-height: 100%; display: block; margin: auto; }

.viewer-body pre {
  margin: 0;
  padding: 22px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.viewer-fallback { padding: 60px 22px; text-align: center; color: var(--text-dim); }
.viewer-fallback p { margin: 0 0 18px; font-size: 14px; }

.spinner {
  width: 26px;
  height: 26px;
  margin: 60px auto;
  border: 2px solid var(--border-bright);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- mobile */

@media (max-width: 720px) {
  .brand-full { display: none; }
  .topbar { padding: 13px 15px; }
  .stats { padding: 14px 15px 2px; gap: 20px; }
  .stat-value { font-size: 16px; }
  .toolbar { padding: 13px 15px; }
  .results { padding: 4px 15px 32px; }
  .results.grid { grid-template-columns: 1fr; }
  .filters { width: 100%; }
  .filters select { flex: 1 1 auto; max-width: none; }
  .footer { padding: 18px 15px 26px; flex-direction: column; align-items: center; gap: 4px; }
  .footer-sep { display: none; }
  .results.list .doc { flex-direction: column; align-items: flex-start; }
}
