/* Office Management System — Design System */
@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;1,9..40,400&family=Outfit:wght@500;600;700;800&display=swap');

:root {
  /* Accent palette */
  --accent-900:     #513B7B;
  --accent-800:     #5D3E7D;
  --accent-600:     #7B5FA3;
  --accent-400:     #A799C0;
  --accent-200:     #D4CBE4;
  --accent-50:      #F0ECF5;

  /* Neutrals */
  --black:          #1A1A2E;
  --gray-700:       #4A4A5E;
  --gray-500:       #7A7A8E;
  --gray-300:       #C8C8D4;
  --gray-100:       #F4F4F8;
  --white:          #FFFFFF;

  /* Typography */
  --font-display: 'Outfit', sans-serif;
  --font-body:    'DM Sans', sans-serif;

  /* Type scale — rem values track fluid html font-size */
  --text-xs:   0.7rem;
  --text-sm:   0.8125rem;
  --text-base: 0.875rem;
  --text-md:   1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.5rem;
  --text-2xl:  1.75rem;
  --text-3xl:  2.25rem;

  /* Spacing scale — rem tracks viewport via html */
  --space-xs:  0.25rem;
  --space-sm:  0.5rem;
  --space-md:  1rem;
  --space-lg:  1.5rem;
  --space-xl:  2rem;
  --space-2xl: 3rem;
  --space-3xl: 5rem;
  --space-4xl: 7rem;

  /* Layout */
  --container: 1200px;
  --header-h:  4rem;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Shadows — minimal */
  --shadow-sm:  0 1px 2px rgba(26, 26, 46, 0.04);
  --shadow-md:  0 2px 8px rgba(26, 26, 46, 0.06);
  --shadow-lg:  0 4px 20px rgba(26, 26, 46, 0.08);
  --shadow-xl:  0 8px 32px rgba(26, 26, 46, 0.1);

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --duration: 0.3s;

  /* Semantic colors */
  --color-success: #2D9B6A;
  --color-warning: #D4920A;
  --color-danger:  #D64545;
  --color-info:    var(--accent-600);

  /* Legacy aliases (used across JS & module CSS) */
  --color-primary:       var(--accent-600);
  --color-primary-dark:  var(--accent-800);
  --color-primary-light: var(--accent-400);
  --color-accent:        var(--accent-400);

  --sidebar-bg:          var(--white);
  --sidebar-text:        var(--gray-500);
  --sidebar-text-active: var(--black);
  --sidebar-hover:       var(--gray-100);
  --sidebar-width:       15rem;

  --bg-body:       #FAFAFC;
  --bg-card:       var(--white);
  --border-color:  #EBEBF0;
  --text-primary:  var(--black);
  --text-secondary: var(--gray-700);
  --text-muted:    var(--gray-500);

  --font-sans:  var(--font-body);
  --transition: var(--duration) var(--ease);

  /* Scrollbars */
  --scrollbar-size: 6px;
  --scrollbar-track: transparent;
  --scrollbar-thumb: var(--accent-200);
  --scrollbar-thumb-hover: var(--accent-400);
}

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

html {
  /* ~13px on phones → 16px on desktop; all rem/type scales with this */
  font-size: clamp(13px, 0.35vw + 11.9px, 16px);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.55;
  min-height: 100vh;
}

/* Themed scrollbars — thin, soft purple (scoped to scroll containers) */
html {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

html::-webkit-scrollbar,
.page-content::-webkit-scrollbar,
.table-wrap::-webkit-scrollbar,
.nav-module.is-open .nav-module-panel-inner::-webkit-scrollbar,
.notif-panel-list::-webkit-scrollbar,
.modal-body::-webkit-scrollbar,
.sidebar-modules::-webkit-scrollbar {
  width: var(--scrollbar-size);
  height: var(--scrollbar-size);
}

html::-webkit-scrollbar-track,
.page-content::-webkit-scrollbar-track,
.table-wrap::-webkit-scrollbar-track,
.nav-module.is-open .nav-module-panel-inner::-webkit-scrollbar-track,
.notif-panel-list::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track,
.sidebar-modules::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
  border-radius: 999px;
}

