/* Kevytjuridiikka — App Shell, Layout, Components
 * Clean build — zero crypto, zero WASM engine logic.
 * Uses VRU Runtime v1 HTTP API for all VRU operations.
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: #111;
  color: rgba(255,255,255,0.85);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  height: 100vh;
}

/* ── APP SHELL ──────────────────────────────────────────────────── */
#app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

#app-nav { display: contents; }
#app-nav[hidden] { display: none; }

/* ── SIDEBAR ────────────────────────────────────────────────────── */
.sidebar {
  width: 216px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: rgba(255,255,255,0.02);
  border-right: 1px solid rgba(255,255,255,0.06);
  height: 100vh;
  overflow: hidden;
}

.sidebar-logo {
  padding: 20px 18px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  background: none;
  border-left: none; border-right: none; border-top: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  color: inherit;
  font-family: inherit;
}
.sidebar-logo-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: rgba(74,222,128,0.15);
  border: 1px solid rgba(74,222,128,0.25);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: #4ade80;
  flex-shrink: 0; letter-spacing: -0.03em;
}
.sidebar-logo-name {
  font-size: 13px; font-weight: 700;
  color: rgba(255,255,255,0.85);
}
.sidebar-logo-tag {
  font-size: 9px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em;
  color: rgba(255,255,255,0.25); margin-top: 1px;
}

.sidebar-nav {
  flex: 1;
  padding: 10px;
  overflow-y: auto;
}

.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: 8px;
  font-size: 13px; font-weight: 500;
  color: rgba(255,255,255,0.45);
  text-decoration: none; cursor: pointer;
  transition: all 0.12s; margin-bottom: 2px;
  border: none; background: none; font-family: inherit; width: 100%;
  text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: rgba(255,255,255,0.75); }
.nav-item.active {
  background: rgba(255,255,255,0.07);
  color: rgba(255,255,255,0.9);
  font-weight: 600;
}
.nav-item-icon { width: 16px; text-align: center; font-size: 14px; flex-shrink: 0; }

.sidebar-user {
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,0.06);
  display: flex; align-items: center; gap: 10px;
  cursor: pointer; transition: background 0.12s;
}
.sidebar-user:hover { background: rgba(255,255,255,0.03); }
.sidebar-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  background: rgba(255,255,255,0.08);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: rgba(255,255,255,0.6);
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  font-size: 12px; font-weight: 600; color: rgba(255,255,255,0.8);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-role { font-size: 10px; color: rgba(255,255,255,0.3); }

.sidebar-signout {
  width: 100%; padding: 9px 14px;
  background: none; border: none; border-top: 1px solid rgba(255,255,255,0.04);
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: rgba(255,255,255,0.3);
  cursor: pointer; transition: color 0.12s, background 0.12s;
  text-align: left; font-family: inherit;
}
.sidebar-signout:hover { color: rgba(239,68,68,0.8); background: rgba(239,68,68,0.05); }

/* ── MAIN CONTENT ───────────────────────────────────────────────── */
#app-content {
  flex: 1; min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.page-wrap {
  padding: 32px 40px;
  max-width: 1080px;
}

.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 28px; gap: 16px;
}
.page-title {
  font-size: 20px; font-weight: 700; color: rgba(255,255,255,0.92);
  letter-spacing: -0.01em;
}
.page-sub {
  font-size: 13px; color: rgba(255,255,255,0.35); margin-top: 3px;
}
.page-header-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

/* ── BOOT / AUTH ────────────────────────────────────────────────── */
.boot-center {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#app-shell:has(.sidebar) .boot-center { min-height: 100%; }

.boot-spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.08);
  border-top-color: #4ade80;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.view-loading {
  height: 40px;
  display: flex; align-items: center; justify-content: center;
}
.view-loading::after {
  content: '';
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.06);
  border-top-color: rgba(74,222,128,0.5);
  animation: spin 0.8s linear infinite;
}

.signin-card {
  width: 400px; max-width: 100%;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px; padding: 36px 32px;
}
.signin-logo {
  display: flex; align-items: center; gap: 10px; margin-bottom: 32px;
}
.signin-logo-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: rgba(74,222,128,0.15); border: 1px solid rgba(74,222,128,0.25);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 800; color: #4ade80;
}
.signin-logo-name { font-size: 16px; font-weight: 700; color: rgba(255,255,255,0.9); }
.signin-title {
  font-size: 18px; font-weight: 700; color: rgba(255,255,255,0.9); margin-bottom: 6px;
}
.signin-sub { font-size: 13px; color: rgba(255,255,255,0.4); margin-bottom: 24px; line-height: 1.5; }
#clerk-signin-root { min-height: 80px; }

/* ── BUTTONS ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s; font-family: inherit;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn-primary {
  background: rgba(74,222,128,0.15); border-color: rgba(74,222,128,0.25);
  color: #4ade80;
}
.btn-primary:hover { background: rgba(74,222,128,0.25); }
.btn-secondary {
  background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.7);
}
.btn-secondary:hover { background: rgba(255,255,255,0.1); }
.btn-danger {
  background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.2);
  color: #f87171;
}
.btn-danger:hover { background: rgba(239,68,68,0.2); }

/* ── CARDS ──────────────────────────────────────────────────────── */
.card {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 24px;
}
.card-title {
  font-size: 14px; font-weight: 600; color: rgba(255,255,255,0.8);
  margin-bottom: 12px;
}

