.react-grid-layout {
  position: relative;
  transition: height 200ms ease;
}
.react-grid-item {
  transition: all 200ms ease;
  transition-property: left, top, width, height;
}
.react-grid-item img {
  pointer-events: none;
  user-select: none;
}
.react-grid-item.cssTransforms {
  transition-property: transform, width, height;
}
.react-grid-item.resizing {
  transition: none;
  z-index: 1;
  will-change: width, height;
}

.react-grid-item.react-draggable-dragging {
  transition: none;
  z-index: 3;
  will-change: transform;
}

.react-grid-item.dropping {
  visibility: hidden;
}

.react-grid-item.react-grid-placeholder {
  background: red;
  opacity: 0.2;
  transition-duration: 100ms;
  z-index: 2;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -o-user-select: none;
  user-select: none;
}

.react-grid-item.react-grid-placeholder.placeholder-resizing {
  transition: none;
}

.react-grid-item > .react-resizable-handle {
  position: absolute;
  width: 20px;
  height: 20px;
}

.react-grid-item > .react-resizable-handle::after {
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 5px;
  height: 5px;
  border-right: 2px solid rgba(0, 0, 0, 0.4);
  border-bottom: 2px solid rgba(0, 0, 0, 0.4);
}

.react-resizable-hide > .react-resizable-handle {
  display: none;
}

.react-grid-item > .react-resizable-handle.react-resizable-handle-sw {
  bottom: 0;
  left: 0;
  cursor: sw-resize;
  transform: rotate(90deg);
}
.react-grid-item > .react-resizable-handle.react-resizable-handle-se {
  bottom: 0;
  right: 0;
  cursor: se-resize;
}
.react-grid-item > .react-resizable-handle.react-resizable-handle-nw {
  top: 0;
  left: 0;
  cursor: nw-resize;
  transform: rotate(180deg);
}
.react-grid-item > .react-resizable-handle.react-resizable-handle-ne {
  top: 0;
  right: 0;
  cursor: ne-resize;
  transform: rotate(270deg);
}
.react-grid-item > .react-resizable-handle.react-resizable-handle-w,
.react-grid-item > .react-resizable-handle.react-resizable-handle-e {
  top: 50%;
  margin-top: -10px;
  cursor: ew-resize;
}
.react-grid-item > .react-resizable-handle.react-resizable-handle-w {
  left: 0;
  transform: rotate(135deg);
}
.react-grid-item > .react-resizable-handle.react-resizable-handle-e {
  right: 0;
  transform: rotate(315deg);
}
.react-grid-item > .react-resizable-handle.react-resizable-handle-n,
.react-grid-item > .react-resizable-handle.react-resizable-handle-s {
  left: 50%;
  margin-left: -10px;
  cursor: ns-resize;
}
.react-grid-item > .react-resizable-handle.react-resizable-handle-n {
  top: 0;
  transform: rotate(225deg);
}
.react-grid-item > .react-resizable-handle.react-resizable-handle-s {
  bottom: 0;
  transform: rotate(45deg);
}

.react-resizable {
  position: relative;
}
.react-resizable-handle {
  position: absolute;
  width: 20px;
  height: 20px;
  background-repeat: no-repeat;
  background-origin: content-box;
  box-sizing: border-box;
  background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2IDYiIHN0eWxlPSJiYWNrZ3JvdW5kLWNvbG9yOiNmZmZmZmYwMCIgeD0iMHB4IiB5PSIwcHgiIHdpZHRoPSI2cHgiIGhlaWdodD0iNnB4Ij48ZyBvcGFjaXR5PSIwLjMwMiI+PHBhdGggZD0iTSA2IDYgTCAwIDYgTCAwIDQuMiBMIDQgNC4yIEwgNC4yIDQuMiBMIDQuMiAwIEwgNiAwIEwgNiA2IEwgNiA2IFoiIGZpbGw9IiMwMDAwMDAiLz48L2c+PC9zdmc+);
  background-position: bottom right;
  padding: 0 3px 3px 0;
}
.react-resizable-handle-sw {
  bottom: 0;
  left: 0;
  cursor: sw-resize;
  transform: rotate(90deg);
}
.react-resizable-handle-se {
  bottom: 0;
  right: 0;
  cursor: se-resize;
}
.react-resizable-handle-nw {
  top: 0;
  left: 0;
  cursor: nw-resize;
  transform: rotate(180deg);
}
.react-resizable-handle-ne {
  top: 0;
  right: 0;
  cursor: ne-resize;
  transform: rotate(270deg);
}
.react-resizable-handle-w,
.react-resizable-handle-e {
  top: 50%;
  margin-top: -10px;
  cursor: ew-resize;
}
.react-resizable-handle-w {
  left: 0;
  transform: rotate(135deg);
}
.react-resizable-handle-e {
  right: 0;
  transform: rotate(315deg);
}
.react-resizable-handle-n,
.react-resizable-handle-s {
  left: 50%;
  margin-left: -10px;
  cursor: ns-resize;
}
.react-resizable-handle-n {
  top: 0;
  transform: rotate(225deg);
}
.react-resizable-handle-s {
  bottom: 0;
  transform: rotate(45deg);
}
/* ─────────────────────────────────────────────────────────────────────────────
   Chanelle OS — Global Styles
   All design tokens mirror the UI/UX spec. Use CSS variables everywhere so
   dark mode can be toggled simply by swapping data-theme="dark".
   ───────────────────────────────────────────────────────────────────────────── */

