/* DCI — M0 shell styles (RTL/LTR via logical properties) */

:root {
  --accent: #0d9488;
  --accent-hover: #0f766e;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --sidebar-w: 260px;
  --topbar-h: 56px;
  --radius: 12px;
  --shadow: 0 1px 3px rgb(15 23 42 / 8%), 0 4px 16px rgb(15 23 42 / 6%);
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --shadow: 0 1px 3px rgb(0 0 0 / 30%);
}

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

html {
  font-size: 16px;
}

body.app-body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

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

/* Sidebar */
.app-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  z-index: 200;
  transition: transform 0.2s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-block-end: 1px solid var(--border);
  font-weight: 700;
}

.sidebar-brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
}

.sidebar-nav {
  padding: 0.75rem;
  flex: 1;
  overflow-y: auto;
}

.sidebar-nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  margin-block-end: 2px;
  transition: background 0.15s, color 0.15s;
}

.sidebar-link:hover,
.sidebar-link.is-active {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
}

.sidebar-link-icon {
  width: 1.25rem;
  text-align: center;
  opacity: 0.85;
}

/* Main area */
.app-main {
  flex: 1;
  margin-inline-start: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-block-end: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding-inline: 1rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-title {
  font-weight: 600;
  flex: 1;
}

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

.app-content {
  padding: 1.25rem;
  max-width: 1200px;
}

/* Components */
.page-header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
}

.text-muted {
  color: var(--text-muted);
  margin: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.card-highlight {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  background: color-mix(in srgb, var(--accent) 6%, var(--surface));
  margin-block-end: 1.25rem;
}

.dashboard-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.dashboard-branch-filter select {
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.dashboard-kpis {
  margin-bottom: 1.25rem;
}

.kpi-card-warn .kpi-value {
  color: #dc2626;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.dashboard-chart-card h2,
.dashboard-low-stock h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.chart-wrap {
  position: relative;
  height: 260px;
}

.dashboard-low-stock {
  grid-column: 1 / -1;
}

.dashboard-widget-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.dashboard-widget-header h2 {
  margin: 0;
}

.dashboard-low-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.dashboard-low-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-block-end: 1px solid var(--border);
}

.dashboard-low-list li:last-child {
  border-block-end: none;
}

.dashboard-low-list a {
  color: var(--text);
  text-decoration: none;
}

.dashboard-low-list a:hover {
  color: var(--accent);
}

.dashboard-low-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

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

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.kpi-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.kpi-label {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 1.125rem;
  font-weight: 600;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
}

.badge-success {
  background: #d1fae5;
  color: #065f46;
}

.badge-danger {
  background: #fee2e2;
  color: #991b1b;
}

.badge-muted {
  background: #f1f5f9;
  color: #475569;
}

[data-theme="dark"] .badge-success {
  background: #064e3b;
  color: #6ee7b7;
}

[data-theme="dark"] .badge-danger {
  background: #7f1d1d;
  color: #fca5a5;
}

[data-theme="dark"] .badge-muted {
  background: #334155;
  color: #cbd5e1;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-size: 0.875rem;
  cursor: pointer;
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
}

.btn-ghost:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.btn-icon {
  padding: 0.4rem 0.6rem;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 8px;
  font-size: 1.25rem;
  color: var(--text);
}

.sidebar-toggle {
  display: none;
}

.avatar-placeholder {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.avatar-lg {
  width: 80px;
  height: 80px;
  font-size: 1.5rem;
}

.avatar-img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.user-menu {
  position: relative;
}

.user-menu-trigger {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text);
  padding: 0.25rem 0.5rem;
  border-radius: 8px;
}

.user-menu-trigger:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.user-menu-name {
  font-size: 0.875rem;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-dropdown {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 4px);
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.35rem;
  z-index: 300;
}

.user-menu-dropdown a,
.user-menu-dropdown form {
  display: block;
}

.user-menu-dropdown a {
  padding: 0.5rem 0.75rem;
  text-decoration: none;
  color: var(--text);
  border-radius: 6px;
}

.user-menu-dropdown a:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.user-menu-logout {
  width: 100%;
  text-align: start;
  padding: 0.5rem 0.75rem;
  border: none;
  background: transparent;
  color: #dc2626;
  cursor: pointer;
  border-radius: 6px;
  font: inherit;
}

.user-menu-logout:hover {
  background: #fee2e2;
}

.auth-body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
}

.auth-shell {
  max-width: 420px;
  margin: 0 auto;
  padding: 1rem;
}

.auth-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-block-end: 2rem;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.auth-card h1 {
  margin: 0 0 0.5rem;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-block-end: 1rem;
  font-size: 0.875rem;
}

.auth-form input[type="text"],
.auth-form input[type="password"],
.auth-form input[type="email"] {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: var(--bg);
  color: var(--text);
}

.btn-block {
  width: 100%;
  margin-top: 0.5rem;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-block-end: 1rem;
  font-size: 0.875rem;
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
}

.alert-success {
  background: #d1fae5;
  color: #065f46;
}

.profile-grid {
  display: grid;
  gap: 1.25rem;
}

.profile-avatar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.profile-avatar-img {
  border-radius: 50%;
  object-fit: cover;
}

@media (min-width: 768px) {
  .profile-grid {
    grid-template-columns: 1fr 2fr;
  }
}

@media (max-width: 768px) {
  .user-menu-name {
    display: none;
  }
}

/* Admin */
.admin-subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-block-end: 1.25rem;
  padding-block-end: 1rem;
  border-block-end: 1px solid var(--border);
}