html::-webkit-scrollbar-thumb,
.page-content::-webkit-scrollbar-thumb,
.table-wrap::-webkit-scrollbar-thumb,
.nav-module.is-open .nav-module-panel-inner::-webkit-scrollbar-thumb,
.notif-panel-list::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb,
.sidebar-modules::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 999px;
  border: 1px solid transparent;
  background-clip: padding-box;
}

html::-webkit-scrollbar-thumb:hover,
.page-content::-webkit-scrollbar-thumb:hover,
.table-wrap::-webkit-scrollbar-thumb:hover,
.nav-module.is-open .nav-module-panel-inner::-webkit-scrollbar-thumb:hover,
.notif-panel-list::-webkit-scrollbar-thumb:hover,
.modal-body::-webkit-scrollbar-thumb:hover,
.sidebar-modules::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
  background-clip: padding-box;
}

.page-content,
.table-wrap,
.nav-module.is-open .nav-module-panel-inner,
.notif-panel-list,
.modal-body {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

.sidebar *::-webkit-scrollbar {
  width: 5px;
}

.sidebar *::-webkit-scrollbar-thumb {
  background: var(--accent-200);
}

.sidebar *::-webkit-scrollbar-thumb:hover {
  background: var(--accent-600);
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: -0.02em;
}

a {
  color: var(--accent-600);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--accent-800);
}

/* ── Login page ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-body);
  padding: var(--space-xl);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  padding: var(--space-2xl);
}

.login-brand {
  text-align: center;
  margin-bottom: var(--space-xl);
}

.login-brand .logo {
  width: auto;
  height: auto;
  background: transparent;
  border-radius: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-lg);
}

.login-brand .logo .kaisha-logo,
.login-brand .logo img {
  width: 120px;
  height: auto;
  max-height: 112px;
  display: block;
  object-fit: contain;
}

.login-brand h1 {
  font-size: var(--text-xl);
  font-weight: 500;
  color: var(--text-primary);
}

.login-brand p {
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin-top: var(--space-xs);
}

/* ── App shell ── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  overflow: hidden;
  border-right: 1px solid var(--border-color);
}

.sidebar-brand {
  flex-shrink: 0;
  padding: var(--space-lg) var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-width: 0;
}

.sidebar-close {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-left: auto;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--accent-800);
  cursor: pointer;
  flex-shrink: 0;
}

.sidebar-close:hover {
  background: var(--accent-50);
  color: var(--accent-900);
}

.sidebar-close .icon-sidebar-close {
  stroke: currentColor;
}

.sidebar-overlay {
  display: none;
}

.sidebar-brand .logo-sm {
  width: auto;
  height: 32px;
  background: transparent;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-brand .logo-sm .kaisha-logo,
.sidebar-brand .logo-sm img {
  width: auto;
  height: 32px;
  display: block;
  object-fit: contain;
}

.sidebar-brand-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.sidebar-brand-name {
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--text-primary);
  font-size: var(--text-md);
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-brand-role {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: capitalize;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-section {
  padding: var(--space-sm) 0;
}

.sidebar-portals {
  flex-shrink: 0;
  border-top: 1px solid var(--border-color);
  margin-top: var(--space-sm);
  padding-top: var(--space-md);
}

/* Module dropdown navigation */
.sidebar-modules {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: var(--space-sm) 0;
  overflow: hidden;
}

.nav-module {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border-color);
}

.nav-module:last-child {
  border-bottom: none;
}

.nav-module.is-open {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.nav-module-toggle {
  flex-shrink: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: 0.65rem var(--space-md);
  margin: 0;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition);
}

.nav-module-toggle:hover {
  background: var(--gray-100);
}