/* ── BADGES ─────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 6px;
  letter-spacing: 0.02em;
}
.badge-dot {
  width: 5px; height: 5px; border-radius: 50%;
  display: inline-block;
}
.badge-gray { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.4); }
.badge-gray .badge-dot { background: rgba(255,255,255,0.3); }
.badge-green { background: rgba(74,222,128,0.12); color: #4ade80; }
.badge-green .badge-dot { background: #4ade80; }
.badge-yellow { background: rgba(250,204,21,0.12); color: #facc15; }
.badge-yellow .badge-dot { background: #facc15; }
.badge-blue { background: rgba(96,165,250,0.12); color: #60a5fa; }
.badge-blue .badge-dot { background: #60a5fa; }

/* ── DOCUMENT GRID ──────────────────────────────────────────────── */
.doc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}

.doc-card {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
}
.doc-card:hover {
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.12);
}
.doc-card-stripe {
  width: 4px; flex-shrink: 0;
}
.doc-card-stripe.status-draft { background: rgba(255,255,255,0.15); }
.doc-card-stripe.status-review { background: rgba(250,204,21,0.5); }
.doc-card-stripe.status-signing { background: rgba(96,165,250,0.5); }
.doc-card-stripe.status-complete,
.doc-card-stripe.status-signed,
.doc-card-stripe.status-sealed,
.doc-card-stripe.status-closed { background: rgba(74,222,128,0.5); }

.doc-card-body { padding: 16px; flex: 1; min-width: 0; }
.doc-card-header {
  display: flex; align-items: center; gap: 10px;
}
.doc-card-icon { font-size: 22px; flex-shrink: 0; }
.doc-card-title {
  font-size: 14px; font-weight: 600; color: rgba(255,255,255,0.85);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.doc-card-schema { font-size: 11px; color: rgba(255,255,255,0.3); margin-top: 1px; }
.doc-card-meta {
  margin-top: 10px; font-size: 11px; color: rgba(255,255,255,0.3);
  display: flex; gap: 12px;
}

/* ── DOCUMENT TYPE PICKER ───────────────────────────────────────── */
.doc-type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.doc-type-card {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 24px 20px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}
.doc-type-card:hover:not(.disabled) {
  background: rgba(255,255,255,0.06);
  border-color: rgba(74,222,128,0.3);
}
.doc-type-card.disabled {
  opacity: 0.4; cursor: default;
}
.doc-type-card-icon { font-size: 32px; margin-bottom: 12px; }
.doc-type-card-label {
  font-size: 14px; font-weight: 600; color: rgba(255,255,255,0.85);
  margin-bottom: 4px;
}
.doc-type-card-desc {
  font-size: 12px; color: rgba(255,255,255,0.35); line-height: 1.4;
}
.doc-type-card-badge { margin-top: 10px; }

/* ── EMPTY STATE ────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
}
.empty-state-icon { font-size: 40px; margin-bottom: 16px; }
.empty-state-title {
  font-size: 16px; font-weight: 600; color: rgba(255,255,255,0.7);
  margin-bottom: 6px;
}
.empty-state-sub {
  font-size: 13px; color: rgba(255,255,255,0.35); line-height: 1.5;
}

/* ── MODAL ──────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal-backdrop[hidden] { display: none !important; }
.modal-card {
  background: #1a1a2e; border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px; padding: 32px; width: 100%; max-width: 440px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}
.modal-header { margin-bottom: 24px; }
.modal-title { font-size: 20px; font-weight: 600; color: #fff; }
.modal-sub { font-size: 13px; color: rgba(255,255,255,0.45); margin-top: 4px; }
.modal-form { display: flex; flex-direction: column; gap: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.field-label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: rgba(255,255,255,0.6); }
.field-label .req { color: #f87171; }
.field-input {
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px; padding: 10px 12px; color: #fff; font-size: 14px; outline: none;
  transition: border-color 0.15s; font-family: inherit;
}
.field-input:focus { border-color: rgba(139,92,246,0.6); }
.field-input::placeholder { color: rgba(255,255,255,0.2); }

/* ── TOAST ──────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.15);
  backdrop-filter: blur(16px);
  color: rgba(255,255,255,0.9); font-size: 13px; font-weight: 500;
  padding: 10px 20px; border-radius: 10px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 200;
}
#toast.show {
  opacity: 1; transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

/* ── SCROLLBAR ──────────────────────────────────────────────────── */
#app-content::-webkit-scrollbar { width: 6px; }
#app-content::-webkit-scrollbar-track { background: transparent; }
#app-content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }
#app-content::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.14); }

/* ── RESPONSIVE ─────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .doc-grid { grid-template-columns: 1fr; }
  .doc-type-grid { grid-template-columns: 1fr 1fr; }
  .page-wrap { padding: 20px 16px; }
}
@media (max-width: 700px) {
  .sidebar { display: none; }
  .page-header { flex-direction: column; }
  .doc-type-grid { grid-template-columns: 1fr; }
}

/* ── UTILITY ────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-muted { color: rgba(255,255,255,0.35); font-size: 12px; }
