:root {
  --mym-green: #3C7A2E;
  --mym-green-dark: #2A5A20;
  --mym-green-light: #E9F3E6;
  --mym-black: #1A1A1A;
  --mym-gray: #6B6B6B;
  --mym-border: #E2E2E0;
  --mym-bg: #F7F7F5;
  --mym-white: #FFFFFF;
  --mym-red: #C0392B;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--mym-bg);
  color: var(--mym-black);
}

a { color: var(--mym-green); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--mym-white);
  border-right: 1px solid var(--mym-border);
  padding: 1.25rem 1rem;
}

.brand { display: flex; align-items: center; gap: 8px; margin-bottom: 1.75rem; }
.brand img { height: 34px; }

.nav-label {
  font-size: 12px;
  color: var(--mym-gray);
  margin: 1.25rem 0 6px 4px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.nav-group { margin: 0; }
.nav-group summary.nav-label {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 6px;
  list-style: none;
}
.nav-group summary.nav-label::-webkit-details-marker { display: none; }
.nav-group summary.nav-label::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--mym-gray);
  border-bottom: 1.5px solid var(--mym-gray);
  transform: rotate(45deg);
  transition: transform .15s ease;
  margin-top: -3px;
}
.nav-group[open] summary.nav-label::after { transform: rotate(-135deg); margin-top: 2px; }

.nav-item {
  display: block;
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--mym-black);
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--mym-green-light); text-decoration: none; }
.nav-item.active { background: var(--mym-green-light); color: var(--mym-green-dark); font-weight: 600; }

.role-badge {
  display: inline-block;
  background: var(--mym-green-light);
  color: var(--mym-green-dark);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius);
}

.main { flex: 1; padding: 1.5rem 2rem; }

.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; flex-wrap: wrap; gap: 12px; }
.breadcrumb { font-size: 13px; color: var(--mym-gray); margin: 0 0 4px; }
.page-title { font-size: 20px; font-weight: 600; margin: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--mym-border);
  background: var(--mym-white);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  color: var(--mym-black);
}
.btn:hover { border-color: var(--mym-green); text-decoration: none; }
.btn-primary { background: var(--mym-green); border-color: var(--mym-green); color: #fff; }
.btn-primary:hover { background: var(--mym-green-dark); }
.btn-danger { color: var(--mym-red); }
.btn-sm { padding: 5px 10px; font-size: 13px; }

/* ---- Grid of files/folders ---- */
.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.item-card {
  position: relative;
  background: var(--mym-white);
  border: 1px solid var(--mym-border);
  border-radius: 12px;
  padding: 14px;
}
.item-card:hover { border-color: var(--mym-green); }
.item-card.drag-over { border-color: var(--mym-green); background: var(--mym-green-light); box-shadow: inset 0 0 0 2px var(--mym-green); }
.breadcrumb a.drag-over, .btn.drag-over { border-color: var(--mym-green) !important; background: var(--mym-green-light) !important; box-shadow: inset 0 0 0 2px var(--mym-green); }

.item-icon { font-size: 26px; color: var(--mym-green); }
.item-icon.file { color: var(--mym-gray); }

.item-name {
  font-size: 13.5px;
  font-weight: 600;
  margin: 10px 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-meta { font-size: 11.5px; color: var(--mym-gray); }

.item-actions { position: absolute; top: 10px; right: 10px; display: flex; gap: 4px; }
.icon-btn {
  width: 26px; height: 26px;
  border: none; background: transparent;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--mym-gray);
}
.icon-btn:hover { background: var(--mym-green-light); color: var(--mym-green-dark); }

/* ---- Forms / modals ---- */
.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 13px; color: var(--mym-gray); margin-bottom: 4px; }
.form-row input[type=text], .form-row select {
  width: 100%; padding: 9px 10px; border: 1px solid var(--mym-border); border-radius: var(--radius); font-size: 14px;
}

.modal-overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  align-items: center; justify-content: center; z-index: 50;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--mym-white); border-radius: 12px; padding: 1.5rem; width: 320px;
}
.modal-box h3 { margin: 0 0 1rem; font-size: 16px; }

