/* =============================================================
   Mirita — Design system
   Font: DM Sans (Google Fonts)
   Palette: dark navy + amber accent + system colours
   ============================================================= */

/* ── Variables ────────────────────────────────────────────── */
:root {
  --font-sans: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'DM Mono', 'Fira Mono', monospace;

  /* Brand */
  --brand-navy:    #0f1b2d;
  --brand-navy-2:  #1a2d47;
  --brand-amber:   #f59e0b;
  --brand-amber-2: #fbbf24;
  --brand-red:     #ef4444;
  --brand-teal:    #0d9488;
  --brand-blue:    #3b82f6;

  /* Surfaces */
  --surface-0:  #ffffff;
  --surface-1:  #f8f9fb;
  --surface-2:  #f1f4f8;
  --surface-3:  #e4e9f0;

  /* Text */
  --text-primary:   #0f1b2d;
  --text-secondary: #4a5568;
  --text-muted:     #8a9ab5;
  --text-inverse:   #ffffff;

  /* Border */
  --border-light: #e4e9f0;
  --border-mid:   #c5d0e0;

  /* Status */
  --success: #10b981;
  --warning: #f59e0b;
  --danger:  #ef4444;
  --info:    #3b82f6;

  /* Layout */
  --nav-height:      56px;
  --sidebar-width:   260px;
  --sidebar-r-width: 300px;
  --border-radius:   8px;
  --border-radius-lg:12px;
  --shadow-sm: 0 1px 3px rgba(15,27,45,.08);
  --shadow-md: 0 4px 16px rgba(15,27,45,.12);
}

/* ── Reset / base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--surface-1);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--brand-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ───────────────────────────────────────────────── */
.mirita-navbar {
  height: var(--nav-height);
  background: var(--brand-navy);
  border-bottom: 1px solid rgba(255,255,255,.08);
  padding: 0 1rem;
  position: sticky;
  top: 0;
  z-index: 1030;
}

.mirita-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-inverse) !important;
  text-decoration: none !important;
  flex-shrink: 0;
}

.brand-mark {
  width: 30px; height: 30px;
  background: var(--brand-amber);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; color: var(--brand-navy);
  flex-shrink: 0;
}

.brand-name {
  font-weight: 600;
  font-size: 16px;
  color: #fff;
  letter-spacing: -0.2px;
}

/* Breadcrumb in navbar */
.navbar-breadcrumb {
  font-size: 13px;
  color: rgba(255,255,255,.5);
}
.breadcrumb-link {
  color: rgba(255,255,255,.6);
  text-decoration: none;
  transition: color .15s;
}
.breadcrumb-link:hover { color: #fff; text-decoration: none; }
.breadcrumb-sep { font-size: 10px; color: rgba(255,255,255,.3); }
.breadcrumb-item.active { color: rgba(255,255,255,.9); }

/* User avatar button */
.user-menu-btn {
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.15);
  color: #fff;
  border-radius: 6px;
  padding: 4px 10px;
}
.user-menu-btn:hover { background: rgba(255,255,255,.18); color: #fff; border-color: rgba(255,255,255,.25); }

.user-avatar {
  width: 24px; height: 24px;
  background: var(--brand-amber);
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
  color: var(--brand-navy);
}

/* Flash messages */
.flash-container { position: sticky; top: var(--nav-height); z-index: 1020; }

/* ── Main layout ──────────────────────────────────────────── */
.mirita-main { min-height: calc(100vh - var(--nav-height)); }

/* Page headers */
.page-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.3px;
  margin-bottom: 4px;
  color: var(--text-primary);
}
.page-subtitle { font-size: 14px; }
.section-title { font-size: 16px; font-weight: 600; margin: 0; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--surface-0);
  border: 1px solid var(--border-light);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-footer {
  background: var(--surface-1);
  border-top: 1px solid var(--border-light);
  border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg);
  padding: 10px 16px;
}

/* Project card */
.project-card {
  display: block;
  transition: box-shadow .15s, transform .15s;
  color: inherit;
}
.project-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  text-decoration: none;
  color: inherit;
}
.project-card .card-body { padding: 20px; }

