:root {
  --accent: #6366f1;
  --bg: #f7f7f8;
  --panel: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --danger: #dc2626;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: inherit; text-decoration: none; }
.link { color: var(--accent); font-weight: 600; text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Shell / sidebar ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; }
.brand-mark, .brand-mark.large {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
}
.brand-mark.large { width: 56px; height: 56px; font-size: 24px; border-radius: 14px; }
.brand-logo { width: 32px; height: 32px; border-radius: 8px; object-fit: cover; }
.brand-name { font-weight: 700; font-size: 15px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-item {
  padding: 9px 10px; border-radius: 8px; font-size: 14px; font-weight: 500;
  color: var(--text); display: block;
}
.nav-item:hover { background: #f3f4f6; }
.nav-item.active { background: color-mix(in srgb, var(--accent) 12%, white); color: var(--accent); font-weight: 700; }
.nav-item.nav-sub { padding-left: 22px; font-size: 13.5px; }
.nav-sub-label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 14px 10px 4px; }

.sidebar-footer { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 6px 8px; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: #e5e7eb;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.user-name { font-size: 13.5px; font-weight: 600; }
.user-role { font-size: 11.5px; color: var(--muted); }
.link-btn {
  background: none; border: none; color: var(--muted); font-size: 12.5px; cursor: pointer;
  padding: 6px 8px; width: 100%; text-align: left;
}
.link-btn:hover { color: var(--text); }
.link-btn.danger { color: var(--danger); }

.main { flex: 1; min-width: 0; overflow-y: auto; }
.page { max-width: 980px; margin: 0 auto; padding: 32px 28px 60px; }
.page-flush { max-width: 980px; margin: 0 auto; padding: 32px 28px 0; height: calc(100vh - 32px); display: flex; flex-direction: column; }
.page-head { margin-bottom: 24px; }
.page-head.row, .page-head.row + * { }
.page-head.row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.page-head h1 { margin: 0 0 4px; font-size: 24px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 28px 0 12px; }
.section-head h2 { margin: 0; font-size: 16px; }

/* ---------- Stats / cards ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 8px; }
.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-value { font-size: 26px; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 13px; margin-top: 2px; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.client-card, .proposal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; display: block; transition: box-shadow .15s, transform .15s;
}
.client-card:hover, .proposal-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.06); transform: translateY(-1px); }
.client-card-avatar {
  width: 36px; height: 36px; border-radius: 8px; background: color-mix(in srgb, var(--accent) 15%, white);
  color: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; margin-bottom: 10px;
}
.client-card-name { font-weight: 600; }
.client-card-contact { color: var(--muted); font-size: 13px; margin-top: 2px; }
.proposal-card-title { font-weight: 600; margin-bottom: 6px; }
.proposal-card-amount { color: var(--muted); font-size: 14px; margin-bottom: 10px; }

/* ---------- Buttons / forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 8px; padding: 9px 16px; font-size: 14px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(0.94); }
.btn-secondary { background: #fff; border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: #f3f4f6; }
.btn-block { width: 100%; }

.stacked-form { display: flex; flex-direction: column; gap: 12px; }
.stacked-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: #374151; }
.stacked-form input, .stacked-form textarea, .stacked-form select {
  font: inherit; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
.inline-form { display: flex; gap: 8px; margin-bottom: 20px; }
.inline-form input[type=text], .inline-form input[type=date] {
  flex: 1; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font: inherit;
}

.two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }
.side-panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.side-panel h3 { margin-top: 0; }
.side-panel.span-2 { grid-column: 1 / -1; }

.logo-preview { max-width: 140px; max-height: 60px; display: block; margin-bottom: 14px; border-radius: 6px; }
.alert-success { background: #dcfce7; color: #166534; }
.connection-status { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 10px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; display: inline-block; }
.folder-status { margin-bottom: 10px; font-size: 14px; }
.folder-status p { margin: 0 0 8px; }

.quota-bar-wrap { margin-bottom: 14px; max-width: 360px; }
.quota-bar { height: 8px; border-radius: 999px; background: #eef0f2; overflow: hidden; }
.quota-bar.mini { height: 5px; margin-bottom: 3px; }
.quota-bar-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .2s; }
.quota-bar-fill.quota-bar-danger { background: var(--danger); }
.quota-label { margin-top: 4px; }
.storage-limit-form { display: flex; gap: 4px; margin-top: 4px; align-items: center; }
.storage-limit-form input { width: 72px; padding: 4px 6px; font-size: 12px; border: 1px solid var(--border); border-radius: 6px; font: inherit; }
.storage-limit-form .link-btn { width: auto; padding: 4px 6px; color: var(--accent); font-weight: 600; }

.file-preview { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-top: 4px; }
.image-preview { text-align: center; padding: 16px; }
.image-preview img { max-width: 100%; max-height: 70vh; border-radius: 8px; }
.pdf-preview { height: 75vh; }
.pdf-preview iframe { width: 100%; height: 100%; border: 0; }

.collapsible { margin-bottom: 20px; }
.collapsible summary { list-style: none; cursor: pointer; width: fit-content; }
.collapsible summary::-webkit-details-marker { display: none; }
.card-form { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-top: 12px; max-width: 480px; }

/* ---------- Table ---------- */
.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; background: #fafafa; }
.table tr:last-child td { border-bottom: none; }
.row-link { cursor: pointer; }
.row-link:hover { background: #fafafa; }
.row-done td { opacity: .55; text-decoration: line-through; }
.status-form select { border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; font: inherit; }

/* ---------- Status badges ---------- */
.status-badge {
  display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
  text-transform: capitalize; background: #f3f4f6; color: #4b5563;
}
.status-sent, .status-badge.status-sent { background: #fef3c7; color: #92400e; }
.status-viewed, .status-badge.status-viewed { background: #dbeafe; color: #1e40af; }
.status-signed, .status-badge.status-signed { background: #dcfce7; color: #166534; }
.status-declined, .status-badge.status-declined { background: #fee2e2; color: #991b1b; }

/* ---------- Calendar ---------- */
.calendar-list { display: flex; flex-direction: column; gap: 10px; }
.calendar-day { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.calendar-day-label { font-weight: 700; font-size: 13px; margin-bottom: 8px; }
.calendar-task { padding: 6px 10px; border-radius: 6px; background: #f3f4f6; margin-bottom: 6px; font-size: 14px; }

/* ---------- Chat ---------- */
.chat-wrap { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-thread { flex: 1; overflow-y: auto; padding: 6px 2px 20px; display: flex; flex-direction: column; gap: 12px; }
.chat-msg { max-width: 70%; padding: 10px 12px; border-radius: 12px; background: #fff; border: 1px solid var(--border); }
.chat-msg.mine { align-self: flex-end; background: color-mix(in srgb, var(--accent) 10%, white); border-color: color-mix(in srgb, var(--accent) 30%, white); }
.chat-msg-meta { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.chat-msg-body { font-size: 14px; white-space: pre-wrap; }
.chat-attachment { display: inline-block; margin-top: 6px; font-size: 13px; color: var(--accent); font-weight: 600; }
.chat-composer { display: flex; gap: 8px; align-items: center; padding: 14px 0 24px; border-top: 1px solid var(--border); }
.chat-composer input[type=text] { flex: 1; padding: 10px 14px; border: 1px solid var(--border); border-radius: 999px; font: inherit; }
.attach-btn { cursor: pointer; padding: 8px; }

/* ---------- Proposal detail ---------- */
.back-link { display: inline-block; margin-bottom: 14px; }
.proposal-content { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin: 16px 0; white-space: pre-wrap; line-height: 1.6; }
.signature-block { margin-top: 24px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; max-width: 560px; }
.sig-pad { border: 1px dashed var(--border); border-radius: 8px; width: 100%; max-width: 500px; touch-action: none; background: #fff; }
.sig-actions { margin: 8px 0; }
.sig-actions .btn { padding: 6px 12px; font-size: 13px; }
.signature-img { max-width: 320px; border: 1px solid var(--border); border-radius: 8px; background: #fff; padding: 8px; }
.legal-note { line-height: 1.5; }

/* ---------- Auth ---------- */
.auth-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 20px; }
.auth-card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 32px; width: 100%; max-width: 380px; }
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand h1 { font-size: 19px; margin: 12px 0 2px; }
.auth-brand p { color: var(--muted); margin: 0; font-size: 13px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }
.auth-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: #374151; }
.auth-form input { font: inherit; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; }
.alert { background: #fee2e2; color: #991b1b; padding: 10px 12px; border-radius: 8px; font-size: 13.5px; margin-bottom: 4px; }

/* ---------- Empty states ---------- */
.empty-state { text-align: center; padding: 50px 20px; background: var(--panel); border: 1px dashed var(--border); border-radius: var(--radius); }
.empty-state.small { padding: 24px; text-align: left; }
.empty-icon { font-size: 30px; margin-bottom: 8px; }
.empty-state h2 { margin: 6px 0 6px; font-size: 17px; }
.empty-state p { color: var(--muted); max-width: 380px; margin: 0 auto 16px; }

.activity-list { display: flex; flex-direction: column; gap: 8px; }
.activity-item { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; font-size: 14px; display: flex; gap: 8px; }
.quick-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 10px; margin-top: 24px; }
.quick-link { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px; font-weight: 600; font-size: 14px; text-align: center; }
.quick-link:hover { background: #fafafa; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; overflow-x: auto; padding: 10px; }
  .nav { flex-direction: row; }
  .nav-sub-label { display: none; }
  .sidebar-footer { display: none; }
  .two-col { grid-template-columns: 1fr; }
}