.nav-module.is-active-module .nav-module-toggle {
  color: var(--accent-800);
}

.nav-module-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-module-label .nav-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--accent-800);
  transition: color var(--transition);
}

.nav-module-toggle:hover .nav-module-label .nav-icon,
.nav-module.is-open .nav-module-label .nav-icon,
.nav-module.is-active-module .nav-module-label .nav-icon {
  color: var(--accent-900);
}

.nav-module-chevron {
  display: inline-flex;
  color: var(--accent-800);
  transition: transform var(--transition), color var(--transition);
}

.nav-module.is-open .nav-module-chevron,
.nav-module.is-active-module .nav-module-chevron {
  color: var(--accent-900);
}

.nav-module.is-open .nav-module-chevron {
  transform: rotate(180deg);
}

.nav-module-panel {
  display: grid;
  grid-template-rows: 0fr;
  min-height: 0;
  transition: grid-template-rows 0.28s var(--ease);
}

.nav-module.is-open .nav-module-panel {
  flex: 1 1 auto;
  min-height: 0;
  grid-template-rows: 1fr;
  overflow: hidden;
}

.nav-module-panel-inner {
  overflow: hidden;
  min-height: 0;
  opacity: 0;
  padding-bottom: 0;
  transition: opacity 0.22s var(--ease), padding-bottom 0.28s var(--ease);
}

.nav-module.is-open .nav-module-panel-inner {
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  opacity: 1;
  padding-bottom: var(--space-sm);
}

.nav-subgroup {
  padding: 0 var(--space-sm) var(--space-xs);
}

.nav-subgroup-title {
  padding: var(--space-xs) var(--space-md) var(--space-xs) 2.25rem;
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.nav-module-panel-inner > .sidebar-nav {
  padding: 0 var(--space-sm);
}

.nav-module-panel .sidebar-nav a {
  padding: 0.45rem var(--space-md) 0.45rem 2.25rem;
  margin: 0;
  font-size: var(--text-sm);
}

.sidebar-section-title {
  padding: var(--space-sm) var(--space-md) var(--space-xs);
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.sidebar-nav {
  list-style: none;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem var(--space-md);
  margin: 0 var(--space-sm);
  color: var(--sidebar-text);
  font-size: var(--text-sm);
  font-weight: 400;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
  border-left: none;
}

.sidebar-nav a:hover {
  background: var(--sidebar-hover);
  color: var(--text-primary);
}

.sidebar-nav a.active {
  background: var(--accent-50);
  color: var(--accent-800);
  font-weight: 500;
}

.sidebar-nav .nav-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  flex-shrink: 0;
  color: var(--accent-800);
  transition: color var(--transition);
}

.sidebar-nav a:hover .nav-icon {
  color: var(--accent-900);
}

.sidebar-nav a.active .nav-icon {
  color: var(--accent-900);
}

/* Ensure SVG strokes follow the highlighted color */
.sidebar .nav-icon .icon,
.sidebar .nav-module-chevron .icon {
  stroke: currentColor;
  opacity: 1;
}

.topbar-user-group {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.topbar-signout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--accent-800);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}

.topbar-signout:hover {
  background: var(--accent-50);
  color: var(--accent-900);
}

.topbar-signout .icon-signout {
  stroke: currentColor;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: var(--space-md) var(--space-xl);
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-leading {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-width: 0;
  flex: 1;
}

.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--accent-800);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}

.sidebar-toggle:hover {
  background: var(--accent-50);
  color: var(--accent-900);
}

.sidebar-toggle .icon-menu {
  stroke: currentColor;
}

.topbar-title {
  min-width: 0;
}

.topbar-title h2 {
  font-size: var(--text-lg);
  font-weight: 500;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.topbar-title p {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-sm);
  flex-wrap: wrap;
  flex-shrink: 0;
}

.topbar-actions.is-empty {
  display: none;
}

