:root {
  --ricavi-navy: #000f23;
  --ricavi-dark: #242a36;
  --ricavi-blue: #1a5ce0;
  --ricavi-blue-light: #0693e3;
  --ricavi-green: #00d084;
  --ricavi-green-soft: #7bdcb5;
  --ricavi-bg: #f8fafc;
  --ricavi-surface: #ffffff;
  --ricavi-border: #e2e8f0;
  --ricavi-text: #1a1a1a;
  --ricavi-muted: #67757f;
  --ricavi-shadow: 0 4px 24px rgba(0, 15, 35, 0.08);
  --ricavi-radius: 12px;
  --font-sans: "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font-sans);
  color: var(--ricavi-text);
  background: var(--ricavi-bg);
}

a {
  color: var(--ricavi-blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--ricavi-surface);
  border-bottom: 1px solid var(--ricavi-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand img {
  height: 42px;
  width: auto;
}

.brand span {
  font-weight: 700;
  color: var(--ricavi-navy);
  font-size: 1.05rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--ricavi-muted);
  font-size: 0.9rem;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

.page-title {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
  color: var(--ricavi-navy);
}

.page-subtitle {
  margin: 0 0 1.5rem;
  color: var(--ricavi-muted);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
}

.tile-sortable {
  position: relative;
  min-width: 0;
}

.tile-sortable.tile-dragging {
  opacity: 0.75;
  z-index: 5;
}

.tile-sortable.tile-dragging .tile {
  pointer-events: none;
  cursor: grabbing;
}

body.dashboard-tiles-dragging {
  cursor: grabbing;
  user-select: none;
}

.tile-sortable.tile-drag-over .tile {
  border-color: var(--ricavi-blue);
  box-shadow: 0 0 0 2px rgba(26, 92, 224, 0.2);
}

.tile-drag-handle {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--ricavi-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: grab;
  touch-action: none;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.1);
}

.tile-drag-handle:hover {
  color: var(--ricavi-blue);
  background: #fff;
}

.tile-sortable.tile-dragging .tile-drag-handle {
  cursor: grabbing;
}

.tile-sortable .tile {
  height: 100%;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.5rem;
  background: var(--ricavi-surface);
  border: 1px solid var(--ricavi-border);
  border-radius: var(--ricavi-radius);
  box-shadow: var(--ricavi-shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  color: inherit;
  text-decoration: none;
}

.tile:hover {
  transform: translateY(-2px);
  border-color: var(--ricavi-blue-light);
  box-shadow: 0 8px 32px rgba(26, 92, 224, 0.12);
  text-decoration: none;
}

.tile-icon-wrap {
  position: relative;
  width: fit-content;
}

.tile-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  background: linear-gradient(135deg, rgba(26, 92, 224, 0.12), rgba(0, 208, 132, 0.12));
  color: var(--ricavi-blue);
}

.tile-badge {
  position: absolute;
  top: -6px;
  right: -8px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: #e53935;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
  line-height: 22px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--ricavi-surface);
}

.tile-badge.hidden {
  display: none;
}

.tile h2 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--ricavi-navy);
}

.tile p {
  margin: 0;
  color: var(--ricavi-muted);
  line-height: 1.5;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.search-input,
.text-input,
.select-input,
textarea {
  width: 100%;
  max-width: 360px;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--ricavi-border);
  border-radius: 8px;
  font: inherit;
  background: var(--ricavi-surface);
}

textarea {
  max-width: 100%;
  min-height: 90px;
  resize: vertical;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1rem;
  border: none;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--ricavi-blue), var(--ricavi-blue-light));
  color: #fff;
}

.btn-primary:hover {
  filter: brightness(1.05);
  text-decoration: none;
}

.btn-secondary {
  background: var(--ricavi-surface);
  color: var(--ricavi-navy);
  border: 1px solid var(--ricavi-border);
}

.btn-danger {
  background: #cf2e2e;
  color: #fff;
}

.btn-link {
  background: transparent;
  color: var(--ricavi-blue);
  padding: 0;
}

.card {
  background: var(--ricavi-surface);
  border: 1px solid var(--ricavi-border);
  border-radius: var(--ricavi-radius);
  box-shadow: var(--ricavi-shadow);
  overflow: hidden;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--ricavi-border);
  text-align: left;
}

