/* ══════════════════════════════════════════════════════════
   SEARCLE — Material Sample Uploader
   app.css — all styles
   ══════════════════════════════════════════════════════════ */

/* ── Variables ────────────────────────────────────────────── */
:root {
  --brand:      #1a5276;
  --brand-light:#2980b9;
  --accent:     #e8f4fd;
  --sidebar-w:  280px;
  --nav-h:      52px;
  --panel-h:    calc(100vh - var(--nav-h));
}

body { background: #f0f4f8; font-size: 0.875rem; min-height: 100vh; }

/* ── Navbar ───────────────────────────────────────────────── */
.navbar { background: var(--brand); padding: 0.5rem 1rem; height: var(--nav-h); }
.navbar-brand { color: #fff !important; font-weight: 700; font-size: 1.1rem; letter-spacing: .5px; }
.badge-tenant { background: rgba(255,255,255,.2); color:#fff; font-size:.7rem; padding:3px 7px; border-radius:20px; }
.conn-badge   { font-size: .72rem; }

.nav-mode-btn {
  background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.3);
  color: #fff; border-radius: 6px; padding: 4px 14px; font-size: .8rem;
  cursor: pointer; transition: background .15s;
}
.nav-mode-btn.active { background: rgba(255,255,255,.35); font-weight: 700; }
.nav-mode-btn:hover  { background: rgba(255,255,255,.25); }

/* ── Mode visibility — driven by body[data-mode] ─────────── */
#app-layout     { display: none; height: var(--panel-h); overflow: hidden; }
#dashboard-view { display: none; height: var(--panel-h); overflow: hidden; background: #f0f4f8; flex-direction: column; }
#model-view     { display: none; height: var(--panel-h); overflow: hidden; }

body[data-mode="edit"]      #app-layout     { display: flex; }
body[data-mode="dashboard"] #dashboard-view { display: flex; }
body[data-mode="model"]     #model-view     { display: flex; }

/* ── Dashboard sub-views — driven by #dashboard-view[data-view] */
#db-grid-view   { display: none; flex: 1; overflow-y: auto; padding: 1.5rem; }
#db-detail-view { display: none; flex: 1; flex-direction: column; overflow: hidden; }
#dashboard-view[data-view="grid"]   #db-grid-view   { display: block; }
#dashboard-view[data-view="detail"] #db-detail-view { display: flex; }

/* ── Sidebar ──────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: #fff; border-right: 1px solid #dee2e6;
  display: flex; flex-direction: column; overflow: hidden;
}
#sidebar-header { padding: 1rem; border-bottom: 1px solid #dee2e6; background: var(--accent); }
#sample-list    { flex: 1; overflow-y: auto; padding: .5rem; }

.sample-item {
  padding: .55rem .75rem; border-radius: 8px; cursor: pointer;
  margin-bottom: 4px; border: 1px solid transparent; transition: background .15s;
}
.sample-item:hover  { background: #e9ecef; }
.sample-item.active { background: var(--accent); border-color: var(--brand-light); }
.sample-item .s-name { font-weight: 600; color: #333; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sample-item .s-meta { font-size: .72rem; color: #888; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Edit main panel ──────────────────────────────────────── */
#main-content { flex: 1; overflow-y: auto; padding: 1.5rem; }

#welcome { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 60vh; }
#welcome .icon { font-size: 4rem; color: #c5d8e8; }

#sample-editor { display: none; }

.sample-header-card {
  background: #fff; border-radius: 12px; border: 1px solid #dee2e6;
  padding: 1.2rem 1.5rem; margin-bottom: 1.5rem;
}
.sample-id-badge {
  font-family: monospace; font-size: .72rem;
  background: #e9ecef; padding: 3px 8px; border-radius: 4px; color: #555;
}

/* ── Edit modules grid ────────────────────────────────────── */
#modules-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 1rem; margin-bottom: 1rem; }

.module-card { background: #fff; border-radius: 12px; border: 1px solid #dee2e6; overflow: hidden; display: flex; flex-direction: column; }
.module-card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .65rem 1rem; border-bottom: 1px solid #f0f0f0; background: #fafafa;
}
.module-card-body { padding: 1rem; flex: 1; }
.module-chart-container { position: relative; height: 220px; margin-bottom: .75rem; }
.module-image-preview { width: 100%; max-height: 200px; object-fit: contain; border-radius: 6px; border: 1px solid #eee; margin-bottom: .75rem; background: #f8f9fa; }
.module-image-placeholder {
  width: 100%; height: 150px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; background: #f8f9fa;
  border: 1px dashed #ccc; border-radius: 6px; color: #999; margin-bottom: .75rem; font-size: .8rem;
}
.file-drop-zone {
  border: 2px dashed #ccc; border-radius: 8px; padding: .75rem;
  text-align: center; cursor: pointer; color: #888;
  transition: border-color .2s, background .2s; margin-bottom: .5rem;
}
.file-drop-zone:hover, .file-drop-zone.dragover { border-color: var(--brand-light); background: var(--accent); color: var(--brand); }
.file-drop-zone.has-file   { border-color: #28a745; background: #f0fff4; color: #155724; }
.file-drop-zone .icon      { font-size: 1.4rem; display: block; margin-bottom: 4px; }

/* ── Type badges ──────────────────────────────────────────── */
.module-type-badge { font-size: .68rem; font-weight: 700; padding: 2px 8px; border-radius: 20px; text-transform: uppercase; letter-spacing: .5px; }
.badge-sem         { background: #ffeeba; color: #856404; }
.badge-xrd         { background: #d4edda; color: #155724; }
.badge-ftir        { background: #d1ecf1; color: #0c5460; }
.badge-psd         { background: #e2d9f3; color: #4a235a; }
.badge-tga         { background: #ffd5d5; color: #721c24; }
.badge-density     { background: #dce3f3; color: #1a3a5c; }
.badge-flowability { background: #fde8d8; color: #7d3c00; }
.badge-comment     { background: #e9ecef; color: #444; }

/* ── Module type picker cards ─────────────────────────────── */
.mod-type-card {
  border: 2px solid #dee2e6; border-radius: 10px; padding: .9rem;
  cursor: pointer; text-align: center; transition: border-color .15s, background .15s;
}
.mod-type-card:hover { border-color: var(--brand-light); background: var(--accent); }
.mod-type-card .mod-icon  { font-size: 1.8rem; margin-bottom: .3rem; }
.mod-type-card .mod-label { font-weight: 700; font-size: .8rem; }
.mod-type-card .mod-desc  { font-size: .7rem; color: #888; }

/* ── Actions bar ──────────────────────────────────────────── */
.actions-bar {
  background: #fff; border-radius: 12px; border: 1px solid #dee2e6;
  padding: 1rem 1.25rem; display: flex; gap: .75rem; flex-wrap: wrap; align-items: center;
}

/* ── Dashboard grid ───────────────────────────────────────── */
.db-stats-bar { display: flex; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.db-stat-card {
  background: #fff; border-radius: 10px; border: 1px solid #dee2e6;
  padding: .75rem 1.25rem; display: flex; align-items: center; gap: .75rem;
}
.db-stat-card .stat-icon { font-size: 1.5rem; }
.db-stat-card .stat-val  { font-size: 1.4rem; font-weight: 700; color: var(--brand); line-height: 1; }
.db-stat-card .stat-lbl  { font-size: .72rem; color: #888; }

#db-cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }

.db-card {
  background: #fff; border-radius: 12px; border: 1px solid #dee2e6;
  padding: 1.25rem; cursor: pointer; transition: box-shadow .2s, transform .1s;
}
.db-card:hover { box-shadow: 0 4px 16px rgba(26,82,118,.15); transform: translateY(-1px); }
.db-card .db-name   { font-size: 1.05rem; font-weight: 700; color: var(--brand); margin-bottom: .3rem; }
.db-card .db-id     { font-family: monospace; font-size: .68rem; color: #999; margin-bottom: .6rem; word-break: break-all; }
.db-card .db-badges { margin-top: .6rem; display: flex; flex-wrap: wrap; gap: 4px; }
.db-card .db-stat   { font-size: .72rem; color: #888; margin-top: .5rem; }

/* ── Dashboard detail ─────────────────────────────────────── */
#db-detail-header {
  background: var(--brand); color: #fff;
  padding: .75rem 1.5rem; display: flex; align-items: center; gap: 1rem; flex-shrink: 0;
}
#db-detail-title { font-size: 1.1rem; font-weight: 700; }
#db-detail-id    { font-size: .7rem; opacity: .7; font-family: monospace; }
#db-detail-body  { flex: 1; overflow-y: auto; padding: 1.5rem; }

.db-mod-card { background: #fff; border-radius: 12px; border: 1px solid #dee2e6; overflow: hidden; margin-bottom: 1rem; }
.db-mod-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .65rem 1rem; border-bottom: 1px solid #f0f0f0; background: #fafafa;
}
.db-mod-body { padding: 1rem; }

.db-chart-container     { position: relative; height: 240px; margin-bottom: 1rem; }
.db-image-preview       { width: 100%; max-height: 260px; object-fit: contain; border-radius: 8px; border: 1px solid #eee; background: #f8f9fa; margin-bottom: .75rem; }
.db-image-placeholder   { width: 100%; height: 120px; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #f8f9fa; border: 1px dashed #ccc; border-radius: 6px; color: #aaa; font-size: .8rem; gap: 4px; margin-bottom: .75rem; }

/* Raw data preview table */
.raw-preview-table { width: 100%; border-collapse: collapse; font-size: .75rem; font-family: monospace; margin-bottom: .5rem; }
.raw-preview-table th { background: #f0f4f8; color: var(--brand); padding: 4px 10px; text-align: left; font-weight: 700; border-bottom: 2px solid #dee2e6; }
.raw-preview-table td { padding: 3px 10px; border-bottom: 1px solid #f0f0f0; color: #444; }
.raw-preview-more     { font-size: .72rem; color: #999; font-style: italic; padding: 3px 10px 0; }

/* Scalar display boxes */
.scalar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.scalar-box  { background: var(--accent); border-radius: 8px; padding: .6rem 1rem; border-left: 3px solid var(--brand-light); }
.scalar-box .s-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .4px; color: #666; font-weight: 700; }
.scalar-box .s-value { font-size: 1.1rem; font-weight: 700; color: var(--brand); }
.scalar-box .s-unit  { font-size: .72rem; color: #888; }

/* Download buttons */
.download-bar { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; padding-top: .75rem; border-top: 1px solid #f0f0f0; }

/* Metadata table */
.meta-table             { width: 100%; font-size: .8rem; margin-bottom: .75rem; }
.meta-table td:first-child { color: #888; width: 40%; padding: 3px 0; font-weight: 600; }
.meta-table td:last-child  { color: #333; }

/* ── Shared utilities ─────────────────────────────────────── */
.btn-brand { background: var(--brand); color: #fff; border: none; }
.btn-brand:hover { background: var(--brand-light); color: #fff; }
.btn-report { background: #00A99D; color: #fff; border: none; }
.btn-report:hover { background: #008f84; color: #fff; }

.lbl {
  font-weight: 600; font-size: .75rem; color: #666;
  text-transform: uppercase; letter-spacing: .4px; margin-bottom: 2px;
}

pre.ngsi-pre {
  background: #1e1e2e; color: #cdd6f4; border-radius: 8px;
  padding: 1rem; font-size: .72rem; max-height: 450px; overflow-y: auto; white-space: pre-wrap;
}

.db-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 50vh; }
.db-empty .icon { font-size: 3.5rem; color: #c5d8e8; }

/* Spinner overlay for send */
.sending-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 9999; display: flex; align-items: center; justify-content: center;
}

/* DB-only card styling */
.db-card-dbonly {
  border: 2px dashed #00A99D;
  background: linear-gradient(135deg, #f0fffe 0%, #fff 100%);
  opacity: .9;
  cursor: default;
}
.db-card-dbonly:hover { border-color: #00A99D; transform: none; box-shadow: none; }

/* Backup samples */
.sample-item.backup-sample { border-left: 3px solid #dc3545; background: #fff5f5; }
.sample-item.backup-sample:hover { background: #ffe0e0; }

.db-card-backup {
  border: 2px solid #dc3545;
  background: #fff5f5;
  border-radius: 8px;
  padding: 1rem;
  cursor: pointer;
  transition: box-shadow .15s;
}
.db-card-backup:hover { box-shadow: 0 4px 16px rgba(220,53,69,.2); }
.db-card-backup .db-name { font-size: 1.05rem; font-weight: 700; color: #dc3545; margin-bottom: .3rem; }
.db-card-backup .db-id   { font-family: monospace; font-size: .68rem; color: #999; margin-bottom: .5rem; word-break: break-all; }
.db-card-backup .db-stat { font-size: .72rem; color: #888; margin-top: .5rem; }

/* Spin animation for sync button */
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.spin { display: inline-block; animation: spin .8s linear infinite; }

/* Login modal header branding */
#modalLogin .modal-header { padding: .75rem 1rem; }
#modalLogin .modal-body   { padding: 1.5rem; }

/* ══════════════════════════════════════════════════════════
   CE MODEL MODE — Circular Economy Canvas
   ══════════════════════════════════════════════════════════ */

/* ── Layout ───────────────────────────────────────────────── */
#model-root  { display: flex; width: 100%; height: 100%; }
.ce-layout   { display: flex; width: 100%; height: 100%; overflow: hidden; }

/* ── Sidebar ──────────────────────────────────────────────── */
.ce-sidebar {
  width: 260px; min-width: 260px;
  background: #fff; border-right: 1px solid #dee2e6;
  display: flex; flex-direction: column; overflow: hidden;
}

.ce-sidebar-header {
  padding: .85rem 1rem;
  background: var(--brand); color: #fff;
  font-weight: 700; font-size: .95rem; letter-spacing: .3px;
  flex-shrink: 0;
}

.ce-sidebar-new {
  padding: .75rem; border-bottom: 1px solid #f0f0f0; flex-shrink: 0;
}

.ce-model-list { flex: 1; overflow-y: auto; padding: .5rem; }

.ce-model-item {
  padding: .6rem .75rem; border-radius: 8px; cursor: pointer;
  margin-bottom: 4px; border: 1px solid transparent;
  transition: background .15s;
}
.ce-model-item:hover { background: #f0f4f8; }
.ce-model-item-active { background: var(--accent); border-color: var(--brand-light); }

.ce-model-name {
  font-weight: 600; font-size: .83rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 150px; display: inline-block; vertical-align: middle;
}
.ce-model-meta { font-size: .7rem; color: #999; margin-top: 1px; }

.ce-empty-msg {
  font-size: .8rem; color: #aaa; text-align: center;
  padding: 1.5rem .5rem; white-space: pre-line; line-height: 1.6;
}

/* Scenario badges */
.ce-badge {
  display: inline-block; font-size: .62rem; font-weight: 700;
  padding: 2px 7px; border-radius: 20px;
  text-transform: uppercase; letter-spacing: .5px; white-space: nowrap;
}
.ce-badge-AS_IS { background: #fef9e7; color: #9a7d0a; border: 1px solid #f9e79f; }
.ce-badge-TO_BE { background: #eafaf1; color: #1a6b3c; border: 1px solid #a9dfbf; }

/* Actor palette */
.ce-palette { border-top: 1px solid #dee2e6; padding-bottom: .5rem; flex-shrink: 0; }

.ce-palette-title {
  font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .4px; color: #999; padding: .6rem .75rem .3rem;
}

.ce-palette-item {
  padding: .38rem .75rem; cursor: grab; border-radius: 6px;
  font-size: .82rem; color: #333;
  transition: background .1s, transform .1s;
  margin: 2px .4rem;
  border: 1px solid transparent;
  user-select: none;
}
.ce-palette-item:hover   { background: var(--accent); border-color: #c8dff0; }
.ce-palette-item:active  { cursor: grabbing; transform: scale(.98); }

.ce-sidebar-footer {
  padding: .75rem; border-top: 1px solid #dee2e6; flex-shrink: 0;
}

/* ── Canvas area ──────────────────────────────────────────── */
.ce-canvas-wrapper { flex: 1; position: relative; overflow: hidden; }

.ce-empty-canvas {
  display: flex; align-items: center; justify-content: center;
  height: 100%; background: #f0f4f8;
}

.ce-canvas-badge {
  background: rgba(255,255,255,.92); backdrop-filter: blur(4px);
  padding: 5px 16px; border-radius: 20px; font-weight: 700;
  font-size: .88rem; color: var(--brand);
  border: 1px solid #dee2e6; box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

.ce-canvas-hint {
  background: rgba(255,255,255,.85);
  padding: 4px 12px; border-radius: 10px;
  font-size: .7rem; color: #666;
  border: 1px solid #e9ecef;
}

/* ── Custom partner node ──────────────────────────────────── */
.ce-node {
  background: #fff;
  border: 2.5px solid var(--brand);
  border-radius: 10px; overflow: hidden;
  min-width: 160px; max-width: 200px;
  box-shadow: 0 2px 8px rgba(0,0,0,.09);
  transition: box-shadow .15s;
}

.ce-node-selected {
  box-shadow: 0 0 0 3px rgba(41,128,185,.35), 0 4px 16px rgba(0,0,0,.15);
}

.ce-node-header {
  padding: .4rem .65rem;
  color: #fff; display: flex; align-items: center; gap: 5px;
}

.ce-node-name {
  font-weight: 700; font-size: .84rem; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.ce-node-type-badge {
  font-size: .62rem; opacity: .85;
  background: rgba(255,255,255,.25); padding: 1px 6px;
  border-radius: 10px; white-space: nowrap;
}

.ce-node-body { padding: .4rem .65rem; }

.ce-flow-pill {
  display: inline-block; font-size: .7rem; padding: 1px 8px;
  border-radius: 4px; margin-right: 4px; margin-bottom: 3px;
}
.ce-flow-pill-in  { background: #ebf5fb; color: #2471a3; }
.ce-flow-pill-out { background: #eafaf1; color: #1a7d3f; }

.ce-node-hint { font-size: .7rem; color: #aaa; font-style: italic; }

/* ── Properties panel ─────────────────────────────────────── */
.ce-props-panel {
  width: 320px; min-width: 320px;
  background: #fff; border-left: 1px solid #dee2e6;
  display: flex; flex-direction: column; overflow: hidden;
}

.ce-props-header {
  padding: .75rem 1rem;
  background: var(--accent); border-bottom: 1px solid #dee2e6;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}

.ce-props-body {
  flex: 1; overflow-y: auto; padding: 1rem;
}

.ce-props-footer {
  padding: .75rem 1rem; border-top: 1px solid #dee2e6; flex-shrink: 0;
}

.ce-label {
  display: block; font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .4px;
  color: #666; margin-bottom: 3px;
}

.ce-section-label {
  font-size: .78rem; font-weight: 700; color: #444;
  background: #f8f9fa; padding: .4rem .7rem;
  border-radius: 6px; margin-bottom: .5rem; margin-top: .25rem;
}

.ce-flow-item {
  border: 1px solid #e9ecef;
  border-left: 3px solid #2471a3;
  border-radius: 6px; padding: .6rem; margin-bottom: .5rem;
  background: #fafafa;
}
