:root {
  --bg: #fff5f8;
  --card: #ffffff;
  --text: #371b2e;
  --muted: #8c7385;
  --line: #fbcfe8;
  --line-light: #fdf2f8;
  --primary: #ec4899;
  --primary-d: #db2777;
  --primary-dark: #be185d;
  --primary-light: #fce7f3;
  --accent: #f59e0b;
  --accent-gold: #fbbf24;
  --accent-light: #fef08a;
  --danger: #e11d48;
  --warn-bg: #fffbeb;
  --warn-line: #fde047;
  --radius: 12px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 13.5px; }
h2 { font-size: 17px; margin: 0 0 8px; color: #831843; font-weight: 700; }
h3 { font-size: 14.5px; margin: 6px 0; color: #9d174d; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* Topbar - Rose-berry wide bar */
.topbar { position: sticky; top: 0; z-index: 50; background: linear-gradient(135deg, #701a75 0%, #9d174d 45%, #be185d 100%); color: #fff; box-shadow: 0 4px 18px rgba(157, 23, 77, 0.25); padding: 10px 0; }
.topbar-inner { max-width: 1320px; margin: 0 auto; padding: 0 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

.tabs { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tab { background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.22); color: #fce7f3; padding: 8px 20px; border-radius: 24px; cursor: pointer; font-size: 14px; font-weight: 600; transition: all .15s ease; display: inline-flex; align-items: center; gap: 6px; }
.tab:hover { background: rgba(255,255,255,0.25); color: #fff; transform: translateY(-1px); }
.tab.active { background: #ffffff; color: #9d174d; font-weight: 700; border-color: #ffffff; box-shadow: 0 3px 12px rgba(0,0,0,0.18); transform: translateY(-1px); }

.profile-picker { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,0.18); padding: 5px 14px; border-radius: 24px; border: 1px solid rgba(255,255,255,0.3); margin-left: auto; }
.profile-picker select { min-width: 250px; padding: 6px 10px; border-radius: 14px; border: none; font-size: 13px; background: #fff; color: #831843; font-weight: 600; }

main { max-width: 1320px; margin: 0 auto; padding: 22px 20px; }
.tabpane { display: none; }
.tabpane.active { display: block; }

/* Cards & Layout */
.card { background: var(--card); border: 1px solid var(--line-light); border-radius: var(--radius); padding: 16px 20px; margin-bottom: 16px; box-shadow: 0 4px 15px rgba(236, 72, 153, 0.04); }
.card.inner { background: #fffafc; border: 1px solid var(--line); margin-top: 12px; }
.card.empty { text-align: center; color: var(--muted); padding: 40px; background: #fffafc; border: 1px dashed var(--line); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 860px) { .grid2, .grid3, .grid4 { grid-template-columns: 1fr; } }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.actions { display: flex; align-items: center; gap: 12px; margin: 8px 0 16px; }

/* Buttons - Rounded & Chic */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 15px; border-radius: 20px; border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer; font-size: 13px; font-weight: 500; white-space: nowrap; transition: transform .1s, box-shadow .15s, background .15s; }
.btn:hover { border-color: #f472b6; background: #fff5f8; transform: translateY(-1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.primary { background: linear-gradient(135deg, #ec4899 0%, #db2777 100%); border: none; color: #fff; font-weight: 600; box-shadow: 0 2px 8px rgba(236,72,153,.3); }
.btn.primary:hover { background: linear-gradient(135deg, #f43f5e 0%, #be185d 100%); box-shadow: 0 4px 14px rgba(236,72,153,.45); }
.btn.accent { background: linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%); border: none; color: #78350f; font-weight: 600; box-shadow: 0 2px 8px rgba(245,158,11,.28); }
.btn.accent:hover { background: linear-gradient(135deg, #d97706 0%, #f59e0b 100%); box-shadow: 0 4px 14px rgba(245,158,11,.4); color: #451a03; }
.btn.ghost { background: transparent; border-color: var(--line); color: #be185d; }
.btn.ghost:hover { background: #fdf2f8; border-color: var(--primary); }
.topbar .btn.ghost { color: #fff; border-color: rgba(255,255,255,0.4); }
.topbar .btn.ghost:hover { background: rgba(255,255,255,0.2); }
.btn.danger { color: var(--danger); border-color: #fecdd3; }
.btn.danger:hover { background: #fff1f2; border-color: var(--danger); }
.btn.big { padding: 11px 24px; font-size: 14.5px; font-weight: 600; border-radius: 24px; }
.btn.icon { padding: 4px 8px; border-radius: 12px; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }

input[type=text], input[type=number], input[type=date], select { padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; background: #fff; font-family: inherit; color: var(--text); }
input:focus, select:focus { outline: 2px solid #fbcfe8; border-color: var(--primary); }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.field input { color: var(--text); }
.chk { display: inline-flex; align-items: center; gap: 6px; margin-right: 14px; cursor: pointer; user-select: none; }
.small-input { width: 140px; }

/* Dropzones */
.dropzone { display: flex; align-items: center; justify-content: center; border: 2px dashed #f472b6; border-radius: var(--radius); padding: 26px; cursor: pointer; color: #9d688c; background: #fffafc; transition: .15s; text-align: center; }
.dropzone.small { padding: 12px; }
.dropzone:hover, .dropzone.over { border-color: var(--primary-d); background: #fdf2f8; color: var(--primary-dark); }
.dropzone input { display: none; }
.filelist { list-style: none; padding: 0; margin: 10px 0 0; }
.filelist li { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; background: #fff0f5; border-radius: 8px; margin-bottom: 4px; font-size: 13px; border: 1px solid #fce7f3; }
.filelist li button { border: none; background: none; cursor: pointer; color: var(--danger); font-size: 15px; }

/* Stats box */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: 0 2px 6px rgba(236,72,153,.04); }
.stat .num { font-size: 24px; font-weight: 700; color: #831843; }
.stat .lbl { font-size: 12px; color: var(--muted); }
.stat.good .num { color: #059669; }
.stat.bad .num { color: var(--danger); }
.warning { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; color: #854d0e; }

/* Tables & Sortable Headers */
.tablewrap { overflow: auto; max-height: 440px; border: 1px solid var(--line); border-radius: 10px; margin-top: 10px; background: #fff; }
.tablewrap.short { max-height: 320px; }
table { border-collapse: collapse; width: 100%; font-size: 12px; }
th, td { padding: 6px 10px; border-bottom: 1px solid var(--line-light); text-align: left; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
th { position: sticky; top: 0; background: #fdf2f8; font-weight: 700; color: #831843; z-index: 2; border-bottom: 1px solid var(--line); }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { background: #fce7f3; color: var(--primary-d); }
th .sort-arrow { margin-left: 4px; font-size: 10px; color: var(--primary); }
tr:hover td { background: #fff5f8; }
.maptable td { max-width: none; overflow: visible; }
.maptable select, .maptable input { width: 100%; }
.maptable .fixed td:first-child { font-weight: 600; color: var(--primary-d); }
.sample { color: var(--muted); font-size: 11px; max-width: 280px; overflow: hidden; text-overflow: ellipsis; }

/* Chips & Badges */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 4px 12px; border: 1px solid var(--line); border-radius: 20px; background: #fff; cursor: pointer; font-size: 12px; color: var(--text); user-select: none; }
.chip.on { background: #fce7f3; border-color: var(--primary); color: var(--primary-dark); font-weight: 600; }
.badge { display: inline-flex; align-items: center; gap: 4px; background: #fce7f3; color: #be185d; border-radius: 14px; padding: 2px 9px; font-size: 11.5px; font-weight: 600; }
.badge.gold { background: #fef08a; color: #854d0e; border: 1px solid #fde047; }
.badge.green { background: #dcfce7; color: #15803d; }
.group { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; background: #fff; }
.group textarea { width: 100%; min-height: 54px; border: 1px solid var(--line); border-radius: 6px; padding: 6px; font-family: inherit; font-size: 12px; }

/* Segments */
.segment { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--primary); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 12px; box-shadow: 0 2px 10px rgba(236,72,153,.04); transition: border-color .15s, background .15s; }
.segment.remainder { border-left-color: #f59e0b; }
.segment.selected-for-merge { border-color: #f59e0b; border-left: 5px solid #f59e0b; background: #fffdf5; box-shadow: 0 4px 14px rgba(245, 158, 11, 0.15); }
.segment-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.segment-head .segname { font-weight: 600; font-size: 14.5px; min-width: 240px; color: #831843; border-color: var(--line); }
.segment-head .count { font-size: 18px; font-weight: 700; color: var(--primary-d); margin-left: auto; }
.rule { display: flex; align-items: center; gap: 6px; margin: 6px 0; flex-wrap: wrap; }
.rule .and { width: 34px; color: var(--muted); font-size: 11px; text-align: right; font-weight: 600; }
.segment-foot { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted); border-top: 1px dashed var(--line-light); padding-top: 8px; }
.seg-summary-card { background: linear-gradient(135deg, #fff5f8 0%, #fefce8 100%); border: 1px solid #fde047; padding: 14px 18px; margin-bottom: 16px; border-radius: var(--radius); }
.seg-summary-stats { font-size: 14px; color: #701a75; }
.seg-inline-preview { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

/* Merged groups */
.merged-group-card { background: #fffdf5; border: 1px solid #fde047; border-left: 4px solid #f59e0b; border-radius: var(--radius); padding: 14px 18px; margin-bottom: 12px; }

/* Avaleht & Hierarhia (Sleeker & more compact) */
.hero { display: flex; justify-content: space-between; align-items: center; background: linear-gradient(135deg, #be185d 0%, #db2777 50%, #ec4899 100%); color: #fff; border-radius: var(--radius); padding: 24px 30px; margin-bottom: 18px; box-shadow: 0 4px 18px rgba(190, 24, 93, 0.2); gap: 20px; flex-wrap: wrap; min-height: 96px; }
.hero-content { flex: 1; min-width: 280px; }
.hero h1 { font-size: 21px; margin: 0 0 4px; font-weight: 700; }
.hero p { color: #fdf2f8; margin: 0; font-size: 13.5px; opacity: .95; }
.hero-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; flex-shrink: 0; }
.hero-tab-btn { background: #ffffff !important; color: #9d174d !important; font-weight: 700 !important; border: 1px solid rgba(255,255,255,0.9) !important; border-radius: 24px !important; padding: 8px 20px !important; box-shadow: 0 2px 10px rgba(0,0,0,0.12); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; transition: transform .12s, box-shadow .15s, background .15s; white-space: nowrap; }
.hero-tab-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0,0,0,0.2); background: #fff5f8 !important; color: #be185d !important; }
.home-nav-bar { display: flex; align-items: center; gap: 12px; margin: 0 0 20px; flex-wrap: wrap; }
.home-tab-nav { background: #ffffff; border: 1.5px solid #f472b6; color: #9d174d; padding: 9px 22px; border-radius: 24px; cursor: pointer; font-size: 14px; font-weight: 600; transition: all .15s ease; display: inline-flex; align-items: center; gap: 8px; box-shadow: 0 2px 8px rgba(236, 72, 153, 0.08); }
.home-tab-nav:hover { background: #fdf2f8; border-color: #db2777; color: #be185d; transform: translateY(-2px); box-shadow: 0 4px 14px rgba(236, 72, 153, 0.18); }
.home-nav-bar .btn.accent { background: linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%); border: none; color: #78350f; font-weight: 700; box-shadow: 0 2px 10px rgba(245, 158, 11, 0.28); }
.home-nav-bar .btn.accent:hover { background: linear-gradient(135deg, #d97706 0%, #f59e0b 100%); color: #451a03; transform: translateY(-2px); box-shadow: 0 4px 16px rgba(245, 158, 11, 0.4); }
.client-header-banner { background: #fff5f8; border-left: 4px solid var(--primary); margin-bottom: 16px; padding: 10px 16px; border-radius: 10px; }

.client-group-card { width: 100%; margin: 0 0 16px; background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--primary); border-radius: var(--radius); padding: 16px 20px; box-shadow: 0 2px 10px rgba(236,72,153,.04); }
.client-group-head { display: flex; justify-content: space-between; align-items: center; padding-bottom: 8px; border-bottom: 1px solid var(--line-light); margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.client-title { font-size: 17px; font-weight: 700; color: #831843; display: flex; align-items: center; gap: 8px; }

.project-box { background: #fffafc; border: 1px solid #fce7f3; border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; }
.project-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; flex-wrap: wrap; gap: 8px; }
.project-title { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 700; color: #be185d; }

.list-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(345px, 1fr)); gap: 12px; }
.list-card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; display: flex; flex-direction: column; justify-content: space-between; transition: transform .12s, box-shadow .12s; min-height: 140px; }
.list-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(236,72,153,.09); border-color: var(--primary); }
.list-card.active-card { border: 2px solid var(--primary); background: #fff9fc; }
.list-title { font-weight: 700; font-size: 14px; margin-bottom: 4px; display: flex; justify-content: space-between; align-items: center; color: #831843; }
.list-desc { font-size: 12px; color: var(--muted); min-height: 20px; line-height: 1.35; margin-bottom: 8px; }
.list-card.add-card { border: 2px dashed #f472b6; background: #fffafc; justify-content: center; align-items: center; text-align: center; cursor: pointer; min-height: 140px; color: #be185d; }
.list-card.add-card:hover { border-color: var(--primary-d); background: #fdf2f8; }
.list-card.add-card .plus-icon { font-size: 22px; color: var(--primary); margin-bottom: 2px; }
.list-card .card-actions { display: flex; gap: 6px; align-items: center; padding-top: 10px; border-top: 1px solid var(--line-light); margin-top: auto; flex-wrap: wrap; }

.workflow-card { margin-top: 0; margin-bottom: 14px; border-radius: var(--radius); padding: 10px 16px; }
.workflow-card h2 { font-size: 13.5px; margin: 0 0 6px; color: #831843; font-weight: 700; }
.step-cards { margin-top: 4px; gap: 10px; }
.step-card { background: #fffafc; border: 1px solid #fce7f3; border-radius: 8px; padding: 8px 12px; }
.step-card h3 { font-size: 12.5px; margin: 2px 0 3px; font-weight: 700; }
.step-card p { font-size: 11.5px; line-height: 1.35; margin: 0; }
.step-num { display: inline-flex; width: 20px; height: 20px; border-radius: 50%; background: linear-gradient(135deg, #ec4899, #db2777); color: #fff; font-weight: 700; font-size: 11px; align-items: center; justify-content: center; margin-bottom: 3px; }
.privacy-note { text-align: center; margin-top: 14px; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(55,27,46,.45); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 200; padding: 16px; }
.modal { background: #fff; border-radius: 16px; padding: 24px 28px; width: 540px; max-width: 100%; box-shadow: 0 20px 40px rgba(131, 24, 67, 0.25); border: 1px solid var(--line); }
.modal h2 { margin: 0 0 14px; font-size: 18px; color: #831843; }

/* Toast & Spinner */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #831843; color: #fff; padding: 10px 20px; border-radius: 20px; z-index: 500; box-shadow: 0 6px 20px rgba(131,24,67,.35); font-weight: 500; }
.toast.err { background: var(--danger); }
.busy { position: fixed; inset: 0; background: rgba(255,245,248,.8); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; z-index: 600; font-weight: 600; color: #831843; }
.spinner { width: 38px; height: 38px; border: 4px solid #fbcfe8; border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