.table th {
  background: #f1f5f9;
  color: var(--ricavi-navy);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.table tr:hover td {
  background: #fafcff;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover td {
  background: #f0f6ff;
}

.clickable-row:focus {
  outline: none;
}

.clickable-row:focus td {
  background: #e8f0fe;
  box-shadow: inset 0 0 0 2px var(--ricavi-blue-light);
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-yes {
  background: rgba(0, 208, 132, 0.15);
  color: #047857;
}

.badge-no {
  background: rgba(103, 117, 127, 0.15);
  color: var(--ricavi-muted);
}

.alert {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.alert-success {
  background: rgba(0, 208, 132, 0.12);
  color: #065f46;
  border: 1px solid rgba(0, 208, 132, 0.25);
}

.alert-error {
  background: rgba(207, 46, 46, 0.1);
  color: #991b1b;
  border: 1px solid rgba(207, 46, 46, 0.2);
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #000f23 0%, #242a36 45%, #f8fafc 45%);
  padding: 1rem;
}

.login-card {
  width: min(420px, 100%);
  background: var(--ricavi-surface);
  border-radius: var(--ricavi-radius);
  box-shadow: var(--ricavi-shadow);
  padding: 2rem;
}

.login-card .brand {
  justify-content: center;
  margin-bottom: 1.5rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
  color: var(--ricavi-navy);
  font-size: 0.9rem;
}

.form-group .text-input {
  max-width: 100%;
}

.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--ricavi-muted);
  margin: 1.25rem 0;
  font-size: 0.85rem;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--ricavi-border);
}

.btn-google {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.65rem 1rem;
  border: 1px solid var(--ricavi-border);
  border-radius: 8px;
  background: #fff;
  color: #3c4043;
  font-weight: 600;
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(60, 64, 67, 0.15);
}

.btn-google:hover {
  background: #f8f9fa;
  text-decoration: none;
  color: #202124;
}

.btn-google-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.settings-layout {
  display: grid;
  gap: 1rem;
}

.category-card {
  background: var(--ricavi-surface);
  border: 1px solid var(--ricavi-border);
  border-radius: var(--ricavi-radius);
  overflow: hidden;
}

.category-header {
  padding: 1rem 1.25rem;
  background: linear-gradient(90deg, rgba(26, 92, 224, 0.08), rgba(0, 208, 132, 0.06));
  border-bottom: 1px solid var(--ricavi-border);
}

.category-header h2 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--ricavi-navy);
}

.section-block {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--ricavi-border);
}

.section-block:last-child {
  border-bottom: none;
}

.section-block h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  color: var(--ricavi-dark);
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem 1rem;
  align-items: center;
}

.settings-grid .label {
  color: var(--ricavi-text);
  font-size: 0.92rem;
}

.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  display: inline-block;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-slider {
  background: var(--ricavi-green);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.vat-block {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--ricavi-border);
}

.vat-block h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  color: var(--ricavi-navy);
}

.vat-row {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 0.5rem 1rem;
  margin-bottom: 0.5rem;
  align-items: start;
}

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
}

.checkbox-group label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
}

.sticky-footer {
  position: sticky;
  bottom: 0;
  background: rgba(248, 250, 252, 0.95);
  backdrop-filter: blur(6px);
  border-top: 1px solid var(--ricavi-border);
  padding: 1rem 0;
  margin-top: 1rem;
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin-bottom: 1rem;
  color: var(--ricavi-muted);
  font-size: 0.9rem;
}

.breadcrumb a {
  color: var(--ricavi-blue);
}

.folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.folder-card {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 1rem;
  background: #f8fafc;
  border: 1px solid var(--ricavi-border);
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
}

.folder-card:hover {
  border-color: var(--ricavi-blue-light);
  background: #fff;
  text-decoration: none;
}

.folder-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.folder-mgmt-panel {
  padding: 1rem 1.25rem;
  margin: 0 0 1rem;
  border-color: rgba(207, 46, 46, 0.25);
}

.folder-mgmt-warning {
  color: #9b2c2c;
  margin: 0 0 1rem;
}

.folder-delete-form {
  margin: 0;
}

.client-meta-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}

.client-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.client-meta-edit {
  margin-bottom: 1rem;
}

.meta-item-wide {
  grid-column: span 2;
}

.meta-item-editable:focus-within {
  border-color: var(--ricavi-blue-light);
  box-shadow: 0 0 0 3px rgba(26, 92, 224, 0.1);
}