.chat-topbar-tools {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.page-content {
  padding: var(--space-xl);
  flex: 1;
  max-width: calc(var(--container) + var(--sidebar-width));
}

/* ── Components ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 0.5rem 1rem;
  font-size: var(--text-sm);
  font-weight: 500;
  font-family: var(--font-body);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  line-height: 1.4;
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-800);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--gray-100);
  border-color: var(--gray-300);
}

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

.btn-danger:hover:not(:disabled) {
  background: #b83838;
  box-shadow: var(--shadow-sm);
}

.btn-sm {
  padding: 0.4rem 0.85rem;
  font-size: var(--text-sm);
}

.btn-icon {
  padding: var(--space-sm);
  width: 38px;
  height: 38px;
}

.form-group {
  margin-bottom: var(--space-lg);
}

.form-group label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
}

.form-control {
  width: 100%;
  padding: 0.55rem 0.8rem;
  font-size: var(--text-base);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: inherit;
  transition: border-color var(--transition);
}

.form-control:focus {
  outline: none;
  border-color: var(--accent-600);
  box-shadow: 0 0 0 2px rgba(123, 95, 163, 0.12);
}

.form-control::placeholder {
  color: var(--text-muted);
}

select.form-control { cursor: pointer; }

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

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.card-header {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}

.card-header h3 {
  font-size: var(--text-md);
  font-weight: 500;
}

.card-body {
  padding: var(--space-lg);
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
}

.stat-card .stat-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-card .stat-value {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 500;
  margin-top: var(--space-xs);
  color: var(--text-primary);
  letter-spacing: -0.03em;
}

.stat-card .stat-change {
  font-size: var(--text-sm);
  margin-top: var(--space-xs);
  font-weight: 500;
}

.stat-change.positive { color: var(--color-success); }
.stat-change.negative { color: var(--color-danger); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  font-size: var(--text-xs);
  font-weight: 500;
  border-radius: 4px;
  white-space: nowrap;
}

.badge-primary   { background: var(--accent-50);  color: var(--accent-800); }
.badge-success   { background: #E6F5EE; color: #1D7A4E; }
.badge-warning   { background: #FEF3E0; color: #9A6B08; }
.badge-danger    { background: #FDEAEA; color: #B83838; }
.badge-secondary { background: var(--gray-100); color: var(--gray-700); }
.badge-info      { background: var(--accent-50); color: var(--accent-600); }

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  border-radius: var(--radius-md);
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  font-size: var(--text-base);
  table-layout: auto;
}

.data-table th,
.data-table td {
  padding: 0.85rem var(--space-md);
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--border-color);
  line-height: 1.4;
}

.data-table th {
  font-weight: 500;
  color: var(--text-muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: transparent;
  white-space: nowrap;
}

.data-table tbody tr:hover {
  background: var(--gray-100);
}

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

.data-table .actions,
.data-table .table-actions {
  width: 1%;
  white-space: nowrap;
  text-align: right;
  vertical-align: middle;
}

.data-table .table-actions .btn,
.data-table .actions .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  margin-left: 0.25rem;
}

.data-table .table-actions .btn:first-child,
.data-table .actions .btn:first-child {
  margin-left: 0;
}

.data-table th.amount-cell,
.data-table td.amount-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.card > .table-wrap,
.card-body > .table-wrap,
.card-body[style*="padding:0"] > .data-table,
.card-body[style*="padding: 0"] > .data-table {
  border-radius: 0;
}

.card-body[style*="padding:0"] > .data-table,
.card-body[style*="padding: 0"] > .data-table {
  width: 100%;
}

.search-bar {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
  flex-wrap: wrap;
}

.search-bar .form-control {
  max-width: 340px;
}

.empty-state {
  text-align: center;
  padding: var(--space-3xl) var(--space-lg);
  color: var(--text-secondary);
}

.empty-state .empty-icon {
  font-size: 2.75rem;
  margin-bottom: var(--space-sm);
  opacity: 0.45;
}

.toast-container {
  position: fixed;
  top: var(--space-md);
  right: var(--space-md);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow-md);
  font-size: var(--text-sm);
  animation: slideIn var(--duration) var(--ease);
  max-width: 360px;
}

.toast.success { border-left: 2px solid var(--color-success); }
.toast.error   { border-left: 2px solid var(--color-danger); }
.toast.info    { border-left: 2px solid var(--accent-600); }

/* ── Notifications (bottom-right) ── */
.notif-root {
  position: fixed;
  right: var(--space-lg);
  bottom: var(--space-lg);
  z-index: 1100;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-sm);
}