.project-icon {
  width: 40px; height: 40px;
  background: var(--brand-navy);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700;
  color: var(--brand-amber);
  flex-shrink: 0;
}
.project-icon-lg {
  width: 52px; height: 52px;
  font-size: 22px;
  border-radius: 12px;
}

.project-card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-primary);
}

/* Site card */
.site-card .card-body { padding: 20px; }
.site-icon {
  width: 36px; height: 36px;
  background: var(--surface-2);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.site-card-title { font-size: 15px; font-weight: 600; }

/* Member chips */
.member-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  padding: 4px 12px 4px 4px;
}
.member-chip-avatar {
  width: 24px; height: 24px;
  background: var(--brand-navy-2);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
  color: #fff;
}
.member-chip-name { font-size: 13px; font-weight: 500; }

/* Badges */
.bg-label-active      { background: #dcfce7; color: #15803d; }
.bg-label-archived    { background: #fef9c3; color: #854d0e; }
.bg-label-deleted     { background: #fee2e2; color: #991b1b; }
.bg-label-permission  { background: var(--surface-3); color: var(--text-secondary); }
.bg-label-view        { background: #eff6ff; color: #1d4ed8; }
.bg-label-comment     { background: #f0fdf4; color: #166534; }
.bg-label-edit        { background: #fff7ed; color: #c2410c; }
.bg-label-manage      { background: #fdf4ff; color: #7e22ce; }

/* Empty state */
.empty-state { padding: 48px 24px; }
.empty-state-icon {
  font-size: 48px;
  color: var(--text-muted);
  display: block;
  margin-bottom: 12px;
}
.empty-state-title { font-size: 18px; font-weight: 600; }

/* Error pages */
.error-code {
  font-size: 80px;
  font-weight: 700;
  color: var(--border-mid);
  line-height: 1;
  margin-bottom: 16px;
  font-variant-numeric: tabular-nums;
}
.error-title { font-size: 24px; font-weight: 600; }

/* ── Auth page ────────────────────────────────────────────── */
.mirita-auth-page {
  background: var(--brand-navy);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-container { width: 100%; max-width: 400px; }
.auth-card {
  background: var(--surface-0);
  border-radius: var(--border-radius-lg);
  padding: 36px 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.auth-brand-mark {
  width: 40px; height: 40px;
  background: var(--brand-amber);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700;
  color: var(--brand-navy);
}
.auth-brand-name { font-size: 20px; font-weight: 700; display: block; }
.auth-brand-tagline { font-size: 12px; color: var(--text-muted); display: block; }
.auth-title { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.auth-subtitle { color: var(--text-secondary); font-size: 14px; margin-bottom: 24px; }
.auth-footer {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 24px;
  margin-bottom: 0;
  line-height: 1.6;
}
.btn-sign-in { height: 42px; font-weight: 600; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn-primary {
  background: var(--brand-navy);
  border-color: var(--brand-navy);
  color: #fff;
  font-weight: 500;
}
.btn-primary:hover, .btn-primary:focus {
  background: var(--brand-navy-2);
  border-color: var(--brand-navy-2);
  color: #fff;
}
.btn-outline-secondary { border-color: var(--border-mid); color: var(--text-secondary); }
.btn-outline-secondary:hover { background: var(--surface-2); border-color: var(--border-mid); color: var(--text-primary); }

/* ── File dropzone ────────────────────────────────────────── */
.file-dropzone {
  border: 2px dashed var(--border-mid);
  border-radius: var(--border-radius-lg);
  padding: 40px 24px;
  text-align: center;
  transition: border-color .2s, background .2s;
  cursor: pointer;
}
.file-dropzone.dragover {
  border-color: var(--brand-blue);
  background: #eff6ff;
}
.file-dropzone-icon { font-size: 40px; color: var(--text-muted); display: block; margin-bottom: 8px; }
.file-dropzone-label { font-weight: 500; }
.file-selected-name { font-weight: 500; font-size: 15px; }

/* ── Canvas workspace ─────────────────────────────────────── */
.mirita-canvas-page .mirita-main {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--nav-height));
  overflow: hidden;
}

.canvas-workspace {
  display: flex;
  flex: 1;
  height: 100%;
  overflow: hidden;
}

/* Left sidebar */
.sidebar-left {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--surface-0);
  border-right: 1px solid var(--border-light);
  display: flex;
  height: 100%;
  overflow: hidden;
}

.sidebar-tabs {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 6px;
  border-right: 1px solid var(--border-light);
  background: var(--surface-1);
}

.sidebar-tab {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border: none;
  background: transparent;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.sidebar-tab:hover { background: var(--surface-2); color: var(--text-primary); }
.sidebar-tab.active { background: var(--brand-navy); color: var(--brand-amber); }

/* Sidebar panels */
.sidebar-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
.sidebar-panel.active { display: flex; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}
.panel-title { font-size: 13px; font-weight: 600; }

/* Layer list */
.layer-list { padding: 8px; overflow-y: auto; flex: 1; }
.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .1s;
}
.layer-item:hover { background: var(--surface-2); }
.layer-visibility-btn {
  border: none; background: none; padding: 0;
  color: var(--text-muted); cursor: pointer; font-size: 14px;
  flex-shrink: 0;
}
.layer-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.layer-name { font-size: 13px; font-weight: 500; }

/* Symbol grid */
.symbol-grid {
  padding: 8px;
  overflow-y: auto;
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  align-content: start;
}
.symbol-item {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  cursor: grab;
  padding: 6px;
  background: var(--surface-0);
  transition: background .1s, border-color .1s;
  font-size: 11px;
  text-align: center;
  color: var(--text-secondary);
}
.symbol-item:hover { background: var(--surface-2); border-color: var(--brand-blue); color: var(--text-primary); }
.symbol-item img { width: 28px; height: 28px; object-fit: contain; }

/* Tools grid */
.tools-grid {
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  overflow-y: auto;
}
.tool-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  background: var(--surface-0);
  cursor: pointer;
  font-size: 10px;
  color: var(--text-secondary);
  transition: background .1s, border-color .1s;
}
.tool-btn i { font-size: 16px; }
.tool-btn:hover { background: var(--surface-2); border-color: var(--brand-blue); color: var(--text-primary); }
.tool-btn.active { background: var(--brand-navy); border-color: var(--brand-navy); color: var(--brand-amber); }

/* Filters */
.filter-section { padding: 10px 12px; border-bottom: 1px solid var(--border-light); }
.filter-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); margin-bottom: 8px; }
.filter-chip { display: flex; align-items: center; gap: 6px; padding: 3px 0; cursor: pointer; font-size: 13px; }
.filter-chip input { cursor: pointer; }

/* Device index */
.index-list { padding: 6px; overflow-y: auto; flex: 1; }

/* Right sidebar */
.sidebar-right {
  width: var(--sidebar-r-width);
  flex-shrink: 0;
  background: var(--surface-0);
  border-left: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.prop-panel-body { padding: 12px; overflow-y: auto; flex: 1; }

/* Canvas area */
.canvas-area {
  flex: 1;
  position: relative;
  background: #d0d7e0;
  overflow: hidden;
}

/* Zoom controls */
.zoom-controls {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 10;
}
.zoom-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-0);
  border: 1px solid var(--border-mid);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background .1s;
}
.zoom-btn:hover { background: var(--surface-2); }
.zoom-level-btn { font-size: 11px; font-weight: 600; width: 44px; }

/* Highlight bar */
.highlight-bar {
  position: absolute;
  top: 10px; left: 50%; transform: translateX(-50%);
  background: var(--brand-navy);
  color: #fff;
  border-radius: 20px;
  padding: 4px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow-md);
  z-index: 10;
  font-size: 13px;
}
.highlight-bar .btn-link { color: rgba(255,255,255,.7); padding: 0 4px; }
.highlight-count { font-weight: 600; }

/* Search dropdown */
.search-bar-wrap { position: relative; }
.search-results-dropdown {
  position: absolute;
  top: calc(100% + 4px); left: 0;
  width: 340px;
  background: var(--surface-0);
  border: 1px solid var(--border-mid);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  z-index: 1040;
  max-height: 320px;
  overflow-y: auto;
}
.search-result-item {
  display: flex; align-items: center; gap-10px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  transition: background .1s;
}
.search-result-item:hover { background: var(--surface-1); }
.search-result-item:last-child { border-bottom: none; }

/* ── Forms ────────────────────────────────────────────────── */
.form-label { font-weight: 500; font-size: 13px; margin-bottom: 4px; }
.form-control, .form-select {
  border-color: var(--border-mid);
  font-size: 14px;
  border-radius: var(--border-radius);
}
.form-control:focus, .form-select:focus {
  border-color: var(--brand-navy);
  box-shadow: 0 0 0 3px rgba(15,27,45,.12);
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar-left  { width: 200px; }
  .sidebar-right { display: none; }
}
@media (max-width: 576px) {
  .sidebar-left { position: fixed; left: -100%; top: var(--nav-height); height: calc(100vh - var(--nav-height)); z-index: 200; transition: left .25s; }
  .sidebar-left.open { left: 0; }
}

/* ── Canvas height fix ────────────────────────────────────── */
.mirita-canvas-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.mirita-canvas-page .mirita-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: calc(100vh - 56px);
}

.canvas-workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
  height: 100%;
}

.canvas-area {
  flex: 1;
  position: relative;
  background: #d0d7e0;
  overflow: hidden;
  height: 100%;
}

#konvaContainer {
  width: 100%;
  height: 100%;
  display: block;
}