.meta-item-static {
  opacity: 0.85;
}

.meta-item-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: transparent;
  border: none;
  padding: 0.25rem 0;
}

.meta-input {
  display: block;
  width: 100%;
  margin-top: 0.15rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--ricavi-border);
  border-radius: 6px;
  font: inherit;
  color: var(--ricavi-navy);
  background: #fff;
}

.meta-textarea {
  resize: vertical;
  min-height: 2.5rem;
}

.meta-input:focus {
  outline: none;
  border-color: var(--ricavi-blue-light);
  box-shadow: 0 0 0 2px rgba(26, 92, 224, 0.12);
}

.meta-item {
  background: var(--ricavi-surface);
  border: 1px solid var(--ricavi-border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.meta-item small {
  display: block;
  color: var(--ricavi-muted);
  margin-bottom: 0.2rem;
}

.client-tabs {
  display: flex;
  gap: 0.5rem;
  margin: 1.25rem 0;
  border-bottom: 1px solid var(--ricavi-border);
}

.client-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem 1rem;
  color: var(--ricavi-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-weight: 600;
}

.client-tab:hover {
  color: var(--ricavi-blue);
  text-decoration: none;
}

.client-tab.active {
  color: var(--ricavi-blue);
  border-bottom-color: var(--ricavi-blue);
}

.tab-count {
  background: rgba(26, 92, 224, 0.12);
  color: var(--ricavi-blue);
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
  font-size: 0.75rem;
}

.comments-section .section-hint {
  margin: 0.35rem 0 0;
  color: var(--ricavi-muted);
  font-size: 0.9rem;
}

.comment-composer {
  display: flex;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--ricavi-border);
}

.comment-compose-form {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.comment-compose-form textarea,
.comment-reply-form textarea,
.comment-edit-form textarea {
  width: 100%;
  max-width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--ricavi-border);
  border-radius: 8px;
  font: inherit;
  resize: vertical;
  min-height: 80px;
}

.comments-feed {
  padding: 1rem 1.25rem 1.25rem;
}

.comments-empty {
  color: var(--ricavi-muted);
  margin: 0;
}

.comment {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.comment-reply {
  margin-top: 0.75rem;
}

.comment-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ricavi-blue), var(--ricavi-green));
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.comment-body-wrap {
  flex: 1;
  min-width: 0;
}

.comment-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.comment-author {
  color: var(--ricavi-navy);
}

.comment-time {
  color: var(--ricavi-muted);
  font-size: 0.85rem;
}

.comment-edited {
  color: var(--ricavi-muted);
  font-size: 0.8rem;
  font-style: italic;
}

.comment-text {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
  margin-bottom: 0.35rem;
}

.comment-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.75rem;
}

.comment-delete-form {
  margin: 0;
  display: inline;
}

.comment-action {
  font-size: 0.85rem;
  padding: 0;
}

.comment-action-danger {
  color: #cf2e2e;
}

.comment-form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.comment-reply-form,
.comment-edit-form {
  margin-top: 0.75rem;
}

.comment-replies {
  margin-top: 0.75rem;
  padding-left: 0.75rem;
  border-left: 3px solid rgba(26, 92, 224, 0.2);
}

.btn-sm {
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
}

.hidden {
  display: none !important;
}

.settings-section {
  margin-top: 0;
}

.client-tab-panel.hidden {
  display: none;
}

.data-empty {
  padding: 2rem 1.25rem;
  color: var(--ricavi-muted);
  text-align: center;
}

.data-empty p {
  margin: 0.5rem 0;
}

.client-tab-link {
  font-weight: 600;
}

.data-form {
  padding: 1rem 1.25rem 1.25rem;
}

.data-category {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--ricavi-border);
}

.data-category:last-of-type {
  border-bottom: none;
}

.data-category h3 {
  margin: 0 0 0.75rem;
  color: var(--ricavi-navy);
  font-size: 1.05rem;
}

.data-section h4 {
  margin: 0 0 0.65rem;
  color: var(--ricavi-dark);
  font-size: 0.92rem;
  font-weight: 600;
}

.data-field {
  margin-bottom: 1rem;
}

.data-field label {
  display: block;
  font-weight: 600;
  color: var(--ricavi-navy);
  margin-bottom: 0.35rem;
  font-size: 0.92rem;
}