/* ── Design Tokens (light) ───────────────────────────────────────────────── */

:root,
[data-theme="light"] {
  --primary:        #0085FF;
  --success:        #00C875;
  --warning:        #FDAB3D;
  --danger:         #E2445C;
  --info:           #579BFC;
  --neutral:        #C5C7D4;

  --bg-base:        #F6F7FB;
  --bg-surface:     #FFFFFF;
  --bg-hover:       #E6E9EF;

  --text-primary:   #323338;
  --text-secondary: #676879;
  --text-disabled:  #C5C7D4;

  --border-color:   #E6E9EF;
  --shadow-sm:      0 1px 4px rgba(0, 0, 0, 0.08);
  --shadow-md:      0 2px 8px rgba(0, 0, 0, 0.12);
  --shadow-lg:      0 4px 20px rgba(0, 0, 0, 0.16);

  --radius-sm:      4px;
  --radius-md:      8px;
  --radius-lg:      12px;

  --nav-width-collapsed: 56px;
  --nav-width-expanded:  180px;
}

/* ── Design Tokens (dark) ────────────────────────────────────────────────── */

[data-theme="dark"],
.dark-app-theme {
  --primary:        #438AFF;
  --success:        #00D68F;
  --warning:        #FFC555;
  --danger:         #FF4D68;
  --info:           #7BB8FC;
  --neutral:        #676879;

  --bg-base:        #1C1F2E;
  --bg-surface:     #252836;
  --bg-hover:       #2E3248;

  --text-primary:   #EAEAEA;
  --text-secondary: #9699B0;
  --text-disabled:  #676879;

  --border-color:   #2E3248;
  --shadow-sm:      0 1px 4px rgba(0, 0, 0, 0.3);
  --shadow-md:      0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-lg:      0 4px 20px rgba(0, 0, 0, 0.5);
}

/* ── Reset & Base ────────────────────────────────────────────────────────── */

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

html, body, #root {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Figtree', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-base);
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
}

p {
  margin: 0;
}

button {
  cursor: pointer;
}

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

a:hover {
  text-decoration: underline;
}

/* Focus visible — consistent across all interactive elements */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Remove default button styles where we manage them ourselves */
button.unstyled {
  appearance: none;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
}

/* ── Custom Scrollbar ─────────────────────────────────────────────────────── */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--neutral);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* ── App Shell ───────────────────────────────────────────────────────────── */

.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-base);
}

.app-main {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.app-loading,
.tab-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.app-loading__spinner,
.tab-loading__spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--neutral);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.app-error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
  font-size: 14px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Widget base ─────────────────────────────────────────────────────────── */

.widget {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  transition: box-shadow 150ms ease;
}

.widget:hover {
  box-shadow: var(--shadow-sm);
}

.widget__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 40px;
  min-height: 40px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.widget__title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.widget__content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.widget__empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}

.widget--loading {
  align-items: center;
  justify-content: center;
}

/* ── Grid layout edit mode ───────────────────────────────────────────────── */

.grid-edit-mode .react-grid-item {
  border: 1.5px dashed var(--primary) !important;
  border-radius: var(--radius-md);
}

.widget-drag-handle {
  cursor: grab;
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1;
  user-select: none;
}

.widget-drag-handle:active {
  cursor: grabbing;
}

/* ── Navigation ──────────────────────────────────────────────────────────── */

.nav-rail {
  width: var(--nav-width-collapsed);
  min-width: var(--nav-width-collapsed);
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  transition: width 200ms ease;
  overflow: hidden;
}

.nav-rail--expanded {
  width: var(--nav-width-expanded);
  min-width: var(--nav-width-expanded);
  align-items: flex-start;
}

.nav-rail__brand {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-bottom: 8px;
  font-size: 20px;
  color: var(--primary);
}

.nav-rail__items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.nav-tab-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, transform 120ms ease;
  padding: 0;
  margin: 2px 8px;
  justify-content: center;
}