/* ── Canvas height fix ────────────────────────────────────── */
/* Only canvas pages get overflow:hidden — all other pages scroll normally */

body.canvas-body {
  overflow: hidden !important;
  height: 100vh !important;
}

body.canvas-body .mirita-app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.canvas-body .mirita-canvas-page {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

body.canvas-body .mirita-canvas-page .mirita-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.canvas-workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

.canvas-area {
  flex: 1;
  position: relative;
  background: #d0d7e0;
  overflow: hidden;
  min-height: 0;
}

#konvaContainer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

body.canvas-body .sidebar-left {
  height: 100%;
  overflow: hidden;
  flex-shrink: 0;
}

.zoom-controls {
  position: absolute;
  bottom: 16px;
  right: 16px;
  z-index: 10;
}

/* Normal pages — allow scroll */
body:not(.canvas-body) {
  overflow: auto;
  height: auto;
}

body:not(.canvas-body) .mirita-main {
  overflow: auto;
  height: auto;
  min-height: calc(100vh - 56px);
}



/* ── Symbol library grid (updated) ───────────────────────── */
.symbol-grid {
  padding: 6px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.symbol-category-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
  padding: 8px 4px 4px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 4px;
}

.symbol-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: grab;
  transition: background .1s;
  font-size: 12px;
  color: var(--text-secondary);
  user-select: none;
}