.data-field textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--ricavi-border);
  border-radius: 8px;
  font: inherit;
  resize: vertical;
  min-height: 72px;
  background: #fafcff;
}

.data-field textarea:focus {
  outline: none;
  border-color: var(--ricavi-blue-light);
  box-shadow: 0 0 0 3px rgba(26, 92, 224, 0.12);
}

.field-meta {
  margin: 0 0 0.35rem;
  font-size: 0.82rem;
  color: var(--ricavi-muted);
}

.data-form-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--ricavi-border);
}

.data-stats {
  color: var(--ricavi-muted);
  font-size: 0.9rem;
}

.user-avatar {
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.user-avatar--sm {
  width: 32px;
  height: 32px;
}

.user-avatar--md {
  width: 40px;
  height: 40px;
}

.user-avatar--lg {
  width: 96px;
  height: 96px;
}

.user-avatar--initials {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--ricavi-blue), var(--ricavi-green));
  color: #fff;
  font-weight: 700;
}

.user-avatar--sm.user-avatar--initials {
  font-size: 0.7rem;
}

.user-avatar--md.user-avatar--initials {
  font-size: 0.8rem;
}

.user-avatar--lg.user-avatar--initials {
  font-size: 1.5rem;
}

.header-profile {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  color: var(--ricavi-navy);
  text-decoration: none;
}

.header-profile:hover {
  color: var(--ricavi-blue);
  text-decoration: none;
}

.profile-card {
  padding: 1.25rem;
  max-width: 640px;
}

.profile-photo-section {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--ricavi-border);
}

.profile-section-title {
  margin: 0 0 1rem;
  font-size: 1rem;
  color: var(--ricavi-navy);
}

.profile-photo-row {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.profile-photo-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
}

.profile-photo-form {
  margin: 0;
}

.profile-photo-label {
  cursor: pointer;
  margin: 0;
}

.profile-photo-input {
  display: none;
}

.profile-photo-hint {
  margin: 0;
  color: var(--ricavi-muted);
  font-size: 0.85rem;
}

.staff-chat-page .staff-chat-panel {
  display: flex;
  flex-direction: column;
  max-width: 900px;
  min-height: 60vh;
}

.staff-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  max-height: min(60vh, 640px);
  border-bottom: 1px solid var(--ricavi-border);
}

.staff-chat-message {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.staff-chat-message--mine .staff-chat-message-body {
  background: rgba(26, 92, 224, 0.06);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
}

.staff-chat-message-body {
  flex: 1;
  min-width: 0;
}

.staff-chat-composer {
  padding: 1rem 1.25rem 1.25rem;
}

.staff-chat-composer .comment-composer {
  margin: 0;
}

.chat-compose-actions {
  align-items: center;
  justify-content: space-between;
}

.emoji-picker-wrap {
  position: relative;
}

.emoji-picker {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 0.15rem;
  width: min(320px, 80vw);
  padding: 0.5rem;
  background: var(--ricavi-surface);
  border: 1px solid var(--ricavi-border);
  border-radius: 10px;
  box-shadow: var(--ricavi-shadow);
}

.emoji-picker.hidden {
  display: none;
}

.emoji-btn {
  width: 100%;
  aspect-ratio: 1;
  border: none;
  border-radius: 6px;
  background: transparent;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.emoji-btn:hover {
  background: rgba(26, 92, 224, 0.1);
}

.chat-widget {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right, 0px));
  bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  z-index: 2147482000;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

.chat-widget--hidden {
  display: none !important;
}

.chat-fab {
  position: relative;
  width: 58px;
  height: 58px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--ricavi-blue), var(--ricavi-green));
  color: #fff;
  box-shadow: 0 10px 30px rgba(26, 92, 224, 0.35);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
  padding: 0;
}

.chat-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 34px rgba(26, 92, 224, 0.4);
}

.chat-fab-icon {
  width: 26px;
  height: 26px;
  display: block;
  pointer-events: none;
}

.chat-fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: #e53935;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
  line-height: 20px;
  text-align: center;
  box-shadow: 0 0 0 2px #fff;
}

.chat-fab-badge.hidden {
  display: none;
}

.chat-widget-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 0.85rem);
  width: min(360px, calc(100vw - 2rem));
  height: min(520px, calc(100vh - 6rem));
  display: flex;
  flex-direction: column;
  background: var(--ricavi-surface);
  border: 1px solid var(--ricavi-border);
  border-radius: 14px;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.18);
  overflow: hidden;
}

