/* d2ctap Complete UI — compact / small size (Tally-like density) */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;0,9..40,800;1,9..40,400&display=swap');

:root {
  --font-sans:
    'DM Sans',
    system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    sans-serif;

  --color-primary: #ff6b35;
  --color-primary-dark: #e55a2b;
  --color-primary-darker: #c44a1f;
  --color-primary-light: #fff7ed;
  --color-primary-border: #fed7aa;
  --color-primary-muted: rgb(255 107 53 / 0.13);
  --color-primary-focus: rgb(255 107 53 / 0.15);
  --color-primary-ring: rgb(249 115 22 / 0.1);

  --sidebar-bg: #111318;
  --sidebar-border: rgb(255 255 255 / 0.07);
  --sidebar-width: 210px;

  --nav-text: #7c8494;
  --nav-hover-bg: rgb(255 255 255 / 0.055);
  --nav-active-bg: rgb(255 107 53 / 0.13);
  --nav-active-color: #ff6b35;

  --bg-main: #f4f5f7;
  --bg-page: #f8f9fb;
  --topbar-bg: #ffffff;
  --topbar-border: #e9eaec;

  --color-text-1: #111827;
  --color-text-2: #6b7280;
  --color-text-3: #9ca3af;

  --color-surface: #ffffff;
  --color-surface-2: #fafafa;
  --color-border: #e5e7eb;
  --color-border-light: #f3f4f6;

  --radius: 10px;
  --radius-md: 8px;
  --radius-sm: 6px;

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.05);
  --shadow: 0 3px 12px rgb(0 0 0 / 0.07);
  --shadow-lg: 0 10px 28px rgb(0 0 0 / 0.1);

  --gradient-primary: linear-gradient(135deg, #ff6b35 0%, #ff9558 100%);

  /* Compact typography & spacing */
  --ui-text-xs: 10px;
  --ui-text-sm: 11px;
  --ui-text-base: 12px;
  --ui-text-md: 13px;
  --ui-text-lg: 15px;
  --ui-text-xl: 18px;
  --ui-pad-xs: 4px;
  --ui-pad-sm: 6px;
  --ui-pad-md: 8px;
  --ui-pad-lg: 10px;
  --ui-pad-xl: 12px;

  /* Books legacy aliases */
  --bg-sidebar: var(--sidebar-bg);
  --text-main: var(--color-text-1);
  --text-muted: var(--color-text-2);
  --border: var(--color-border);
  --brand: var(--color-primary);
  --brand-soft: var(--color-primary-light);
}

html.ui-size-small {
  font-size: 12px;
}

body {
  line-height: 1.35;
}

/* —— Shell —— */
.app-shell,
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  background: var(--bg-main);
}

/* —— Dark sidebar (OMS) —— */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  color: #e8ecf7;
  border-right: 1px solid var(--sidebar-border);
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 20;
  padding: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0.65rem 0.6rem;
  border-bottom: 1px solid rgb(255 255 255 / 0.1);
  flex-shrink: 0;
}

.sidebar-brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  flex-shrink: 0;
  background: var(--gradient-primary);
  box-shadow: 0 4px 10px rgb(255 107 53 / 0.3);
}

.sidebar-app {
  margin: 0;
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: -0.02em;
  color: #fff;
}

.sidebar-sub {
  margin: 0.1rem 0 0;
  font-size: 0.62rem;
  font-weight: 600;
  color: rgb(255 255 255 / 0.55);
}

.sidebar-nav {
  flex: 1;
  overflow: auto;
  padding: 0.45rem 0.35rem;
}

.sidebar-nav .menu {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.sidebar-nav .menu a {
  display: flex;
  align-items: center;
  text-decoration: none;
  padding: 0.42rem 0.6rem;
  border-radius: var(--radius-sm);
  color: rgb(255 255 255 / 0.85);
  font-weight: 600;
  font-size: 0.74rem;
  transition: background 0.12s ease, color 0.12s ease;
}

.sidebar-nav .menu a:hover {
  background: var(--nav-hover-bg);
  color: #fff;
}

.sidebar-nav .menu a.active {
  background: var(--nav-active-bg);
  color: var(--nav-active-color);
}

/* —— Buttons —— */
.d2ui-btn,
.btn-primary,
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.65rem;
  font-size: var(--ui-text-sm);
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition:
    filter 0.12s ease,
    border-color 0.12s ease,
    background 0.12s ease;
}

.d2ui-btn--primary,
.btn-primary {
  border: none;
  background: var(--gradient-primary);
  color: #fff;
  box-shadow: 0 2px 8px rgb(255 107 53 / 0.22);
}

.d2ui-btn--primary:hover,
.btn-primary:hover {
  filter: brightness(1.05);
}

.d2ui-btn--secondary,
.btn-secondary {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-1);
}

.d2ui-btn--secondary:hover,
.btn-secondary:hover {
  border-color: var(--color-primary-border);
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
}

/* —— Modal (compact) —— */
.d2ui-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  pointer-events: none;
}

.d2ui-modal:not(.hidden) {
  pointer-events: auto;
}

.d2ui-modal.hidden {
  display: none !important;
}

.d2ui-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgb(12 30 77 / 0.45);
  backdrop-filter: blur(2px);
}

.d2ui-modal__panel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(380px, calc(100vw - 1rem));
  max-height: min(90vh, 640px);
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid #e2e8f6;
  box-shadow: 0 14px 36px rgb(15 31 77 / 0.16);
  overflow: hidden;
}

.d2ui-modal__panel--wide {
  width: min(780px, calc(100vw - 1.25rem));
}

.d2ui-modal__head {
  padding: 0.55rem 0.7rem;
  background: linear-gradient(180deg, #f4f7ff 0%, #fff 100%);
  border-bottom: 1px solid #e8edf7;
}

.d2ui-modal__title {
  margin: 0;
  font-size: var(--ui-text-md);
  font-weight: 800;
  color: var(--color-text-1);
}

.d2ui-modal__subtitle,
.d2ui-modal__meta {
  margin: 0.15rem 0 0;
  font-size: var(--ui-text-xs);
  font-weight: 600;
  color: var(--color-text-2);
}

.d2ui-modal__body {
  overflow: auto;
  padding: 0.45rem 0.55rem;
}

.d2ui-modal__foot {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-end;
  padding: 0.45rem 0.55rem;
  border-top: 1px solid var(--color-border-light);
  background: var(--color-surface-2);
}