.symbol-item:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}

.symbol-item:active { cursor: grabbing; }

.symbol-item-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 11px;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,.5);
}

.symbol-item-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
}

/* ── Search dropdown ──────────────────────────────────────── */
.search-bar-wrap {
  position: relative;
}

.search-results-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 380px;
  background: var(--surface-0);
  border: 1px solid var(--border-mid);
  border-radius: var(--border-radius-lg);
  box-shadow: 0 8px 32px rgba(15,27,45,.18);
  z-index: 1050;
  max-height: 360px;
  overflow-y: auto;
  padding: 4px;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .1s;
}

.search-result-item:hover,
.search-result-item.active {
  background: var(--surface-2);
}

.search-result-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.search-result-body {
  flex: 1;
  min-width: 0;
}

.search-result-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.search-result-name mark {
  background: #fef08a;
  color: #854d0e;
  border-radius: 2px;
  padding: 0 1px;
}

.search-result-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  flex-shrink: 0;
  white-space: nowrap;
}

.search-empty {
  padding: 16px 14px;
  font-size: 13px;
  color: var(--text-muted);
}

/* Highlight bar */
.highlight-bar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--brand-navy);
  color: #fff;
  border-radius: 20px;
  padding: 5px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(15,27,45,.25);
  z-index: 20;
  font-size: 13px;
  white-space: nowrap;
}

.highlight-bar .btn-link {
  color: rgba(255,255,255,.7);
  padding: 0 4px;
  font-size: 13px;
  line-height: 1;
}

.highlight-bar .btn-link:hover { color: #fff; }
.highlight-count { font-weight: 600; }
