/*
 * Miqyas Design System v2
 * Phase 1: shared tokens, controls, surfaces, navigation, data and feedback.
 * This layer intentionally loads after feature styles so old screens inherit one
 * visual language without changing their workflows or printable documents.
 */

:root {
  color-scheme: light;
  --ds-brand-950: #0d332b;
  --ds-brand-900: #10463a;
  --ds-brand-800: #125b4b;
  --ds-brand-700: #13705b;
  --ds-brand-600: #16836b;
  --ds-brand-500: #1b967b;
  --ds-brand-200: #b9ddd3;
  --ds-brand-100: #dcf0ea;
  --ds-brand-50: #f0f8f5;
  --ds-violet-800: #352878;
  --ds-violet-700: #44358c;
  --ds-violet-100: #eeeafb;
  --ds-gold-700: #9b641a;
  --ds-gold-500: #d49a3a;
  --ds-gold-100: #fff0d5;
  --ds-red-700: #a5463a;
  --ds-red-100: #fce9e6;
  --ds-blue-700: #326b91;
  --ds-blue-100: #e7f1f8;
  --ds-ink-950: #102820;
  --ds-ink-800: #24453c;
  --ds-ink-600: #5f746d;
  --ds-ink-500: #7b8c86;
  --ds-line-strong: #c8d8d3;
  --ds-line: #dce6e2;
  --ds-line-soft: #e9efed;
  --ds-surface: #ffffff;
  --ds-surface-soft: #f7faf9;
  --ds-canvas: #f3f7f5;
  --ds-overlay: rgba(8, 35, 29, .52);
  --ds-shadow-1: 0 2px 7px rgba(13, 51, 43, .045);
  --ds-shadow-2: 0 12px 32px rgba(13, 51, 43, .075);
  --ds-shadow-3: 0 24px 65px rgba(13, 51, 43, .16);
  --ds-radius-sm: 9px;
  --ds-radius-md: 13px;
  --ds-radius-lg: 18px;
  --ds-radius-xl: 24px;
  --ds-control-height: 44px;
  --ds-space-1: 4px;
  --ds-space-2: 8px;
  --ds-space-3: 12px;
  --ds-space-4: 16px;
  --ds-space-5: 20px;
  --ds-space-6: 24px;
  --ds-space-8: 32px;
  --ds-ease: cubic-bezier(.2, .8, .2, 1);

  /* Bridge old feature styles to the system tokens. */
  --ink: var(--ds-ink-950);
  --muted: var(--ds-ink-600);
  --green: var(--ds-brand-800);
  --green2: var(--ds-brand-700);
  --mint: var(--ds-brand-50);
  --line: var(--ds-line);
  --paper: var(--ds-surface);
  --bg: var(--ds-canvas);
  --shadow: var(--ds-shadow-2);
}

html {
  background: var(--ds-canvas);
  color: var(--ds-ink-950);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(circle at 18% -15%, rgba(22, 131, 107, .055), transparent 34rem),
    var(--ds-canvas);
}

::selection { background: var(--ds-brand-200); color: var(--ds-brand-950); }

:where(button, a, input, select, textarea) {
  -webkit-tap-highlight-color: transparent;
}

:where(button, [role="button"], a, input, select, textarea):focus-visible {
  outline: 3px solid rgba(22, 131, 107, .25) !important;
  outline-offset: 2px;
}

:where(button, input, select, textarea) {
  font: inherit;
}

:where(input, select, textarea):not([type="checkbox"]):not([type="radio"]) {
  min-height: var(--ds-control-height);
  border: 1px solid var(--ds-line-strong);
  border-radius: var(--ds-radius-sm);
  background: var(--ds-surface);
  color: var(--ds-ink-950);
  transition: border-color .16s var(--ds-ease), box-shadow .16s var(--ds-ease), background .16s var(--ds-ease);
}

:where(input, select, textarea):not([type="checkbox"]):not([type="radio"]):hover {
  border-color: #acc4bc;
}

:where(input, select, textarea):not([type="checkbox"]):not([type="radio"]):focus {
  border-color: var(--ds-brand-600);
  box-shadow: 0 0 0 4px rgba(22, 131, 107, .10);
  outline: none;
}