.nav-rail--expanded .nav-tab-btn {
  width: calc(var(--nav-width-expanded) - 16px);
  justify-content: flex-start;
  padding: 0 10px;
}

.nav-tab-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  transform: scale(1.05);
}

.nav-tab-btn--active {
  color: var(--primary) !important;
  border-left: 3px solid var(--primary);
  padding-left: 7px;
}

.nav-tab-btn__label {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  display: none;
}

.nav-rail--expanded .nav-tab-btn__label {
  display: block;
}

.nav-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

/* ── Note rows ───────────────────────────────────────────────────────────── */

.note-row {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
  transition: background 120ms ease;
}

.note-row:hover {
  background: var(--bg-hover);
}

.note-row__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.note-row__title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-row__time {
  font-size: 11px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.note-row__preview {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-row__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.note-row__tag {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--bg-hover);
  color: var(--text-secondary);
}

/* ── Quick Actions grid ──────────────────────────────────────────────────── */

.qa-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 8px;
}

.qa-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  cursor: pointer;
  transition: background 120ms ease, box-shadow 120ms ease;
  min-height: 64px;
}

.qa-btn:hover {
  background: var(--bg-hover);
  box-shadow: var(--shadow-sm);
}

.qa-btn--primary { border-color: var(--primary); background: rgba(0,133,255,0.06); }
.qa-btn--success { border-color: var(--success); background: rgba(0,200,117,0.06); }
.qa-btn--warning { border-color: var(--warning); background: rgba(253,171,61,0.06); }
.qa-btn--info    { border-color: var(--info);    background: rgba(87,155,252,0.06); }

.qa-btn__icon {
  font-size: 20px;
  line-height: 1;
}

.qa-btn__label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-primary);
  text-align: center;
}

/* ── Command Palette ─────────────────────────────────────────────────────── */

.command-palette-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(4px);
}

.command-palette {
  width: 100%;
  max-width: 640px;
  max-height: 480px;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.command-palette__input {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.command-palette__results {
  flex: 1;
  overflow-y: auto;
}

.command-palette__group-label {
  padding: 6px 16px 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.command-palette__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background 80ms ease;
}

.command-palette__item--active {
  background: var(--bg-hover);
  border-left: 3px solid var(--primary);
  padding-left: 13px;
}

.command-palette__item-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.command-palette__item-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.command-palette__item-sub {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 1px;
}

.command-palette__footer {
  padding: 8px 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 12px;
  flex-shrink: 0;
}

.command-palette__kbd {
  font-size: 11px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.command-palette__kbd kbd {
  font-family: monospace;
  font-size: 11px;
  padding: 1px 4px;
  border: 1px solid var(--neutral);
  border-radius: 3px;
  background: var(--bg-hover);
}

/* ── Quick capture ───────────────────────────────────────────────────────── */

.quick-capture {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px 0;
}

.quick-capture__hint {
  font-size: 11px;
  color: var(--text-secondary);
  text-align: right;
}

.quick-capture__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.quick-capture__success {
  text-align: center;
  color: var(--success);
  font-weight: 600;
  padding: 16px 0;
}

/* ── Status badges ───────────────────────────────────────────────────────── */

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.status-badge--success  { background: rgba(0,200,117,0.15); color: #006843; }
.status-badge--warning  { background: rgba(253,171,61,0.15); color: #8a5a00; }
.status-badge--danger   { background: rgba(226,68,92,0.15);  color: #a01030; }
.status-badge--info     { background: rgba(87,155,252,0.15); color: #1a5db5; }
.status-badge--neutral  { background: rgba(197,199,212,0.3); color: var(--text-secondary); }

/* ── Escalation Drawer ───────────────────────────────────────────────────── */

.escalation-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 900;
}

.escalation-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 320px;
  background: var(--bg-surface);
  box-shadow: var(--shadow-lg);
  z-index: 901;
  display: flex;
  flex-direction: column;
  animation: slideInRight 220ms ease-out;
}

@keyframes slideInRight {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

.escalation-drawer__header {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
  font-size: 15px;
  font-weight: 600;
}

.escalation-drawer__body {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.escalation-drawer__footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-color);
}

/* ── Accessibility ───────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 1279px) {
  .nav-rail {
    width: var(--nav-width-collapsed);
  }
  .nav-rail--expanded {
    width: var(--nav-width-expanded);
  }
}

@media (max-width: 767px) {
  .app-shell {
    flex-direction: column;
  }

  .nav-rail {
    width: 100%;
    height: 56px;
    min-width: unset;
    flex-direction: row;
    border-right: none;
    border-top: 1px solid var(--border-color);
    order: 2;
    padding: 0 8px;
    overflow-x: auto;
  }

  .app-main {
    order: 1;
    flex: 1;
    overflow-y: auto;
  }
}