.notif-fab {
  position: relative;
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 50%;
  background: var(--accent-800);
  color: var(--white);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
}

.notif-fab:hover,
.notif-fab.is-open {
  background: var(--accent-900);
  transform: translateY(-1px);
  box-shadow: var(--shadow-xl);
}

.notif-fab .icon-notif-fab {
  stroke: currentColor;
}

.notif-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--color-danger);
  color: var(--white);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 18px;
  text-align: center;
  border: 2px solid var(--bg-body);
}

.notif-panel {
  width: min(360px, calc(100vw - 2rem));
  max-height: min(420px, calc(100vh - 7rem));
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(8px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}

.notif-panel.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.notif-panel-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-color);
}

.notif-panel-header strong {
  font-family: var(--font-display);
  font-size: var(--text-md);
  font-weight: 500;
  color: var(--text-primary);
}

.notif-unread-label {
  display: inline-block;
  margin-left: 0.4rem;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--accent-800);
  background: var(--accent-50);
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
}

.notif-mark-all {
  border: none;
  background: transparent;
  color: var(--accent-800);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 500;
  cursor: pointer;
  padding: 0.2rem 0.35rem;
  border-radius: var(--radius-sm);
}

.notif-mark-all:hover {
  background: var(--accent-50);
}

.notif-panel-list {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.notif-item {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border: none;
  border-bottom: 1px solid var(--border-color);
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-family: var(--font-body);
  transition: background var(--transition);
}

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

.notif-item:hover {
  background: var(--gray-100);
}

.notif-item.is-unread {
  background: var(--accent-50);
}

.notif-item.is-unread:hover {
  background: var(--accent-100, #ebe6f3);
}

.notif-item-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--white);
  border: 1px solid var(--accent-200);
  color: var(--accent-800);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.notif-item-icon .icon-notif {
  stroke: currentColor;
}

.notif-item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.notif-item-title {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-primary);
}

.notif-item-msg {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  line-height: 1.4;
}

.notif-item-time {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.notif-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-600);
  flex-shrink: 0;
  margin-top: 0.35rem;
}

.notif-empty {
  padding: 2rem 1.25rem;
  text-align: center;
  color: var(--text-muted);
}

.notif-empty .icon-notif {
  stroke: var(--accent-400);
  margin-bottom: 0.5rem;
}

.notif-empty p {
  font-size: var(--text-sm);
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 46, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1200;
  padding: var(--space-md);
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid var(--border-color);
}

.modal-header {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: var(--text-md);
  font-weight: 500;
}

.modal-body {
  padding: var(--space-lg);
}

.modal-close {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  background: transparent;
}

.prototype-banner {
  background: var(--gray-100);
  color: var(--text-muted);
  text-align: center;
  padding: 0.35rem var(--space-md);
  font-size: var(--text-xs);
  font-weight: 400;
  border-bottom: 1px solid var(--border-color);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
}

.hidden { display: none !important; }

/* Login utilities */
.login-error {
  color: var(--color-danger);
  font-size: var(--text-sm);
  margin-bottom: var(--space-md);
}

.btn-block {
  width: 100%;
}