:where(input, select, textarea)::placeholder { color: #98a7a2; }

:where(button, .primary, .outline, .acc-btn) {
  transition: transform .16s var(--ds-ease), box-shadow .16s var(--ds-ease), border-color .16s var(--ds-ease), background .16s var(--ds-ease), color .16s var(--ds-ease);
}

:where(button, .primary, .outline, .acc-btn):not(:disabled):active { transform: translateY(1px); }

:where(button, .primary, .outline, .acc-btn):disabled,
:where(button, .primary, .outline, .acc-btn)[aria-disabled="true"] {
  cursor: not-allowed !important;
  filter: grayscale(.15);
  opacity: .52;
  box-shadow: none !important;
}

/* Buttons: one visual hierarchy across features. */
:where(.primary, .acc-btn.primary, .employee-primary-action, .receipt-submit, .field-form button[type="submit"], .modal-actions button[type="submit"]) {
  min-height: var(--ds-control-height);
  border: 1px solid transparent;
  border-radius: var(--ds-radius-sm);
  background: linear-gradient(145deg, var(--ds-brand-700), var(--ds-brand-800));
  color: #fff;
  font-weight: 700;
  box-shadow: 0 7px 18px rgba(18, 91, 75, .16);
}

:where(.primary, .acc-btn.primary, .employee-primary-action, .receipt-submit, .field-form button[type="submit"]):not(:disabled):hover {
  background: linear-gradient(145deg, var(--ds-brand-600), var(--ds-brand-800));
  box-shadow: 0 10px 24px rgba(18, 91, 75, .22);
  transform: translateY(-1px);
}

:where(.outline, .acc-btn:not(.primary), .modal-actions button:not(.primary):not([type="submit"])) {
  min-height: var(--ds-control-height);
  border: 1px solid var(--ds-line-strong);
  border-radius: var(--ds-radius-sm);
  background: var(--ds-surface);
  color: var(--ds-ink-800);
  font-weight: 700;
  box-shadow: var(--ds-shadow-1);
}

:where(.outline, .acc-btn:not(.primary), .modal-actions button:not(.primary):not([type="submit"])):not(:disabled):hover {
  border-color: var(--ds-brand-200);
  background: var(--ds-brand-50);
  color: var(--ds-brand-800);
}

:where(.icon-btn, .more, .stage-menu, .chevron, .modal-close, .drawer-head button, .employee-sheet-close, .acc-modal-close) {
  display: inline-grid;
  place-items: center;
  min-width: 40px;
  min-height: 40px;
  border: 1px solid var(--ds-line);
  border-radius: 11px;
  background: var(--ds-surface);
  color: var(--ds-ink-600);
}

:where(.icon-btn, .more, .modal-close, .drawer-head button, .employee-sheet-close, .acc-modal-close):hover {
  border-color: var(--ds-brand-200);
  background: var(--ds-brand-50);
  color: var(--ds-brand-800);
}

/* Admin shell and navigation. */
.app { grid-template-columns: 248px minmax(0, 1fr); }

.sidebar {
  width: 248px;
  padding: 20px 14px 14px;
  background:
    radial-gradient(circle at 15% 105%, rgba(40, 163, 134, .15), transparent 18rem),
    linear-gradient(175deg, var(--ds-brand-950), #0b2c25);
  box-shadow: -8px 0 30px rgba(9, 38, 32, .08);
}

.logo { padding: 0 8px 20px; border-bottom-color: rgba(255, 255, 255, .09); }
.logo strong { font-size: 18px; letter-spacing: -.2px; }
.logo small { color: #91b9ae; }
.sidebar nav { gap: 3px; padding-top: 14px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.16) transparent; }
.sidebar nav a {
  min-height: 43px;
  padding: 9px 11px;
  border: 1px solid transparent;
  border-radius: 11px;
  color: #aec7c0;
  font-size: 12px;
}
.sidebar nav a:hover { background: rgba(255,255,255,.065); color: #fff; }
.sidebar nav a.active {
  border-color: rgba(255,255,255,.10);
  background: linear-gradient(90deg, rgba(255,255,255,.12), rgba(255,255,255,.075));
  box-shadow: inset -3px 0 #d6a354;
  color: #fff;
}
.sidebar nav em { background: rgba(255,255,255,.11); color: #d8e6e2; }
.nav-label { padding: 17px 11px 5px; color: #769e93; letter-spacing: .04em; }
.sidebar-help { border-color: rgba(255,255,255,.09); box-shadow: inset 0 1px rgba(255,255,255,.04); }
.user-card { border-top-color: rgba(255,255,255,.09); }

.app > main { grid-column: 2; }
.topbar {
  height: 66px;
  padding: 0 clamp(18px, 2.4vw, 32px);
  border-bottom-color: var(--ds-line);
  background: rgba(255, 255, 255, .88);
  box-shadow: 0 3px 14px rgba(13, 51, 43, .035);
  backdrop-filter: blur(14px) saturate(1.25);
}
.workspace { max-width: 1510px; padding: 28px clamp(20px, 3vw, 42px) 64px; }
.crumb { color: var(--ds-ink-600); }

/* Consistent headings and intentional information hierarchy. */
:where(.workspace, .accounting-workspace, .employee-main, .customer-portal-main) h1 {
  color: var(--ds-ink-950);
  letter-spacing: -.025em;
}
:where(.workspace, .accounting-workspace) h2 { color: var(--ds-ink-950); letter-spacing: -.015em; }
.eyebrow { color: var(--ds-brand-600); letter-spacing: .08em; }
.muted { color: var(--ds-ink-600); }

/* Surfaces and cards. */
:where(
  .floors-panel, .accounting-panel, .acc-card, .accounting-kpis article,
  .employee-section, .employee-project-card, .engineer-task-card,
  .project-action-strip, .project-schedule-command, .schedule-setting-card,
  .team-panel, .project-documents-panel, .inventory-panel, .asset-panel
) {
  border-color: var(--ds-line) !important;
  border-radius: var(--ds-radius-lg);
  background-color: var(--ds-surface);
  box-shadow: var(--ds-shadow-1);
}

:where(.stats-grid article, .accounting-kpis article, .acc-card) {
  border: 1px solid var(--ds-line);
  box-shadow: var(--ds-shadow-1);
}

:where(.stats-grid article, .accounting-kpis article, .acc-card, .employee-project-card, .engineer-task-card):hover {
  border-color: var(--ds-brand-200) !important;
  box-shadow: var(--ds-shadow-2);
}

.section-top,
.acc-panel-head,
.employee-section-head {
  border-bottom-color: var(--ds-line-soft);
}

.smart-strip {
  border-color: #cfe5de;
  border-radius: var(--ds-radius-md);
  background: linear-gradient(110deg, var(--ds-brand-50), #fbfdfc);
}

/* Status language. Same meaning, same color, everywhere. */
:where(.status, .acc-status, [class*="status-"]) {
  font-weight: 700;
}

:where(.status, .acc-status, .project-smart-alerts span) {
  display: inline-flex;
  align-items: center;
  width: max-content;
  max-width: 100%;
  border: 1px solid transparent;
  border-radius: 999px;
  line-height: 1.25;
}

:where(.status.active, .status.done, .status.completed, .status.approved, .acc-status.paid, .acc-status.received, .acc-status.done, .acc-status.is-clear, .employee-record.done, .engineer-task-state.ready) {
  border-color: #bfdfd4 !important;
  background: var(--ds-brand-50) !important;
  color: var(--ds-brand-700) !important;
}

:where(.status.pending, .acc-status.pending, .acc-status.soon, .engineer-task-state.current) {
  border-color: #edd6a9 !important;
  background: var(--ds-gold-100) !important;
  color: var(--ds-gold-700) !important;
}

:where(.status.rejected, .status.late, .status.blocked, .acc-status.danger, .acc-status.late, .acc-status.returned, .employee-record.missing) {
  border-color: #efc6bf !important;
  background: var(--ds-red-100) !important;
  color: var(--ds-red-700) !important;
}

:where(.status.info, .acc-status.neutral, .acc-status.default) {
  border-color: #cbddea !important;
  background: var(--ds-blue-100) !important;
  color: var(--ds-blue-700) !important;
}

:where(.status.conditional, .approval-conditional) {
  border-color: #d7cef2 !important;
  background: var(--ds-violet-100) !important;
  color: var(--ds-violet-700) !important;
}

/* Tabs and filters. */
:where(.floor-tabs, .accounting-tabbar) {
  gap: 4px;
  border-bottom-color: var(--ds-line);
  scrollbar-width: thin;
}

:where(.floor-tabs button, .accounting-tabbar button) {
  border-radius: 10px 10px 0 0;
  color: var(--ds-ink-500);
  font-weight: 600;
}

:where(.floor-tabs button, .accounting-tabbar button):hover {
  background: var(--ds-surface-soft);
  color: var(--ds-ink-800);
}

:where(.floor-tabs button.active, .accounting-tabbar button.active) {
  border-bottom-color: var(--ds-brand-600);
  background: var(--ds-brand-50);
  color: var(--ds-brand-800);
}

/* Dense data becomes easier to scan. */
:where(.acc-table-wrap, .supplier-accounts-table) {
  overflow: auto;
  border: 1px solid var(--ds-line);
  border-radius: var(--ds-radius-md);
  background: var(--ds-surface);
}

:where(.acc-table, .supplier-accounts-table) {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

:where(.acc-table, .supplier-accounts-table) th {
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom: 1px solid var(--ds-line-strong);
  background: #f0f6f3;
  color: var(--ds-ink-600);
  font-size: 11px;
  font-weight: 700;
}

:where(.acc-table, .supplier-accounts-table) :is(th, td) { padding: 13px 14px; }
:where(.acc-table, .supplier-accounts-table) td { border-bottom-color: var(--ds-line-soft); color: var(--ds-ink-800); }
:where(.acc-table, .supplier-accounts-table) tbody tr:hover td { background: var(--ds-brand-50); }

/* Modal and drawer behavior. */
:where(.modal-overlay, .acc-modal-overlay, .employee-sheet-overlay) {
  background: var(--ds-overlay);
  backdrop-filter: blur(7px);
}

:where(.modal, .acc-modal, .employee-sheet) {
  border: 1px solid rgba(255,255,255,.8);
  border-radius: var(--ds-radius-xl);
  background: var(--ds-surface);
  box-shadow: var(--ds-shadow-3);
}

.modal { padding: 28px; }
.modal h2 { margin-bottom: 6px; font-size: clamp(21px, 2.2vw, 26px); }
.modal > p { color: var(--ds-ink-600); line-height: 1.75; }
.modal-actions { padding-top: 16px; border-top: 1px solid var(--ds-line-soft); }

.task-drawer {
  border-inline-end: 1px solid var(--ds-line);
  box-shadow: var(--ds-shadow-3);
}
.drawer-overlay { background: var(--ds-overlay); backdrop-filter: blur(5px); }
.drawer-head, .drawer-footer { border-color: var(--ds-line); background: rgba(255,255,255,.96); }

/* Action strip: clear next action, without visual competition. */
.project-action-strip {
  gap: 9px;
  padding: 10px;
  border-color: var(--ds-line) !important;
  box-shadow: var(--ds-shadow-1);
}
.project-action-strip > div {
  border-inline-start-color: var(--ds-brand-500);
  background: var(--ds-surface-soft);
}
.project-action-strip > div.blocked { border-inline-start-color: var(--ds-gold-500); background: #fffaf0; }
.project-action-strip > button {
  min-height: var(--ds-control-height);
  border-radius: 11px;
  background: var(--ds-violet-800);
  box-shadow: 0 7px 18px rgba(53, 40, 120, .14);
}
.project-action-strip > button:hover { background: var(--ds-violet-700); transform: translateY(-1px); }

/* Accounting shell: quieter, role-first dashboard. */
.accounting-workspace { background: transparent; }
.accounting-hero {
  border-radius: var(--ds-radius-xl);
  background:
    radial-gradient(circle at 9% 115%, rgba(62, 170, 143, .18), transparent 19rem),
    linear-gradient(125deg, var(--ds-brand-950), var(--ds-brand-700));
  box-shadow: 0 18px 40px rgba(13, 51, 43, .13);
}
.accounting-kpis { gap: 12px; }
.accounting-panel { overflow: clip; }
.acc-toolbar { gap: 9px; }
.acc-toolbar input { min-width: min(280px, 100%); }

/* Employee experience: field-first and thumb-friendly. */
.employee-portal-shell { background: var(--ds-canvas); }
.employee-app { background: var(--ds-canvas); }
.employee-header {
  border-bottom: 1px solid var(--ds-line);
  background: rgba(255,255,255,.91);
  box-shadow: 0 3px 14px rgba(13,51,43,.04);
  backdrop-filter: blur(14px);
}
.employee-main { max-width: 1180px; }
.engineer-hero {
  border-radius: var(--ds-radius-xl);
  background:
    radial-gradient(circle at 12% 110%, rgba(79, 191, 162, .18), transparent 15rem),
    linear-gradient(135deg, var(--ds-brand-950), var(--ds-brand-700));
  box-shadow: 0 16px 38px rgba(13, 51, 43, .14);
}
.engineer-task-card { overflow: hidden; }
.employee-bottom-nav {
  border-top: 1px solid var(--ds-line);
  background: rgba(255,255,255,.93);
  box-shadow: 0 -8px 30px rgba(13,51,43,.07);
  backdrop-filter: blur(16px);
}
.employee-bottom-nav button { color: var(--ds-ink-500); }
.employee-bottom-nav button.active { color: var(--ds-brand-700); }

/* Customer shell receives the same interaction language while keeping membership theming. */
.customer-portal-header {
  border-bottom-color: var(--ds-line);
  background: rgba(255,255,255,.91);
  backdrop-filter: blur(14px);
}
.customer-portal-nav {
  border-top-color: var(--ds-line);
  background: rgba(255,255,255,.94);
  box-shadow: 0 -8px 30px rgba(13,51,43,.06);
  backdrop-filter: blur(16px);
}

/* Feedback. */
:where(.toast, .employee-toast) {
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--ds-radius-md);
  background: var(--ds-brand-950);
  box-shadow: var(--ds-shadow-3);
}

/* Reusable primitives for all upcoming phases. */
.ds-card { border: 1px solid var(--ds-line); border-radius: var(--ds-radius-lg); background: var(--ds-surface); box-shadow: var(--ds-shadow-1); }
.ds-stack { display: grid; gap: var(--ds-space-4); }
.ds-cluster { display: flex; align-items: center; flex-wrap: wrap; gap: var(--ds-space-2); }
.ds-divider { height: 1px; border: 0; background: var(--ds-line); }
.ds-status { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border: 1px solid transparent; border-radius: 999px; font-size: 11px; font-weight: 700; }
.ds-status[data-state="success"] { border-color: #bfdfd4; background: var(--ds-brand-50); color: var(--ds-brand-700); }
.ds-status[data-state="warning"] { border-color: #edd6a9; background: var(--ds-gold-100); color: var(--ds-gold-700); }
.ds-status[data-state="danger"] { border-color: #efc6bf; background: var(--ds-red-100); color: var(--ds-red-700); }
.ds-status[data-state="info"] { border-color: #cbddea; background: var(--ds-blue-100); color: var(--ds-blue-700); }

@media (max-width: 1050px) {
  .app { grid-template-columns: 230px minmax(0, 1fr); }
  .sidebar { width: 230px; }
}

@media (max-width: 780px) {
  body { background: var(--ds-canvas); }
  .app { display: block; }
  .app > main { width: 100%; }
  .sidebar { width: min(310px, 88vw); }
  .topbar { height: 60px; padding-inline: 14px; }
  .workspace { padding: 18px 12px 86px; }
  .modal-overlay, .acc-modal-overlay { align-items: end; padding: 0; }
  .modal, .acc-modal {
    width: 100%;
    max-height: 92dvh;
    overflow: auto;
    border-radius: 24px 24px 0 0;
    padding: 22px 18px calc(20px + env(safe-area-inset-bottom));
    animation: ds-sheet-in .22s var(--ds-ease);
  }
  .modal-actions { position: sticky; bottom: 0; margin-inline: -18px; padding: 14px 18px calc(8px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.95); backdrop-filter: blur(10px); }
  :where(button, .primary, .outline, .acc-btn, .employee-bottom-nav button) { min-height: 44px; }
  .accounting-hero { border-radius: 18px; }
  .engineer-hero { border-radius: 18px; }
  .employee-bottom-nav, .customer-portal-nav { padding-bottom: env(safe-area-inset-bottom); }
}

@media (max-width: 560px) {
  .workspace { padding-inline: 10px; }
  .stats-grid, .accounting-kpis { gap: 8px; }
  :where(.stats-grid article, .accounting-kpis article) { padding: 13px; border-radius: 14px; }
  .project-action-strip { grid-template-columns: 1fr; }
  .modal-actions { display: grid; grid-template-columns: 1fr; }
  .modal-actions button { width: 100%; }
  .acc-toolbar { align-items: stretch; flex-direction: column; }
  .acc-toolbar > * { width: 100%; }
}

@keyframes ds-sheet-in {
  from { opacity: 0; transform: translateY(28px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@media print {
  /* Product documents own their print styles; the design layer stays invisible. */
  body { background: #fff !important; }
  .topbar, .sidebar, .employee-bottom-nav, .customer-portal-nav { box-shadow: none !important; }
}
