:root {
  --accent: #2b6cb0;
  --accent-2: #4a90e2;
  --bg: #eaf1fb;
  --glass: rgba(255,255,255,.72);
  --glass-dark: rgba(20,30,50,.55);
  --border: rgba(255,255,255,.55);
  --shadow: 0 12px 40px rgba(15,35,80,.18);
  --radius: 16px;
  --text: #0b1c33;
  --muted: #64748b;
}
* { box-sizing: border-box; }
html,body { margin:0; padding:0; height:100%; }
body {
  font-family: 'Vazirmatn', Tahoma, sans-serif;
  direction: rtl; color: var(--text); background: var(--bg);
  overflow: hidden;
}
.muted { color: var(--muted); font-size: 12px; }
.err { color: #b91c1c; font-size: 13px; min-height: 18px; margin-top: 6px; }
.hint { margin-top: 12px; font-size: 12px; color: #475569; }

/* ====== Login ====== */
.login-body {
  display:flex; align-items:center; justify-content:center; min-height:100vh;
  background: #0b1c33;
}
.login-bg {
  position:fixed; inset:0;
  background:
    radial-gradient(circle at 25% 25%, #4a90e2 0%, transparent 45%),
    radial-gradient(circle at 75% 75%, #2b6cb0 0%, transparent 50%),
    linear-gradient(135deg, #0b1c33, #142a4c);
  z-index:-1;
}
.login-card {
  width: 400px; padding: 40px 34px; text-align:center;
  background: var(--glass); backdrop-filter: blur(30px) saturate(160%);
  border: 1px solid var(--border); border-radius: 24px;
  box-shadow: 0 30px 80px rgba(0,0,0,.35);
}
.login-logo { width: 84px; height: 84px; margin-bottom: 8px; filter: drop-shadow(0 8px 20px rgba(43,108,176,.5)); }
.login-card h1 { font-size: 20px; margin: 8px 0 4px; }
.login-card form { display:flex; flex-direction:column; gap:12px; margin-top:22px; text-align:right; }
.login-card label { font-size:13px; color:#1e293b; display:flex; flex-direction:column; gap:6px; }
.login-card input {
  padding: 11px 14px; border-radius:10px; border:1px solid #cbd5e1;
  font-family: inherit; font-size: 14px; background: #fff;
}
.login-card input:focus { outline:none; border-color: var(--accent); box-shadow:0 0 0 3px rgba(74,144,226,.25); }
.login-card button {
  padding: 12px; border:none; border-radius:10px; cursor:pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color:#fff; font-family:inherit; font-size:15px; font-weight:600;
  box-shadow: 0 8px 20px rgba(43,108,176,.35);
}
.login-card button:hover { filter: brightness(1.08); }

/* ====== Windows 11 shell ====== */
.win-body { overflow: hidden; }
.win-wallpaper {
  position: fixed; inset:0; z-index:-2;
  background:
    radial-gradient(circle at 20% 15%, rgba(74,144,226,.55), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(43,108,176,.6), transparent 45%),
    linear-gradient(135deg, #0a1a33, #163a68 60%, #0a1a33);
}
.glass {
  background: var(--glass);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border: 1px solid var(--border);
}

/* Topbar */
.win-topbar {
  position: fixed; top: 10px; left: 10px; right: 10px; height: 60px;
  border-radius: 16px; display:flex; align-items:center;
  padding: 0 16px; gap: 16px; box-shadow: var(--shadow);
  z-index: 20;
}
.brand { display:flex; align-items:center; gap:12px; }
.brand img { width: 38px; height: 38px; }
.brand-title { font-weight: 700; font-size: 14px; }
.brand-sub { font-size: 11px; color: var(--muted); }
.today { flex:1; text-align:center; font-size:13px; color:#334155; }
.user-chip { display:flex; align-items:center; gap:10px; font-size:13px; }

/* Desktop */
.win-desktop {
  position: fixed; inset: 84px 10px 84px 10px;
  overflow-y: auto; padding: 20px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px; align-content: start;
}
.icon {
  background: var(--glass); border:1px solid var(--border);
  backdrop-filter: blur(18px);
  border-radius: 16px; padding: 18px; cursor:pointer;
  text-align: center; transition: all .2s ease;
  box-shadow: 0 6px 22px rgba(15,35,80,.12);
}
.icon:hover { transform: translateY(-3px); box-shadow: 0 14px 34px rgba(15,35,80,.22); background:#fff; }
.icon .emoji { font-size: 30px; display:block; margin-bottom: 8px; }
.icon .label { font-size: 13px; font-weight: 600; color:#0b1c33; }
.icon .sub { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* Taskbar */
.win-taskbar {
  position: fixed; bottom: 10px; left: 50%; transform: translateX(-50%);
  height: 56px; border-radius: 16px; display:flex; align-items:center;
  padding: 0 12px; gap: 8px; box-shadow: var(--shadow); z-index: 25;
}
.tb-start {
  width: 42px; height: 42px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display:flex; align-items:center; justify-content:center; cursor:pointer;
  box-shadow: 0 6px 16px rgba(43,108,176,.5);
}
.tb-start:hover { filter: brightness(1.1); }
.tb-apps { display:flex; gap:6px; }
.tb-app {
  width: 40px; height: 40px; border-radius: 10px; cursor:pointer;
  display:flex; align-items:center; justify-content:center; font-size: 18px;
  background: rgba(255,255,255,.5);
}
.tb-app:hover { background:#fff; }
.tb-tray { margin-inline-start: 8px; display:flex; gap:10px; align-items:center; font-size: 12px; color:#334155; }

/* Start menu */
.start-menu {
  position: fixed; bottom: 78px; left: 50%; transform: translateX(-50%) translateY(20px);
  width: 420px; border-radius: 20px; padding: 20px;
  box-shadow: var(--shadow); z-index: 30;
  opacity: 0; pointer-events: none; transition: all .2s ease;
}
.start-menu.open { opacity:1; pointer-events: auto; transform: translateX(-50%) translateY(0); }
.sm-header { display:flex; gap:12px; align-items:center; padding-bottom: 16px; border-bottom:1px solid rgba(15,35,80,.1); }
.sm-header img { width:44px; height:44px; border-radius:50%; }
.sm-items { display:grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 14px 0; }
.sm-item {
  padding: 14px 8px; text-align:center; border-radius: 12px; cursor:pointer;
  font-size: 12px;
}
.sm-item:hover { background: #fff; }
.sm-item .emoji { font-size: 22px; display:block; margin-bottom:6px; }
.sm-footer { border-top:1px solid rgba(15,35,80,.1); padding-top: 12px; text-align:center; }

/* Window */
.win-window {
  position: fixed; top: 90px; left: 50%; transform: translateX(-50%) scale(.95);
  width: min(1100px, calc(100vw - 40px)); height: calc(100vh - 200px);
  border-radius: 18px; display:flex; flex-direction:column;
  box-shadow: 0 30px 80px rgba(0,0,0,.35); z-index: 40;
  opacity: 0; pointer-events: none; transition: all .22s ease;
}
.win-window.open { opacity:1; pointer-events: auto; transform: translateX(-50%) scale(1); }
.win-titlebar {
  display:flex; align-items:center; justify-content:space-between;
  padding: 10px 16px; border-bottom: 1px solid rgba(15,35,80,.1);
}
.win-title { font-weight:600; font-size:14px; }
.win-controls { display:flex; gap:6px; }
.win-controls button {
  width: 30px; height:26px; border:none; border-radius:6px; cursor:pointer;
  background: transparent; font-size: 12px; color:#334155;
}
.win-controls button:hover { background: #e2e8f0; }
.win-controls button.danger:hover { background: #ef4444; color:#fff; }
.win-body { flex:1; overflow-y: auto; padding: 20px; }

/* KPI cards */
.kpi-grid { display:grid; grid-template-columns: repeat(auto-fit, minmax(170px,1fr)); gap:14px; margin-bottom:20px; }
.kpi {
  background: #fff; border-radius:14px; padding:16px;
  border:1px solid #e5ecf6;
}
.kpi .label { color: var(--muted); font-size:12px; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top:6px; color: var(--accent); }

/* Tables */
.tbl { width:100%; border-collapse: collapse; background:#fff; border-radius:12px; overflow:hidden; font-size: 13px; }
.tbl th, .tbl td { padding: 10px 12px; text-align: right; border-bottom: 1px solid #eef2f7; }
.tbl th { background:#f4f7fc; color:#334155; font-weight:600; }
.tbl tr:hover td { background: #f9fbff; }

/* Buttons */
button.primary, button.ghost, button.danger {
  padding: 8px 16px; border:none; border-radius:10px; cursor:pointer;
  font-family:inherit; font-size:13px; font-weight:600;
}
button.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color:#fff; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background:#eef2f7; color:#0b1c33; }
button.ghost:hover { background:#e2e8f0; }
button.danger { background:#fee2e2; color:#991b1b; }
button.danger:hover { background:#fecaca; }

/* Form */
.form-grid { display:grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap:12px; }
.form-grid label { display:flex; flex-direction:column; gap:6px; font-size:12px; color:#334155; }
.form-grid input, .form-grid select, .form-grid textarea {
  padding:9px 12px; border-radius:9px; border:1px solid #cbd5e1;
  font-family:inherit; font-size:13px; background:#fff;
}
.form-grid input:focus, .form-grid textarea:focus { outline:none; border-color: var(--accent); }
.section { background:#fff; border-radius:14px; padding:18px; margin-bottom:16px; border:1px solid #e5ecf6; }
.section h3 { margin: 0 0 14px; font-size:14px; }
.row-actions { display:flex; gap:8px; margin-top:16px; flex-wrap:wrap; }
.badge { display:inline-block; padding:2px 8px; border-radius:6px; font-size:11px; font-weight:600; }
.badge.pending { background:#fef3c7; color:#92400e; }
.badge.approved { background:#d1fae5; color:#065f46; }
.badge.rejected { background:#fee2e2; color:#991b1b; }
.badge.draft { background:#e0e7ff; color:#3730a3; }
.steps { display:flex; flex-direction:column; gap:8px; }
.step { display:flex; gap:10px; padding:10px; border-radius:10px; background:#f8fafc; font-size:12px; }
.step .when { color: var(--muted); min-width: 120px; }
.step .act { font-weight:700; }

/* ============ Attachments Preview ============ */
.att-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 8px;
}
.att-item {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 8px;
  text-align: center;
}
.att-thumb {
  width: 100%;
  height: 120px;
  object-fit: cover;
  border-radius: 8px;
  cursor: zoom-in;
  transition: transform .15s;
  background: #fff;
}
.att-thumb:hover { transform: scale(1.03); }
.att-name {
  font-size: 11px;
  color: #475569;
  margin-top: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.att-dl {
  display: inline-block;
  margin-top: 6px;
  font-size: 11px;
  color: #2b6cb0;
  text-decoration: none;
}
.att-dl:hover { text-decoration: underline; }
.att-file {
  color: #2b6cb0;
  text-decoration: none;
  font-size: 13px;
  word-break: break-all;
}




/* ===== Jalali Calendar Popup ===== */
.jalcal-pop {
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(15,35,80,.25);
  padding: 12px;
  width: 272px;
  font-family: Vazirmatn, Tahoma, sans-serif;
  direction: rtl;
  z-index: 10000;
}
.jalcal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.jalcal-title {
  font-weight: 700;
  font-size: 14px;
  color: #0b1c33;
}
.jalcal-nav {
  width: 32px; height: 32px;
  border: none; border-radius: 8px;
  background: #eef2f7; cursor: pointer;
  font-size: 18px; color: #334155;
  font-family: Vazirmatn, Tahoma, sans-serif;
}
.jalcal-nav:hover { background: #dbeafe; color: #1d4ed8; }
.jalcal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}
.jalcal-wd {
  text-align: center;
  font-size: 11px;
  color: #64748b;
  padding: 4px 0;
  font-weight: 600;
}
.jalcal-empty { height: 30px; }
.jalcal-day {
  text-align: center;
  padding: 6px 0;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: #0b1c33;
}
.jalcal-day:hover { background: #eff6ff; }
.jalcal-day.sel { background: #2b6cb0; color: #fff; font-weight: 700; }
.jalcal-day.today { border: 1px solid #2b6cb0; }
.jalcal-day.sel.today { background: #2b6cb0; }
.jalcal-foot {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #eef2f7;
}
.jalcal-btn {
  padding: 6px 14px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-family: Vazirmatn, Tahoma, sans-serif;
  font-size: 12px;
  background: #eef2f7;
  color: #334155;
}
.jalcal-btn:hover { background: #dbeafe; color: #1d4ed8; }

/* ===== Lightbox (strong version) ===== */
.lightbox {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  background: rgba(0, 0, 0, 0.95) !important;
  z-index: 2147483647 !important;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  padding: 20px;
  box-sizing: border-box;
}
.lightbox.open {
  display: flex !important;
}
.lightbox img {
  max-width: 95vw !important;
  max-height: 95vh !important;
  width: auto !important;
  height: auto !important;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 20px 80px rgba(0,0,0,0.8);
  background: #fff;
}
.lightbox .lb-close {
  position: absolute;
  top: 20px;
  left: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.9);
  color: #000;
  border: none;
  cursor: pointer;
  font-size: 24px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}
.lightbox .lb-close:hover { background: #fff; }


/* ===== Workflow Steps (تاریخچه گردش‌کار) ===== */
.step {
  display: flex;
  gap: 12px;
  padding: 12px;
  border-radius: 10px;
  background: #f8fafc;
  font-size: 13px;
  align-items: flex-start;
  flex-wrap: wrap;
  direction: rtl;
  line-height: 1.7;
}
.step .when {
  color: #64748b;
  min-width: 140px;
  font-size: 12px;
  flex-shrink: 0;
}
.step .act {
  font-weight: 700;
  color: #1d4ed8;
  min-width: 80px;
  flex-shrink: 0;
}
.step .flow {
  color: #0f172a;
  font-weight: 500;
  flex: 1;
  min-width: 150px;
}
.step .cmt {
  color: #475569;
  font-size: 12px;
  flex-basis: 100%;
  padding-top: 6px;
  border-top: 1px dashed #e2e8f0;
  margin-top: 6px;
}


/* ===== MOBILE ===== */
@media (max-width: 768px) {
  html, body { font-size: 15px; }
  
  /* ===== Login page ===== */
  .login-card {
    width: calc(100vw - 32px) !important;
    max-width: 420px;
    padding: 28px 20px !important;
    border-radius: 20px !important;
  }
  .login-logo { width: 72px !important; height: 72px !important; }
  .login-card h1 { font-size: 18px !important; }
  .login-card input { font-size: 16px !important; padding: 14px !important; }
  .login-card button { font-size: 16px !important; padding: 14px !important; }
  .captcha-box { width: 180px !important; height: 56px !important; }
  .captcha-wrap input { font-size: 18px !important; }
  
  /* ===== Windows shell ===== */
  .win-topbar {
    top: 6px !important;
    left: 6px !important;
    right: 6px !important;
    height: 54px !important;
    padding: 0 12px !important;
    border-radius: 14px !important;
    gap: 8px !important;
  }
  .brand img { width: 32px !important; height: 32px !important; }
  .brand-title { font-size: 13px !important; }
  .brand-sub { font-size: 10px !important; }
  .today { font-size: 11px !important; display: none; }
  .user-chip { font-size: 11px !important; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  
  /* ===== Desktop icons grid ===== */
  .win-desktop {
    inset: 70px 6px 78px 6px !important;
    padding: 12px !important;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
    gap: 10px !important;
  }
  .icon {
    padding: 14px 10px !important;
    border-radius: 14px !important;
  }
  .icon .emoji { font-size: 30px !important; margin-bottom: 6px !important; }
  .icon .label { font-size: 13px !important; }
  .icon .sub { font-size: 10px !important; }
  
  /* ===== Taskbar ===== */
  .win-taskbar {
    bottom: 6px !important;
    left: 6px !important;
    right: 6px !important;
    transform: none !important;
    height: 56px !important;
    padding: 0 8px !important;
    border-radius: 16px !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .tb-start { width: 44px !important; height: 44px !important; flex-shrink: 0; }
  .tb-app { width: 40px !important; height: 40px !important; font-size: 20px !important; flex-shrink: 0; }
  .tb-tray { display: none !important; }
  
  /* ===== Start menu ===== */
  .start-menu {
    bottom: 72px !important;
    left: 6px !important;
    right: 6px !important;
    width: auto !important;
    transform: translateY(20px) !important;
    max-height: 70vh;
    overflow-y: auto;
    padding: 16px !important;
  }
  .start-menu.open {
    transform: translateY(0) !important;
  }
  .sm-items {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  .sm-item {
    padding: 16px 8px !important;
    font-size: 13px !important;
  }
  .sm-item .emoji { font-size: 26px !important; }
  
  /* ===== Window overlay (فورم‌ها) ===== */
  .win-window {
    top: 6px !important;
    left: 6px !important;
    right: 6px !important;
    bottom: 6px !important;
    width: auto !important;
    height: auto !important;
    max-height: calc(100vh - 12px) !important;
    transform: scale(0.96) !important;
    border-radius: 16px !important;
  }
  .win-window.open {
    transform: scale(1) !important;
  }
  .win-titlebar {
    padding: 12px 14px !important;
  }
  .win-title { font-size: 14px !important; }
  .win-body {
    padding: 14px !important;
  }
  
  /* ===== Forms ===== */
  .form-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
  .form-grid label { font-size: 13px !important; }
  .form-grid input,
  .form-grid select,
  .form-grid textarea {
    font-size: 16px !important;
    padding: 12px !important;
  }
  
  /* ===== Tables (بزرگ‌نمایی عمودی + اسکرول افقی) ===== */
  .tbl { font-size: 13px !important; }
  .tbl th, .tbl td { padding: 12px 10px !important; white-space: nowrap; }
  .tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  
  /* ===== KPI cards ===== */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }
  .kpi { padding: 14px !important; }
  .kpi .label { font-size: 11px !important; }
  .kpi .value { font-size: 22px !important; }
  
  /* ===== Sections ===== */
  .section { padding: 14px !important; border-radius: 12px !important; }
  .section h3 { font-size: 15px !important; margin-bottom: 10px !important; }
  
  /* ===== Buttons ===== */
  button.primary, button.ghost, button.danger {
    padding: 12px 18px !important;
    font-size: 14px !important;
    border-radius: 10px !important;
  }
  .row-actions {
    gap: 8px !important;
    flex-wrap: wrap !important;
  }
  .row-actions button { flex: 1 1 auto; min-width: 120px; }
  
  /* ===== Steps (تاریخچه) ===== */
  .step {
    flex-direction: column !important;
    gap: 6px !important;
    padding: 12px !important;
  }
  .step .when { font-size: 11px !important; min-width: auto !important; }
  .step .act { font-size: 13px !important; }
  .step .flow { font-size: 12px !important; }
  .step .cmt { font-size: 11px !important; }
  
  /* ===== Attachments ===== */
  .att-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }
  .att-thumb { height: 100px !important; }
  
  /* ===== Calendar popup ===== */
  .jalcal-pop {
    width: calc(100vw - 24px) !important;
    max-width: 320px;
    left: 12px !important;
    right: 12px !important;
  }
  .jalcal-day { padding: 8px 0 !important; font-size: 14px !important; }
  
  /* ===== Lightbox ===== */
  .lightbox .lb-close { top: 10px !important; left: 10px !important; }
  
  /* ===== Scrollbars ===== */
  ::-webkit-scrollbar { width: 6px; height: 6px; }
  ::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 3px; }
}

/* ===== Extra small phones ===== */
@media (max-width: 400px) {
  .win-desktop {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  .icon { padding: 12px 8px !important; }
  .icon .emoji { font-size: 26px !important; }
  .icon .label { font-size: 12px !important; }
  .kpi-grid { grid-template-columns: 1fr !important; }
  .att-grid { grid-template-columns: 1fr !important; }
}

/* ===== Landscape phone ===== */
@media (max-height: 500px) and (orientation: landscape) {
  .win-desktop { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)) !important; }
  .win-window { top: 4px !important; bottom: 4px !important; }
  .start-menu { max-height: 85vh !important; }
}

/* ===== Touch improvements ===== */
@media (hover: none) and (pointer: coarse) {
  button, .icon, .sm-item, .tb-app, .jalcal-day, .att-thumb {
    -webkit-tap-highlight-color: rgba(43,108,176,0.15);
  }
  button:active, .icon:active, .tb-app:active {
    transform: scale(0.96);
    transition: transform 0.08s ease;
  }
}
