/* ===== CRM Apple Style - Main CSS ===== */

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

:root {
  --white: #FFFFFF;
  --bg-light: #F5F5F7;
  --blue: #0071E3;
  --blue-dark: #0058B0;
  --blue-light: #E8F1FB;
  --dark: #1D1D1F;
  --mid-gray: #6E6E73;
  --light-gray: #D2D2D7;
  --border: rgba(0,0,0,0.08);
  --border-strong: rgba(0,0,0,0.12);
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --radius-card: 12px;
  --radius-btn: 8px;
  --radius-input: 8px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  --red: #FF3B30;
  --orange: #FF9500;
  --green: #34C759;
  --purple: #AF52DE;
  --yellow: #FFCC00;
}

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--bg-light);
  color: var(--dark);
  line-height: 1.5;
  min-height: 100vh;
}

/* ===== Layout ===== */
.app-container {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: var(--white);
  border-right: 0.5px solid var(--border-strong);
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.main-content {
  margin-left: 240px;
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page-content {
  padding: 24px 32px;
  flex: 1;
}

/* ===== Sidebar ===== */
.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 0.5px solid var(--border);
}

.sidebar-logo h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--dark);
  letter-spacing: -0.3px;
}

.sidebar-logo span {
  color: var(--blue);
}

.sidebar-user {
  padding: 14px 20px;
  border-bottom: 0.5px solid var(--border);
  font-size: 0.85rem;
}

.sidebar-user .user-name {
  font-weight: 600;
  color: var(--dark);
}

.sidebar-user .user-role {
  color: var(--mid-gray);
  font-size: 0.78rem;
}

.sidebar-nav {
  padding: 8px 0;
  flex: 1;
}

.nav-section-label {
  padding: 12px 20px 4px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--mid-gray);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--dark);
  text-decoration: none;
  font-size: 0.9rem;
  border-radius: 0;
  transition: background 0.15s;
}

.nav-item:hover {
  background: var(--bg-light);
}

.nav-item.active {
  background: var(--blue-light);
  color: var(--blue);
  font-weight: 500;
}

.nav-item .nav-icon {
  width: 20px;
  text-align: center;
  font-size: 1rem;
  opacity: 0.7;
}

.nav-item.active .nav-icon {
  opacity: 1;
}

.nav-item {
  justify-content: flex-start;
}

.nav-badge {
  margin-left: auto;
  background: var(--blue);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
  line-height: 18px;
}

.nav-badge-gray {
  background: var(--text-secondary);
}

.sidebar-footer {
  padding: 12px 20px;
  border-top: 0.5px solid var(--border);
}

/* ===== Top Bar ===== */
.topbar {
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(20px);
  border-bottom: 0.5px solid var(--border-strong);
  padding: 12px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--dark);
  letter-spacing: -0.3px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== Cards ===== */
.card {
  background: var(--white);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  border: 0.5px solid var(--border);
}

.card-header {
  padding: 18px 20px 14px;
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--dark);
}

.card-body {
  padding: 20px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-btn);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--blue);
  color: white;
}

.btn-primary:hover {
  background: var(--blue-dark);
  color: white;
}

.btn-secondary {
  background: var(--bg-light);
  color: var(--dark);
  border: 0.5px solid var(--border-strong);
}

.btn-secondary:hover {
  background: var(--light-gray);
}

.btn-danger {
  background: var(--red);
  color: white;
}

.btn-danger:hover {
  background: #cc2f26;
  color: white;
}

.btn-success {
  background: var(--green);
  color: white;
}

.btn-ghost {
  background: transparent;
  color: var(--mid-gray);
  border: 0.5px solid var(--border-strong);
}

.btn-ghost:hover {
  background: var(--bg-light);
  color: var(--dark);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 1rem;
}

.btn-icon {
  padding: 8px;
  border-radius: 8px;
}

/* ===== Forms ===== */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--dark);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--light-gray);
  border-radius: var(--radius-input);
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--dark);
  background: var(--white);
  transition: border-color 0.15s;
  outline: none;
}

.form-control:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}

select.form-control {
  cursor: pointer;
}

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

/* ===== Tables ===== */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
}

thead th {
  padding: 12px 16px;
  text-align: left;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--mid-gray);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-bottom: 0.5px solid var(--border-strong);
  background: var(--bg-light);
}

tbody td {
  padding: 12px 16px;
  font-size: 0.88rem;
  border-bottom: 0.5px solid var(--border);
  vertical-align: middle;
}

/* Truncated company name cell */
.cell-name {
  display: block;
  max-width: 210px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cell-name-sub {
  display: block;
  max-width: 210px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--bg-light);
}

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}