.chat-widget-panel.hidden {
  display: none;
}

.chat-widget-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--ricavi-border);
  background: linear-gradient(180deg, rgba(26, 92, 224, 0.05), transparent);
}

.chat-widget-title {
  margin: 0;
  font-size: 1rem;
  color: var(--ricavi-navy);
}

.chat-widget-subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--ricavi-muted);
}

.chat-widget-header-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.chat-widget-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ricavi-muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.chat-widget-close:hover {
  background: rgba(15, 23, 42, 0.06);
  color: var(--ricavi-navy);
}

.chat-widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.85rem 1rem;
}

.staff-chat-message--compact {
  margin-bottom: 0.75rem;
}

.staff-chat-message--compact .comment-header {
  margin-bottom: 0.2rem;
}

.staff-chat-message--compact .comment-author,
.staff-chat-message--compact .comment-time {
  font-size: 0.8rem;
}

.staff-chat-message--compact .comment-text {
  font-size: 0.92rem;
}

.chat-attachments {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.chat-attachment-image-link {
  display: inline-block;
  max-width: 100%;
}

.chat-attachment-image {
  display: block;
  max-width: min(320px, 100%);
  max-height: 240px;
  border-radius: 10px;
  border: 1px solid var(--ricavi-border);
  object-fit: contain;
  background: #fff;
}

.chat-attachment-file {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--ricavi-border);
  border-radius: 10px;
  background: var(--ricavi-bg);
  text-decoration: none;
  color: inherit;
}

.chat-attachment-file:hover {
  text-decoration: none;
  border-color: var(--ricavi-blue);
}

.chat-attachment-file-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.chat-attachment-file-meta strong {
  word-break: break-word;
}

.chat-attachment-file-meta small {
  color: var(--ricavi-muted);
}

.chat-file-label {
  cursor: pointer;
  margin: 0;
}

.chat-file-preview {
  margin-top: 0.35rem;
  font-size: 0.85rem;
  color: var(--ricavi-muted);
}

.chat-widget-error {
  margin: 0 1rem 0.5rem;
}

.chat-widget-composer {
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--ricavi-border);
}

.chat-widget-composer textarea {
  width: 100%;
  max-width: 100%;
  min-height: 64px;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--ricavi-border);
  border-radius: 8px;
  font: inherit;
  resize: vertical;
}

.chat-widget .emoji-picker {
  grid-template-columns: repeat(8, 1fr);
  width: min(280px, 70vw);
}

@media (max-width: 480px) {
  .chat-widget {
    right: max(0.85rem, env(safe-area-inset-right, 0px));
    bottom: max(0.85rem, env(safe-area-inset-bottom, 0px));
  }

  .chat-widget-panel {
    width: min(calc(100vw - 1.5rem), 360px);
    height: min(70vh, 520px);
    max-height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 5rem);
  }
}

.task-alert {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-weight: 800;
  font-size: 0.85rem;
  line-height: 1;
}

.task-alert-danger {
  background: #cf2e2e;
  color: #fff;
}

.task-alert-warning {
  background: #f59e0b;
  color: #1a1a1a;
}

.assignment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  padding: 1rem 1.25rem;
}

.task-add-form,
.project-add-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--ricavi-border);
}

.task-add-form .text-input,
.project-add-form .text-input,
.task-add-form .select-input {
  flex: 1;
  min-width: 160px;
  max-width: 100%;
}

.project-add-form textarea {
  width: 100%;
  padding: 0.65rem;
  border: 1px solid var(--ricavi-border);
  border-radius: 8px;
  font: inherit;
}

.checklist {
  list-style: none;
  margin: 0;
  padding: 0.75rem 1.25rem 1.25rem;
}

.checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--ricavi-border);
}

.checklist-item:last-child {
  border-bottom: none;
}

.checklist-item.completed .checklist-title {
  text-decoration: line-through;
  color: var(--ricavi-muted);
}

.checklist-toggle-form {
  margin: 0;
}

.checklist-check {
  width: 28px;
  height: 28px;
  border: 2px solid var(--ricavi-border);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--ricavi-green);
  display: grid;
  place-items: center;
  padding: 0;
}

.checklist-item.completed .checklist-check {
  background: rgba(0, 208, 132, 0.15);
  border-color: var(--ricavi-green);
}

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