.empty-state { text-align: center; color: var(--mym-gray); padding: 3rem 0; font-size: 14px; }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--mym-bg); }
.login-card {
  width: 340px; background: var(--mym-white); border: 1px solid var(--mym-border); border-radius: 14px; padding: 2rem;
}
.login-card img { height: 42px; display: block; margin: 0 auto 1.5rem; }
.login-card .subtitle { text-align: center; font-size: 13px; color: var(--mym-gray); margin: -1rem 0 1.5rem; }
.login-card input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--mym-border); border-radius: var(--radius); margin-bottom: 12px; font-size: 14px;
}
.login-card button { width: 100%; padding: 10px; }
.alert-error { background: #FBEAEA; color: var(--mym-red); font-size: 13px; padding: 8px 10px; border-radius: var(--radius); margin-bottom: 12px; }
.footer-note { text-align: center; font-size: 12px; color: var(--mym-gray); margin-top: 1.25rem; }

/* ---- PR module: status pill + timeline ---- */
.status-pill { display:inline-block; padding:3px 10px; border-radius:999px; font-size:12px; font-weight:600; color:#fff; }

.pr-timeline { display: flex; align-items: center; margin: 6px 0 4px; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
.pr-tl-step { display: flex; flex-direction: column; align-items: center; text-align: center; flex: 0 0 auto; width: 84px; }
.pr-tl-dot { width: 16px; height: 16px; border-radius: 50%; background: var(--mym-border); border: 3px solid var(--mym-border); box-sizing: content-box; margin-bottom: 6px; }
.pr-tl-label { font-size: 11px; color: var(--mym-gray); font-weight: 600; line-height: 1.2; }
.pr-tl-line { flex: 1 1 auto; height: 3px; background: var(--mym-border); margin: 0 -2px 20px; min-width: 16px; }
.pr-tl-line-done { background: var(--mym-green); }
.pr-tl-step.pr-tl-done .pr-tl-dot { background: var(--mym-green); border-color: var(--mym-green-light); }
.pr-tl-step.pr-tl-done .pr-tl-label { color: var(--mym-green-dark); }
.pr-tl-step.pr-tl-current .pr-tl-dot { background: var(--mym-white); border-color: var(--mym-green); box-shadow: 0 0 0 3px var(--mym-green-light); }
.pr-tl-step.pr-tl-current .pr-tl-label { color: var(--mym-green-dark); }
.pr-tl-step.pr-tl-rejected .pr-tl-dot { background: var(--mym-red); border-color: #F6D9D5; }
.pr-tl-step.pr-tl-rejected .pr-tl-label { color: var(--mym-red); }
@media (max-width: 640px) {
  /* A regular PR's timeline has 6 steps, a Non Trade PR's has 7 (extra
     "HOD Verified" + "Director Approved" split) - neither fits a phone
     width side by side without wrapping/overlapping labels, so switch to
     a vertical stepper instead of shrinking columns further. This must
     match the app's general mobile breakpoint (see the "Mobile (phones)"
     block below) - a gap between the two left the horizontal layout
     active on phones in the 481-640px range, where it visibly overflowed
     the card. */
  .pr-timeline { flex-direction: column; align-items: flex-start; margin: 8px 0 2px; overflow-x: visible; }
  .pr-tl-step { flex-direction: row; align-items: flex-start; width: 100%; text-align: left; gap: 10px; padding: 6px 0; position: relative; }
  .pr-tl-dot { margin-bottom: 0; flex-shrink: 0; position: relative; z-index: 1; }
  .pr-tl-label { font-size: 13px; padding-top: 2px; }
  .pr-tl-line { display: none; }
  .pr-tl-step:not(:last-child)::before {
    content: '';
    position: absolute;
    left: 10px;
    top: 26px;
    bottom: -6px;
    width: 2px;
    background: var(--mym-border);
    transform: translateX(-50%);
  }
  .pr-tl-step.pr-tl-done:not(:last-child)::before { background: var(--mym-green); }
}

/* ---- Mobile (phones, e.g. after scanning a QR share link) ---- */
@media (max-width: 640px) {
  .main { padding: 1rem; max-width: 100% !important; }
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--mym-border); }

  .topbar { gap: 8px; }
  .page-title { font-size: 18px; }
  .breadcrumb { font-size: 13px; }

  .item-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
  .item-card { padding: 12px; }
  .item-icon { font-size: 36px; }
  .item-name { font-size: 15px; white-space: normal; }
  .item-meta { font-size: 13px; }

  .btn { padding: 10px 16px; font-size: 15px; }
  .icon-btn { width: 34px; height: 34px; }

  .login-card { width: 100%; padding: 1.5rem; }
}

/* =======================================================================
 * File preview modal + mobile search
 * -----------------------------------------------------------------------
 * Tapping a file on a phone used to hand it straight to the browser's
 * download prompt. It now opens here instead, with an explicit close
 * button and Download / Open-in-new-tab as deliberate choices.
 * ======================================================================= */
.preview-box {
  width: min(920px, 94vw);
  max-height: 90vh;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.preview-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--mym-border);
}
.preview-title {
  margin: 0; font-size: 15px; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.preview-close { flex-shrink: 0; }
.preview-body {
  flex: 1; min-height: 0; overflow: auto;
  background: var(--mym-bg);
  display: flex; align-items: center; justify-content: center;
}
.preview-img   { max-width: 100%; max-height: 78vh; display: block; }
.preview-frame { width: 100%; height: 78vh; border: 0; background: var(--mym-white); }
.preview-text  {
  margin: 0; padding: 14px; width: 100%; align-self: stretch;
  font-size: 13px; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
  background: var(--mym-white);
}
.preview-none      { text-align: center; color: var(--mym-gray); padding: 2.5rem 1rem; }
.preview-none-icon { font-size: 44px; margin-bottom: 10px; }
.preview-none-hint { font-size: 13px; margin: 6px 0 0; }
.preview-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 14px;
  border-top: 1px solid var(--mym-border);
}

/* ---- search bar ------------------------------------------------------ */
.file-search { display: flex; gap: 6px; flex: 1; min-width: 0; }
.file-search-input {
  padding: 8px 10px;
  border: 1px solid var(--mym-border);
  border-radius: var(--radius);
  font-size: 14px;
  width: 220px;
}
.file-search-btn { flex-shrink: 0; }

/* ---- phones ---------------------------------------------------------- */
@media (max-width: 640px) {
  /* The toolbar was a single non-wrapping flex row: a fixed 220px search
     box next to three buttons, which squeezed the search box off-screen. */
  .x-c850abf.x-c850abf { flex-wrap: wrap; }
  .file-search { flex: 1 1 100%; order: -1; }
  .file-search-input { width: auto; flex: 1; min-width: 0; font-size: 16px; }  /* 16px stops iOS zooming on focus */

  /* .item-actions is position:absolute top-right on desktop. On a phone the
     card shrinks to ~130px while the icon buttons grow to 34px, so four or
     five of them are WIDER than the card and sit on top of the file link -
     tapping the middle of a card hit "Version history" instead of opening
     the file. Put them back in normal flow underneath the name. */
  .item-actions {
    position: static;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--mym-border);
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .preview-box   { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .preview-body  { align-items: flex-start; }
  .preview-img   { max-height: none; }
  .preview-frame { height: 100%; min-height: 60vh; }
  .preview-foot  { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .preview-foot .btn { flex: 1; text-align: center; }
}

/* ---- Mobile navigation bar ------------------------------------------- */
/* Hidden on desktop: the sidebar is always visible there. */
.mobile-bar { display: none; }

@media (max-width: 640px) {
  .mobile-bar {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    background: var(--mym-white);
    border-bottom: 1px solid var(--mym-border);
    position: sticky; top: 0; z-index: 40;
  }
  .mobile-bar-title { font-weight: 600; font-size: 15px; }
  .mobile-menu-btn  { padding: 8px 12px; font-size: 15px; }

  /* Collapsed by default so the file list and its search box are the first
     thing on screen. Tapping Menu reveals the full nav. */
  .sidebar { display: none; }
  .sidebar.nav-open { display: block; }
}

/* Search result path, shown under a hit in a shared folder. */
.item-path { font-style: italic; word-break: break-word; }
.share-search { margin: 0 0 14px; max-width: 520px; }

/* Single shared file: the page itself is the viewer. */
.file-view {
  background: var(--mym-bg);
  border: 1px solid var(--mym-border);
  border-radius: 12px;
  min-height: 55vh;
  display: flex; align-items: center; justify-content: center;
  overflow: auto;
}
.file-view .preview-img   { max-height: 72vh; }
.file-view .preview-frame { height: 72vh; }
.file-view-foot { border-top: 0; padding-left: 0; padding-right: 0; }

@media (max-width: 640px) {
  .file-view { min-height: 62vh; border-radius: 10px; }
  .file-view .preview-img   { max-height: none; }
  .file-view .preview-frame { height: 62vh; }
  .file-view-foot .btn { flex: 1; text-align: center; }
}

/* =======================================================================
 * Drag files in from the desktop
 * ======================================================================= */
.dropzone-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 60;
  background: rgba(60, 122, 46, .12);
  backdrop-filter: blur(1px);
  align-items: center; justify-content: center;
  pointer-events: none;               /* the drop must reach the page beneath */
}
.dropzone-overlay.open { display: flex; }
.dropzone-card {
  background: var(--mym-white);
  border: 2px dashed var(--mym-green);
  border-radius: 16px;
  padding: 2rem 2.5rem;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,.15);
}
.dropzone-icon  { font-size: 40px; color: var(--mym-green); line-height: 1; }
.dropzone-title { margin: 10px 0 4px; font-size: 18px; font-weight: 600; }
.dropzone-sub   { margin: 0; font-size: 14px; color: var(--mym-gray); }

.upload-toast {
  display: none;
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 70;
  max-width: min(560px, 92vw);
  background: var(--mym-black, #222); color: #fff;
  padding: 12px 18px; border-radius: 10px;
  font-size: 14px; line-height: 1.4;
  box-shadow: 0 8px 28px rgba(0,0,0,.25);
}
.upload-toast.open { display: block; }

@media (max-width: 640px) {
  .dropzone-card { padding: 1.5rem; margin: 0 16px; }
  .upload-toast  { bottom: 12px; width: calc(100vw - 24px); text-align: center; }
}

/* ---- Recycle bin ----------------------------------------------------- */
.table-wrap      { overflow-x: auto; }
.recycle-table   { width: 100%; }
.recycle-icon    { margin-right: 6px; }
.recycle-actions { white-space: nowrap; }
.recycle-actions form { display: inline; margin-right: 4px; }

@media (max-width: 640px) {
  .recycle-actions { white-space: normal; }
  .recycle-actions form { display: block; margin: 0 0 6px; }
  .recycle-actions .btn { width: 100%; }
}