.badge-blue { background: #E8F1FB; color: var(--blue); }
.badge-green { background: #E8F9EF; color: #1E8E3E; }
.badge-orange { background: #FFF3E0; color: #E65100; }
.badge-red { background: #FDEEEE; color: var(--red); }
.badge-gray { background: var(--bg-light); color: var(--mid-gray); }
.badge-purple { background: #F3E5F5; color: var(--purple); }
.badge-yellow { background: #FFFDE7; color: #F57F17; }

/* ===== Flash Messages ===== */
.flash-messages {
  padding: 0 32px;
  margin-top: 16px;
}

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-btn);
  font-size: 0.875rem;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.alert-success {
  background: #E8F9EF;
  color: #1E8E3E;
  border: 0.5px solid rgba(30, 142, 62, 0.2);
}

.alert-error {
  background: #FDEEEE;
  color: var(--red);
  border: 0.5px solid rgba(255, 59, 48, 0.2);
}

.alert-info {
  background: var(--blue-light);
  color: var(--blue);
  border: 0.5px solid rgba(0, 113, 227, 0.2);
}

/* ===== Metrics Grid ===== */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.metric-card {
  background: var(--white);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  border: 0.5px solid var(--border);
  padding: 20px;
  text-align: center;
}

.metric-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--dark);
  line-height: 1;
  margin-bottom: 6px;
}

.metric-label {
  font-size: 0.8rem;
  color: var(--mid-gray);
  font-weight: 500;
}

.metric-card.blue .metric-value { color: var(--blue); }
.metric-card.orange .metric-value { color: var(--orange); }
.metric-card.red .metric-value { color: var(--red); }
.metric-card.green .metric-value { color: var(--green); }

/* ===== Search Bar ===== */
.search-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 200px;
  padding: 9px 14px 9px 36px;
  border: 1px solid var(--light-gray);
  border-radius: var(--radius-input);
  font-family: var(--font);
  font-size: 0.9rem;
  background: var(--white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236E6E73' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E") no-repeat 10px center;
  outline: none;
  transition: border-color 0.15s;
}

.search-input:focus {
  border-color: var(--blue);
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
  padding: 20px 0;
}

.page-btn {
  padding: 6px 12px;
  border-radius: 6px;
  border: 0.5px solid var(--border-strong);
  background: var(--white);
  color: var(--dark);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}

.page-btn:hover {
  background: var(--bg-light);
}

.page-btn.active {
  background: var(--blue);
  color: white;
  border-color: var(--blue);
}

.page-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--white);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-body {
  padding: 20px 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 0.5px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ===== Inline call buttons ===== */
.call-btns {
  display: flex;
  gap: 4px;
}

.call-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  font-weight: 600;
}

.call-btn-zvedl { background: #E8F9EF; color: #1E8E3E; }
.call-btn-zvedl:hover { background: var(--green); color: white; }
.call-btn-nezvedl { background: #FDEEEE; color: var(--red); }
.call-btn-nezvedl:hover { background: var(--red); color: white; }
.call-btn-odlozit { background: #FFF3E0; color: var(--orange); }
.call-btn-odlozit:hover { background: var(--orange); color: white; }
.call-btn-nezajem { background: var(--bg-light); color: var(--mid-gray); }
.call-btn-nezajem:hover { background: var(--light-gray); color: var(--dark); }

/* ===== Customer Avatar ===== */
.customer-avatar {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--blue-light);
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* ===== Status indicators ===== */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.green { background: var(--green); }
.status-dot.orange { background: var(--orange); }
.status-dot.red { background: var(--red); }
.status-dot.gray { background: var(--light-gray); }

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 0.5px solid var(--border-strong);
  margin-bottom: 20px;
}

.tab-btn {
  padding: 10px 20px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--mid-gray);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}

.tab-btn:hover {
  color: var(--dark);
}

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

/* ===== Section Headers ===== */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--dark);
}

/* ===== Timeline / History ===== */
.timeline {
  list-style: none;
}

.timeline-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 0.5px solid var(--border);
}

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

.timeline-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.timeline-content {
  flex: 1;
}

.timeline-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--dark);
}

.timeline-meta {
  font-size: 0.78rem;
  color: var(--mid-gray);
  margin-top: 2px;
}

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--mid-gray);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state-text {
  font-size: 0.95rem;
}

/* ===== Dropdown inline ===== */
.inline-dropdown {
  background: var(--white);
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-md);
  padding: 12px;
  margin-top: 6px;
}

/* ===== Quick date buttons ===== */
.date-quick-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.date-quick-btn {
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bg-light);
  border: 0.5px solid var(--border-strong);
  font-size: 0.78rem;
  cursor: pointer;
  color: var(--dark);
  transition: all 0.15s;
}

.date-quick-btn:hover {
  background: var(--blue-light);
  color: var(--blue);
  border-color: var(--blue);
}

/* ===== Info list ===== */
.info-list {
  list-style: none;
}

.info-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 0.5px solid var(--border);
  font-size: 0.875rem;
}

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

.info-label {
  color: var(--mid-gray);
  min-width: 130px;
  flex-shrink: 0;
}

.info-value {
  color: var(--dark);
  font-weight: 500;
  word-break: break-word;
}

/* ===== Alert box ===== */
.alert-box {
  padding: 12px 16px;
  border-radius: var(--radius-btn);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.875rem;
  margin-bottom: 12px;
}

.alert-box.red {
  background: #FDEEEE;
  color: var(--red);
  border: 0.5px solid rgba(255,59,48,0.2);
}

.alert-box.orange {
  background: #FFF3E0;
  color: #E65100;
  border: 0.5px solid rgba(230,81,0,0.2);
}

.alert-box.blue {
  background: var(--blue-light);
  color: var(--blue);
  border: 0.5px solid rgba(0,113,227,0.2);
}

/* ===== Checklist ===== */
.checklist {
  list-style: none;
}

.checklist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 0.875rem;
}

.checklist-item input[type=checkbox] {
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
  cursor: pointer;
}

.checklist-item.checked span {
  text-decoration: line-through;
  color: var(--mid-gray);
}

/* ===== Heading utils ===== */
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.5px; }
h2 { font-size: 1.25rem; font-weight: 600; letter-spacing: -0.3px; }
h3 { font-size: 1.05rem; font-weight: 600; }

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

.text-muted { color: var(--mid-gray); }
.text-small { font-size: 0.8rem; }
.text-right { text-align: right; }
.text-center { text-align: center; }

.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }

.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }

.w-full { width: 100%; }
.hidden { display: none !important; }
