:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #1e3a5f;
  --accent-2: #c45c26;
  --accent-soft: #e8eef5;
  --success: #15803d;
  --danger: #b91c1c;
  --warning: #b45309;
  --sidebar-w: 240px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.04);
  --font: "Manrope", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.45;
}

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

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #132337 0%, #1e3a5f 55%, #243b55 100%);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  transition: transform .2s ease;
}
.brand {
  padding: 22px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-name {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: .04em;
  color: #fff;
}
.brand-sub { font-size: 12px; color: #94a3b8; margin-top: 2px; }

.nav { padding: 14px 10px; overflow-y: auto; flex: 1; }
.nav-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #64748b;
  padding: 12px 12px 6px;
}
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: #cbd5e1;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}
.nav a:hover, .nav a.active {
  background: rgba(255,255,255,.08);
  color: #fff;
  text-decoration: none;
}
.nav a.active { background: rgba(196, 92, 38, .25); }

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.menu-toggle {
  display: none;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}
.search-dummy {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--muted);
  font-size: 13px;
  min-width: 220px;
}
.user-menu { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.user-menu form { display: inline; margin: 0; }

.content { padding: 24px; }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-header h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.02em;
}
.page-header .meta { color: var(--muted); font-size: 14px; margin-top: 4px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  background: var(--accent);
  color: #fff;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; color: #fff; }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { color: var(--text); background: var(--bg); }
.btn-danger { background: var(--danger); }
.btn-accent { background: var(--accent-2); }
.btn-sm { padding: 5px 10px; font-size: 13px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.card h2, .card h3 { margin: 0 0 12px; font-size: 16px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.stat-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.data th, table.data td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
  background: #f8fafc;
}
table.data tr:hover td { background: #fafbfc; }

.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: #334155; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=datetime-local], select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
textarea { min-height: 90px; resize: vertical; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }

.alert {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
}
.badge-paid, .badge-done, .badge-won, .badge-active, .badge-completed { background: #dcfce7; color: #166534; }
.badge-lost, .badge-cancelled, .badge-overdue { background: #fee2e2; color: #991b1b; }
.badge-draft, .badge-new { background: #f1f5f9; color: #475569; }
.badge-partial, .badge-in_progress, .badge-review { background: #ffedd5; color: #9a3412; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a {
  padding: 8px 12px;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  text-decoration: none;
}
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent-2); }

.kanban {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding: 4px 4px 20px;
  align-items: stretch;
  min-height: calc(100vh - 180px);
  scroll-snap-type: x proximity;
}
.kanban-col {
  flex: 0 0 290px;
  width: 290px;
  background: linear-gradient(180deg, #e8eef5 0%, #eef2f6 100%);
  border-radius: 12px;
  border: 1px solid #dbe3ec;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 170px);
  scroll-snap-align: start;
  transition: background .15s ease, box-shadow .15s ease;
}
.kanban-col.is-over {
  background: #e2ebf5;
  box-shadow: inset 0 0 0 2px rgba(30, 58, 95, .25);
}
.kanban-col-head {
  padding: 12px 12px 10px;
  border-top: 3px solid #94a3b8;
  border-radius: 12px 12px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  position: sticky;
  top: 0;
  background: inherit;
  z-index: 1;
}
.kanban-col-head h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .01em;
}
.kanban-col-sum {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.kanban-col-count {
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(15, 23, 42, .08);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.kanban-col-body {
  padding: 0 10px 12px;
  overflow-y: auto;
  flex: 1;
  min-height: 80px;
}
.kanban-card {
  position: relative;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 12px 12px 18px;
  margin-bottom: 8px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
  cursor: grab;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease, opacity .12s ease;
  user-select: none;
}
.kanban-card:hover {
  border-color: #cbd5e1;
  box-shadow: 0 6px 16px rgba(15, 23, 42, .08);
  transform: translateY(-1px);
}
.kanban-card:active { cursor: grabbing; }
.kanban-card.is-dragging {
  opacity: .45;
  transform: rotate(1.5deg) scale(.98);
}
.kanban-card.is-drop-target {
  box-shadow: 0 0 0 2px rgba(196, 92, 38, .35);
}
.kanban-card-drag {
  position: absolute;
  left: 6px;
  top: 14px;
  width: 6px;
  height: 18px;
  border-radius: 2px;
  background: repeating-linear-gradient(
    to bottom,
    #94a3b8 0 2px,
    transparent 2px 4px
  );
  opacity: .7;
}
.kanban-card-title {
  display: block;
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  text-decoration: none;
  line-height: 1.3;
}
.kanban-card-title:hover { color: var(--accent-2); text-decoration: none; }
.kanban-card .amount { font-weight: 800; font-size: 13px; color: var(--accent); }
.kanban-card .meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.kanban-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}
.kanban-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
}
.kanban-placeholder {
  border: 2px dashed #94a3b8;
  border-radius: 10px;
  background: rgba(255,255,255,.55);
  margin-bottom: 8px;
  pointer-events: none;
}

/* Drawer / modal panel (amoCRM-like) */
.drawer-root[hidden] { display: none !important; }
.drawer-root {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  justify-content: flex-end;
}
.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .42);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity .2s ease;
}
.drawer-root.is-open .drawer-backdrop { opacity: 1; }
.drawer-panel {
  position: relative;
  width: min(720px, 100%);
  height: 100%;
  background: #fff;
  box-shadow: -12px 0 40px rgba(15, 23, 42, .18);
  display: flex;
  flex-direction: column;
  transform: translateX(24px);
  opacity: 0;
  transition: transform .22s ease, opacity .22s ease;
}
.drawer-root.is-open .drawer-panel {
  transform: translateX(0);
  opacity: 1;
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #f8fafc, #fff);
  flex-shrink: 0;
}
.drawer-head-actions { display: flex; gap: 8px; align-items: center; }
.drawer-close {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
}
.drawer-close:hover { color: var(--text); border-color: #cbd5e1; }
.drawer-body {
  overflow: auto;
  padding: 18px 20px 32px;
  flex: 1;
  background:
    radial-gradient(ellipse at top right, rgba(30,58,95,.04), transparent 40%),
    #fff;
}
.drawer-body.is-loading {
  opacity: .55;
  pointer-events: none;
}
.drawer-loading {
  padding: 48px 20px;
  text-align: center;
  color: var(--muted);
  font-weight: 600;
}
.panel-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.panel-title-row h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
}
.panel-title-row .amount {
  font-size: 18px;
  font-weight: 800;
  color: var(--accent);
  white-space: nowrap;
}
.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.panel-grid .card { margin-bottom: 0; }
.panel-entity .card { box-shadow: none; }

body.drawer-open { overflow: hidden; }

@media (max-width: 700px) {
  .drawer-panel { width: 100%; }
  .kanban-col { flex-basis: 260px; width: 260px; }
}

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li {
  padding: 10px 0 10px 14px;
  border-left: 2px solid var(--border);
  margin-left: 6px;
  position: relative;
}
.timeline li::before {
  content: '';
  width: 8px; height: 8px;
  background: var(--accent-2);
  border-radius: 50%;
  position: absolute;
  left: -5px; top: 16px;
}
.timeline .when { font-size: 12px; color: var(--muted); }

.empty { color: var(--muted); padding: 24px; text-align: center; }

/* Browser / in-app notifications */
.notify-wrap { position: relative; }
.notify-bell {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.notify-bell:hover { border-color: #cbd5e1; background: #f8fafc; }
.notify-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent-2);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.notify-badge[hidden] { display: none !important; }
.notify-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: min(360px, calc(100vw - 24px));
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 60;
  overflow: hidden;
}
.notify-dropdown[hidden] { display: none !important; }
.notify-dropdown-head,
.notify-dropdown-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}
.notify-dropdown-foot {
  border-bottom: 0;
  border-top: 1px solid var(--border);
  justify-content: center;
}
.notify-dropdown-list {
  max-height: 360px;
  overflow: auto;
}
.notify-item {
  display: block;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
.notify-item:hover { background: #f8fafc; text-decoration: none; }
.notify-item.is-unread { background: #f3f7fb; }
.notify-item-title { font-weight: 700; font-size: 13px; margin-bottom: 2px; }
.notify-item-body { font-size: 12px; color: var(--muted); }
.notify-item-time { font-size: 11px; color: #94a3b8; margin-top: 4px; }
.notify-empty { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 13px; }

.notify-permission {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 70;
  display: flex;
  justify-content: center;
  pointer-events: none;
}
.notify-permission[hidden] { display: none !important; }
.notify-permission-inner {
  pointer-events: auto;
  width: min(640px, 100%);
  background: #132337;
  color: #e2e8f0;
  border-radius: 14px;
  padding: 16px 18px;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 16px 40px rgba(15, 23, 42, .35);
}
.notify-permission-inner p {
  margin: 4px 0 0;
  font-size: 13px;
  color: #94a3b8;
  line-height: 1.4;
}
.notify-permission-actions { display: flex; gap: 8px; flex-shrink: 0; }
.notify-permission-actions .btn { white-space: nowrap; }

@media (max-width: 700px) {
  .notify-permission-inner { flex-direction: column; align-items: stretch; }
  .notify-permission-actions { width: 100%; }
  .notify-permission-actions .btn { flex: 1; }
}

/* Auth */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(30,58,95,.18), transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(196,92,38,.15), transparent 45%),
    linear-gradient(160deg, #f8fafc, #e8eef5 50%, #f4f6f8);
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.auth-card h1 { margin: 0 0 6px; font-size: 24px; }
.auth-card .sub { color: var(--muted); margin-bottom: 22px; font-size: 14px; }
.auth-card .field { margin-bottom: 14px; }
.auth-card .btn { width: 100%; justify-content: center; margin-top: 8px; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .grid-2, .grid-3, .grid-4, .form-grid { grid-template-columns: 1fr; }
  .search-dummy { display: none; }
  .content { padding: 16px; }
}