.admin-subnav-link {
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  text-decoration: none;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.admin-subnav-link:hover,
.admin-subnav-link.is-active {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
}

.page-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-block-end: 1rem;
  flex-wrap: wrap;
}

.search-form {
  display: flex;
  gap: 0.5rem;
}

.search-form input {
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  min-width: 200px;
}

.data-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th,
.data-table td {
  padding: 0.65rem 0.85rem;
  text-align: start;
  border-block-end: 1px solid var(--border);
}

.data-table th {
  background: color-mix(in srgb, var(--accent) 6%, var(--surface));
  font-weight: 600;
}

.table-actions {
  white-space: nowrap;
}

.table-actions a {
  margin-inline-end: 0.75rem;
  color: var(--accent);
}

.inline-form {
  display: inline;
}

.link-danger {
  border: none;
  background: none;
  color: #dc2626;
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
  padding: 0;
}

.btn-danger {
  background: #dc2626;
  color: #fff;
  border-color: #dc2626;
}

.danger-zone {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.pagination {
  display: flex;
  gap: 0.35rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.pagination a {
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.pagination a.is-current {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.permission-matrix {
  display: grid;
  gap: 1rem;
  margin-block: 1rem;
}

.permission-module {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.permission-module legend {
  font-weight: 600;
  padding: 0 0.35rem;
}

.perm-key {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-inline-start: 0.35rem;
}

.branch-checkboxes {
  margin-top: 1rem;
  border: none;
  padding: 0;
}

.filters-form select {
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.toolbar-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.text-in {
  color: #059669;
  font-weight: 600;
}

.text-out {
  color: #dc2626;
  font-weight: 600;
}

.badge-danger {
  background: #fee2e2;
  color: #991b1b;
  margin-inline-start: 0.35rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin: 0;
}

.detail-grid dt {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0 0 0.15rem;
}

.detail-grid dd {
  margin: 0;
  font-weight: 500;
}

.voucher-header-grid {
  margin-bottom: 1.5rem;
}

.voucher-lines-section h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.item-picker {
  position: relative;
  margin-bottom: 1rem;
  max-width: 420px;
}

.item-picker input[type="search"] {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.item-search-results {
  position: absolute;
  inset-inline: 0;
  top: 100%;
  margin: 0.25rem 0 0;
  padding: 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 240px;
  overflow-y: auto;
  z-index: 50;
}

.item-search-results li {
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  border-block-end: 1px solid var(--border);
}

.item-search-results li:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.item-search-results .item-balance {
  float: inline-end;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.form-hint {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.btn-sm {
  padding: 0.2rem 0.5rem;
  font-size: 0.85rem;
}

.notif-menu {
  position: relative;
}

.notif-bell {
  position: relative;
}

.notif-badge {
  position: absolute;
  top: -4px;
  inset-inline-end: -4px;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.25rem;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.notif-dropdown {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 0.35rem);
  width: min(360px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 300;
}

.notif-dropdown-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.65rem 0.85rem;
  border-block-end: 1px solid var(--border);
  font-size: 0.875rem;
}

.notif-dropdown-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 320px;
  overflow-y: auto;
}

.notif-dropdown-list li a {
  display: block;
  padding: 0.65rem 0.85rem;
  text-decoration: none;
  color: var(--text);
  border-block-end: 1px solid var(--border);
  font-size: 0.875rem;
}

.notif-dropdown-list li.is-unread a {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.notif-dropdown-list li a span {
  display: block;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 0.15rem;
}

.notif-dropdown-empty {
  padding: 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  margin: 0;
}

.notification-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.notification-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-block-end: 0.5rem;
}

.notification-item.is-unread {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.notification-item p {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.notification-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}

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

.report-hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.report-hub-card {
  display: block;
  padding: 1.25rem;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.report-hub-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.report-hub-card h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  color: var(--accent);
}

.report-hub-card p {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.report-filters label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.report-export-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0 1rem;
}

.cron-url code,
.cron-token {
  word-break: break-all;
  font-size: 0.75rem;
}

@media print {
  .app-sidebar,
  .app-topbar,
  .page-toolbar,
  .report-filters,
  .report-export-bar,
  .pagination,
  .sidebar-backdrop {
    display: none !important;
  }

  .app-main {
    margin: 0 !important;
  }

  .app-content {
    padding: 0 !important;
  }

  .data-table-wrap {
    box-shadow: none;
    border: none;
  }
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(15 23 42 / 40%);
  z-index: 150;
}

/* Mobile */
@media (max-width: 768px) {
  .app-sidebar {
    transform: translateX(100%);
  }

  [dir="ltr"] .app-sidebar {
    transform: translateX(-100%);
  }

  .app-sidebar.is-open {
    transform: translateX(0);
  }

  .app-main {
    margin-inline-start: 0;
  }

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

/* PWA install prompt */
.pwa-install-banner {
  position: fixed;
  inset-inline: 1rem;
  inset-block-end: 1rem;
  z-index: 500;
  max-width: 28rem;
  margin-inline-start: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
}

.pwa-install-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.pwa-install-copy {
  flex: 1 1 12rem;
}

.pwa-install-copy p {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.pwa-install-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

@media (max-width: 768px) {
  .pwa-install-banner {
    inset-inline: 0.75rem;
    inset-block-end: 0.75rem;
    max-width: none;
  }
}