.checklist-title {
  display: block;
  font-weight: 600;
  color: var(--ricavi-navy);
}

.checklist-body small {
  color: var(--ricavi-muted);
  font-size: 0.82rem;
}

.checklist-empty {
  color: var(--ricavi-muted);
  padding: 0.5rem 0;
}

.progress-wrap {
  padding: 0.75rem 1.25rem;
}

.progress-bar {
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.35rem;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--ricavi-blue), var(--ricavi-green));
  border-radius: 999px;
}

.progress-label {
  font-size: 0.85rem;
  color: var(--ricavi-muted);
}

.projects-list {
  display: grid;
  gap: 1rem;
}

.time-layout {
  display: grid;
  grid-template-columns: minmax(300px, 420px) 1fr;
  gap: 1rem;
  align-items: start;
}

.time-form-card,
.time-list-card {
  padding: 1.25rem;
}

.time-section-title {
  margin: 0 0 1rem;
  color: var(--ricavi-navy);
  font-size: 1.1rem;
}

.time-entry-form textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--ricavi-border);
  border-radius: 8px;
  font: inherit;
  resize: vertical;
  min-height: 96px;
}

.time-desc-cell {
  max-width: 280px;
  white-space: pre-wrap;
  word-break: break-word;
}

.table-wrap {
  overflow-x: auto;
}

.doc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.doc-delete-form {
  margin: 0;
}

.doc-preview-page .doc-preview-card {
  padding: 1rem;
  overflow: auto;
}

.doc-preview-image {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

.doc-preview-frame {
  width: 100%;
  min-height: 70vh;
  border: none;
  border-radius: 8px;
  background: #f4f6fa;
}

.doc-preview-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  max-height: 70vh;
  overflow: auto;
}

.doc-preview-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--ricavi-muted);
}

.time-admin-employee-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--ricavi-border);
  background: #f8faff;
}

.time-admin-employee-header h2 {
  margin: 0;
  font-size: 1.15rem;
  color: var(--ricavi-navy);
}

.time-admin-total {
  font-weight: 600;
  color: var(--ricavi-blue);
}

.time-admin-day {
  border-bottom: 1px solid var(--ricavi-border);
}

.time-admin-day:last-child {
  border-bottom: none;
}

.time-admin-day-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  background: #fafcff;
}

.time-admin-day-header h3 {
  margin: 0;
  font-size: 1rem;
  color: var(--ricavi-navy);
}

.time-admin-day-header span {
  color: var(--ricavi-muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.time-admin-summary {
  color: var(--ricavi-navy);
}

.time-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.time-summary-sub {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.82rem;
  color: var(--ricavi-muted);
  font-weight: 400;
}

.time-user-day {
  border: 1px solid var(--ricavi-border);
  border-radius: 8px;
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.time-user-day .time-admin-day-header h3 {
  font-size: 0.95rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem 1rem;
}

.form-group-wide {
  grid-column: 1 / -1;
}

.representatives-section {
  padding: 0 1.25rem 1.25rem;
}

.representative-form .text-input,
.representative-form textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--ricavi-border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}

.representative-form .text-input:focus,
.representative-form textarea:focus {
  outline: none;
  border-color: var(--ricavi-blue-light);
  box-shadow: 0 0 0 3px rgba(26, 92, 224, 0.12);
}

.representatives-section h3 {
  margin: 0 0 0.25rem;
  color: var(--ricavi-navy);
}

.representatives-list {
  display: grid;
  gap: 1rem;
  margin: 1rem 0;
}

.representative-card {
  position: relative;
  border: 1px solid var(--ricavi-border);
  border-radius: 8px;
  padding: 1rem;
  background: #fafcff;
}

.representative-card-new {
  background: var(--ricavi-surface);
}

.representative-card-new h4 {
  margin: 0 0 0.75rem;
  color: var(--ricavi-navy);
}

.representative-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.representative-delete-form {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
}

.representatives-empty {
  color: var(--ricavi-muted);
  margin: 1rem 0;
}

@media (max-width: 768px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .meta-item-wide {
    grid-column: span 1;
  }

  .time-layout {
    grid-template-columns: 1fr;
  }

  .settings-grid,
  .vat-row {
    grid-template-columns: 1fr;
  }

  .header-actions span {
    display: none;
  }
}