.login-footer {
  text-align: center;
  margin-top: var(--space-lg);
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* ── Responsive: tablet & mobile ── */
@media (max-width: 900px) {
  body.sidebar-open {
    overflow: hidden;
  }

  .sidebar {
    width: min(280px, 88vw);
    transform: translateX(-105%);
    transition: transform 0.28s var(--ease);
    box-shadow: none;
    z-index: 120;
  }

  .app-shell.sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: var(--shadow-xl);
  }

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(26, 26, 46, 0.45);
    z-index: 110;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s var(--ease);
  }

  .app-shell.sidebar-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar-close {
    display: inline-flex;
  }

  .sidebar-toggle {
    display: inline-flex;
  }

  .main-content {
    margin-left: 0;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .topbar {
    padding: var(--space-sm) var(--space-md);
    flex-wrap: wrap;
    align-items: center;
  }

  .topbar-leading {
    flex: 1;
    min-width: 0;
  }

  .topbar-title h2 {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-title p {
    display: none;
  }

  .topbar-actions {
    order: 3;
    width: 100%;
    justify-content: flex-start;
    gap: var(--space-sm);
  }

  .topbar-actions.is-empty {
    display: none;
  }

  .topbar-user-group {
    order: 2;
    flex-shrink: 0;
  }

  .page-content {
    padding: var(--space-md);
    max-width: 100%;
    overflow-x: hidden;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
  }

  .stat-card {
    padding: var(--space-md);
  }

  .card-header {
    flex-wrap: wrap;
    padding: var(--space-md);
  }

  .card-body {
    padding: var(--space-md);
  }

  .search-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .search-bar .form-control {
    max-width: none;
    width: 100%;
  }

  .search-bar .btn {
    width: 100%;
  }

  .data-table th,
  .data-table td {
    padding: 0.65rem 0.75rem;
  }

  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    max-width: 100%;
    max-height: 92vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .toast-container {
    left: var(--space-sm);
    right: var(--space-sm);
    top: auto;
    bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
  }

  .toast {
    max-width: none;
  }

  .notif-root {
    right: var(--space-md);
    bottom: calc(var(--space-md) + env(safe-area-inset-bottom, 0px));
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .login-page {
    padding: var(--space-md);
  }

  .login-card {
    padding: var(--space-xl);
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions .btn {
    flex: 1 1 auto;
    min-width: calc(50% - 0.25rem);
  }

  .topbar-actions .btn-sm {
    padding: 0.45rem 0.65rem;
  }

  .modal-footer {
    flex-wrap: wrap;
  }

  .modal-footer .btn {
    flex: 1 1 auto;
  }

  .ss-grid,
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 400px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions .btn {
    min-width: 100%;
  }
}

/* ── Icon system ── */
.icon {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

.icon-nav {
  stroke: currentColor;
  opacity: 1;
}

.icon-tile-wrap,
.icon-action-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--gray-100);
  color: var(--accent-800);
}

.icon-tile-wrap {
  width: 40px;
  height: 40px;
  margin: 0 auto var(--space-sm);
}

.icon-action-wrap {
  width: 40px;
  height: 40px;
  margin: 0 auto var(--space-sm);
  border-radius: var(--radius-sm);
  background: var(--gray-100);
  color: var(--text-primary);
}

.ss-hero {
  text-align: center;
  padding: var(--space-2xl) var(--space-lg);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.ss-hero .icon-tile-wrap {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  background: var(--gray-100);
}

.ss-hero h3 {
  margin: var(--space-md) 0 var(--space-sm);
  font-size: var(--text-lg);
  font-weight: 500;
}

.ss-hero p {
  color: var(--text-muted);
  margin-bottom: var(--space-lg);
  font-size: var(--text-base);
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

.icon-brand { stroke: currentColor; }

.btn .icon { margin-right: 0.1rem; }

.btn-lg {
  padding: 0.65rem 1.25rem;
  font-size: var(--text-base);
}

.doc-title-cell {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
}

.doc-title-cell .icon {
  color: var(--accent-600);
}
