:root {
  --bg: #edf2f7;
  --card: #ffffff;
  --text: #17212b;
  --muted: #667583;
  --primary: #1666d8;
  --primary-dark: #0e4fae;
  --border: #d7e0e9;
  --danger-bg: #fff3f3;
  --danger: #a32626;
  --row-height: 32px;
  --header-height: 36px;
  --cell-width: 180px;
  --row-number-width: 72px;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-family: Inter, "Segoe UI", Arial, sans-serif; }
button, input { font: inherit; }
.app-shell { width: min(100% - 28px, 1500px); margin: 18px auto 40px; }
.topbar { display: flex; justify-content: space-between; gap: 20px; align-items: center; margin-bottom: 14px; }
.topbar h1 { margin: 0 0 5px; font-size: clamp(22px, 3vw, 32px); }
.topbar p { margin: 0; color: var(--muted); }
.badge { border: 1px solid #b7cae5; background: #e8f1ff; color: #174f9a; border-radius: 999px; padding: 8px 13px; white-space: nowrap; font-weight: 700; }
.upload-card, .viewer, .document-viewer, .api-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 8px 24px rgba(22, 43, 72, .07); }
.upload-card { padding: 16px; margin-bottom: 14px; }
.drop-zone { min-height: 132px; border: 2px dashed #9db5cf; border-radius: 12px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 7px; cursor: pointer; text-align: center; padding: 20px; background: #f8fbff; transition: .15s ease; }
.drop-zone:hover, .drop-zone.dragging { border-color: var(--primary); background: #eef6ff; transform: translateY(-1px); }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop-zone strong { font-size: 18px; }
.drop-zone span { color: var(--muted); }
.upload-actions { display: flex; gap: 12px; align-items: center; margin-top: 13px; }
button { border: 0; border-radius: 9px; padding: 9px 15px; background: var(--primary); color: white; cursor: pointer; font-weight: 700; }
button:hover:not(:disabled) { background: var(--primary-dark); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.secondary { background: #e8edf2; color: #344250; }
.selected-file { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-block { margin-top: 13px; }
.progress-row { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 7px; color: #44515e; font-size: 14px; }
.progress-track { height: 9px; background: #e5eaf0; border-radius: 999px; overflow: hidden; }
.progress-bar { width: 0; height: 100%; background: linear-gradient(90deg, #1672df, #4b9cff); transition: width .15s linear; }
.warning { margin-top: 12px; padding: 10px 12px; border: 1px solid #efc3c3; background: var(--danger-bg); color: var(--danger); border-radius: 9px; white-space: pre-wrap; }
.hidden { display: none !important; }
.viewer { overflow: hidden; }
.viewer-toolbar { min-height: 52px; display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--border); gap: 15px; }
.sheet-tabs { display: flex; gap: 7px; flex-wrap: wrap; }
.sheet-tab { padding: 7px 11px; background: #eef2f6; color: #3e4c58; font-size: 13px; }
.sheet-tab.active { background: var(--primary); color: white; }
.viewer-stats { display: flex; gap: 14px; color: var(--muted); font-size: 14px; white-space: nowrap; }
.grid-scroll { height: min(70vh, 760px); overflow: auto; position: relative; background: white; outline: none; }
.grid-canvas { position: relative; min-width: 100%; }
.grid-header { position: sticky; top: 0; z-index: 5; height: var(--header-height); display: flex; width: max-content; background: #eef3f8; border-bottom: 1px solid #cfd8e2; font-weight: 700; }
.grid-spacer { position: relative; }
.rows-layer { position: absolute; inset: 0 auto auto 0; }
.grid-row { position: absolute; left: 0; height: var(--row-height); display: flex; width: max-content; border-bottom: 1px solid #edf0f3; background: white; }
.grid-row:nth-child(even) { background: #fbfcfd; }
.grid-cell, .row-number, .header-cell, .header-corner { flex: 0 0 var(--cell-width); width: var(--cell-width); min-width: var(--cell-width); padding: 6px 9px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-right: 1px solid #e3e8ed; font-size: 13px; }
.row-number, .header-corner { flex-basis: var(--row-number-width); width: var(--row-number-width); min-width: var(--row-number-width); position: sticky; left: 0; z-index: 3; text-align: right; color: #65727e; background: #f1f4f7; border-right-color: #cfd8e2; }
.header-corner { z-index: 7; }
.header-cell { text-align: center; color: #2f3c48; }
.grid-cell.loading { color: #a2acb5; font-style: italic; }
.document-viewer { min-height: 72vh; overflow: hidden; }
#pdfFrame { display: block; width: 100%; height: 78vh; border: 0; background: #555; }
.word-shell { overflow: auto; background: #dfe4e9; padding: 24px 12px; max-height: 82vh; }
.word-content { width: 100%; }
.docx-page { width: min(210mm, calc(100% - 8px)); min-height: 297mm; margin: 0 auto 24px; padding: 22mm 20mm; background: white; box-shadow: 0 4px 20px rgba(0,0,0,.16); font-family: Calibri, Arial, sans-serif; font-size: 11pt; line-height: 1.35; color: #111; }
.docx-page p { min-height: 1em; margin: 0 0 8px; white-space: pre-wrap; }
.docx-page h1, .docx-page h2, .docx-page h3, .docx-page h4, .docx-page h5, .docx-page h6 { margin: 14px 0 8px; }
.docx-page img { max-width: 100%; height: auto; display: inline-block; }
.docx-list-item { padding-left: 22px; position: relative; }
.docx-list-item::before { content: "•"; position: absolute; left: 7px; }
.docx-table { width: 100%; border-collapse: collapse; margin: 10px 0; }
.docx-table td { border: 1px solid #555; padding: 5px 7px; vertical-align: top; }
.docx-table p { margin: 0 0 4px; }
.api-card { margin-top: 14px; padding: 13px 16px; }
.api-card summary { cursor: pointer; font-weight: 800; }
.api-card pre { overflow: auto; background: #101820; color: #eaf2f8; border-radius: 9px; padding: 12px; line-height: 1.45; }
.api-card code { font-family: Consolas, monospace; }
@media (max-width: 720px) {
  .app-shell { width: min(100% - 16px, 1500px); margin: 8px auto; }
  .topbar, .viewer-toolbar { align-items: flex-start; flex-direction: column; }
  .upload-actions { align-items: flex-start; flex-direction: column; }
  :root { --cell-width: 150px; }
  .docx-page { padding: 14mm 10mm; }
}

/* v3.1: Excel açıldıqda maksimum brauzer eni */
body.excel-open .app-shell {
  width: calc(100% - 12px);
  max-width: none;
  margin: 6px auto 24px;
}
body.excel-open #excelViewer {
  width: 100%;
  border-radius: 8px;
}
body.excel-open .grid-scroll {
  height: max(520px, calc(100vh - 285px));
  max-height: none;
}

/* v3.1: iframe əvəzinə lokal PDF.js canvas viewer */
.pdf-shell {
  height: min(92vh, 980px);
  min-height: 620px;
  background: #30343a;
  display: flex;
  flex-direction: column;
}
.pdf-toolbar {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: #1f252b;
  border-bottom: 1px solid #4b535b;
  color: #f3f6f8;
}
.pdf-toolbar-group {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}
.pdf-tool-button,
.pdf-text-button,
.pdf-download-link {
  min-height: 34px;
  border: 1px solid #59636d;
  border-radius: 7px;
  background: #343c44;
  color: #f7f9fb;
  padding: 6px 10px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
}
.pdf-tool-button {
  min-width: 36px;
  font-size: 21px;
}
.pdf-text-button,
.pdf-download-link {
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.pdf-tool-button:hover:not(:disabled),
.pdf-text-button:hover:not(:disabled),
.pdf-download-link:hover,
.pdf-text-button.active {
  background: #1666d8;
  border-color: #3984e8;
}
.pdf-page-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #e2e8ee;
  font-size: 14px;
}
.pdf-page-control input {
  width: 64px;
  height: 34px;
  border: 1px solid #5d6872;
  border-radius: 7px;
  background: #11171c;
  color: white;
  text-align: center;
  padding: 4px 6px;
}
.pdf-zoom-label {
  min-width: 54px;
  text-align: center;
  color: #dce3e9;
  font-size: 13px;
  font-weight: 700;
}
.pdf-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow: hidden;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #4a4f55;
  outline: none;
  text-align: center;
}
.pdf-stage:focus-visible {
  box-shadow: inset 0 0 0 2px #4b9cff;
}
.pdf-canvas {
  display: block;
  margin: 0 auto;
  background: white;
  box-shadow: 0 5px 22px rgba(0, 0, 0, .42);
}
.pdf-loading-text {
  display: none;
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  width: max-content;
  max-width: calc(100% - 24px);
  margin: 0;
  padding: 9px 13px;
  border-radius: 999px;
  background: rgba(20, 27, 33, .9);
  color: white;
  font-size: 13px;
  font-weight: 700;
}
.pdf-stage.loading .pdf-loading-text { display: block; }
.pdf-stage.loading .pdf-canvas { opacity: .45; }

@media (max-width: 720px) {
  body.excel-open .app-shell { width: calc(100% - 4px); margin-top: 2px; }
  body.excel-open .grid-scroll { height: max(460px, calc(100vh - 310px)); }
  .pdf-toolbar { align-items: flex-start; }
  .pdf-stage { padding: 8px; min-height: 65vh; }
  .pdf-text-button, .pdf-download-link { font-size: 12px; padding: 6px 8px; }
}


/* PDF tam ekran və hündürlüyə görə bütöv səhifə */
body.pdf-open {
  height: 100dvh;
  overflow: hidden;
  background: #30343a;
}
body.pdf-open .app-shell {
  width: 100%;
  max-width: none;
  height: 100dvh;
  margin: 0;
}
body.pdf-open .topbar,
body.pdf-open .upload-card,
body.pdf-open .api-card {
  display: none;
}
body.pdf-open #pdfViewer {
  width: 100%;
  height: 100dvh;
  min-height: 100dvh;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.pdf-stage.fit-page {
  overflow: hidden;
}
.pdf-stage.scrollable {
  display: block;
  overflow: auto;
  text-align: center;
}
.pdf-stage.scrollable .pdf-canvas {
  margin: 0 auto;
}


/* v3.3: Excel PDF kimi tam ekran */
.excel-toolbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-width: 0;
}
.excel-text-button {
  min-height: 34px;
  flex: 0 0 auto;
  border: 1px solid #b9c8d8;
  border-radius: 8px;
  background: #eef4fb;
  color: #174f9a;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 800;
}
.excel-text-button:hover:not(:disabled) {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
body.excel-open {
  height: 100dvh;
  overflow: hidden;
  background: #fff;
}
body.excel-open .app-shell {
  width: 100%;
  max-width: none;
  height: 100dvh;
  margin: 0;
}
body.excel-open .topbar,
body.excel-open .upload-card,
body.excel-open .api-card {
  display: none;
}
body.excel-open #excelViewer {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  min-height: 100dvh;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
}
body.excel-open .viewer-toolbar {
  flex: 0 0 auto;
  min-height: 52px;
  background: #fff;
}
body.excel-open .sheet-tabs {
  min-width: 0;
  flex: 1 1 auto;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}
body.excel-open .grid-scroll {
  flex: 1 1 auto;
  width: 100%;
  height: auto;
  min-height: 0;
  max-height: none;
  border-radius: 0;
}

@media (max-width: 720px) {
  body.excel-open .app-shell {
    width: 100%;
    height: 100dvh;
    margin: 0;
  }
  body.excel-open #excelViewer {
    height: 100dvh;
    min-height: 100dvh;
  }
  body.excel-open .viewer-toolbar {
    flex-direction: row;
    align-items: center;
    min-height: 48px;
    padding: 6px 8px;
  }
  body.excel-open .grid-scroll {
    height: auto;
    min-height: 0;
  }
  body.excel-open .viewer-stats {
    display: none;
  }
  .excel-toolbar-right {
    gap: 6px;
  }
  .excel-text-button {
    padding: 6px 9px;
    font-size: 12px;
  }
}

/* v3.4: Excel background indeksləmə faizi */
.excel-progress-panel {
  flex: 0 0 auto;
  padding: 7px 12px 8px;
  border-bottom: 1px solid #d7e0ea;
  background: #f7faff;
}
.excel-progress-copy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 6px;
  color: #33465a;
  font-size: 13px;
}
.excel-progress-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.excel-progress-copy strong {
  flex: 0 0 auto;
  min-width: 52px;
  color: #0c61c9;
  text-align: right;
}
.excel-progress-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe8f2;
}
.excel-progress-bar {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #1672df, #55a4ff);
  transition: width .2s linear;
}
.excel-progress-bar.indeterminate {
  animation: excel-progress-slide 1.2s ease-in-out infinite;
}
.excel-progress-panel.complete {
  background: #f1fbf5;
  border-bottom-color: #bfe7cb;
}
.excel-progress-panel.complete .excel-progress-copy,
.excel-progress-panel.complete .excel-progress-copy strong {
  color: #16713a;
}
.excel-progress-panel.complete .excel-progress-bar {
  background: #25a45a;
}
@keyframes excel-progress-slide {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(310%); }
}
@media (max-width: 720px) {
  .excel-progress-panel { padding: 6px 8px 7px; }
  .excel-progress-copy { font-size: 12px; }
  .excel-progress-copy span { white-space: normal; line-height: 1.25; }
}

/* v3.5: minimal upload screen */
body:not(.excel-open):not(.pdf-open):not(.word-open) {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background: #f3f6f9;
}
body:not(.excel-open):not(.pdf-open):not(.word-open) .app-shell {
  width: min(92vw, 520px);
  margin: 0;
}
body:not(.excel-open):not(.pdf-open):not(.word-open) .topbar,
body:not(.excel-open):not(.pdf-open):not(.word-open) .api-card,
body:not(.excel-open):not(.pdf-open):not(.word-open) .upload-internals {
  display: none;
}
body:not(.excel-open):not(.pdf-open):not(.word-open) .upload-card {
  margin: 0;
  padding: 8px;
  border-radius: 16px;
  box-shadow: 0 10px 34px rgba(25, 45, 68, .08);
}
body:not(.excel-open):not(.pdf-open):not(.word-open) .drop-zone {
  min-height: 170px;
  gap: 8px;
  padding: 24px;
  border-radius: 12px;
}
body:not(.excel-open):not(.pdf-open):not(.word-open) .drop-zone strong {
  font-size: 20px;
}
body:not(.excel-open):not(.pdf-open):not(.word-open) .drop-zone span {
  font-size: 13px;
  letter-spacing: .03em;
}
body:not(.excel-open):not(.pdf-open):not(.word-open) .warning {
  margin: 8px 2px 0;
  font-size: 13px;
}

/* v3.5: Word viewer Excel/PDF kimi tam ekran */
body.word-open {
  height: 100dvh;
  overflow: hidden;
  background: #dfe4e9;
}
body.word-open .app-shell {
  width: 100%;
  max-width: none;
  height: 100dvh;
  margin: 0;
}
body.word-open .topbar,
body.word-open .upload-card,
body.word-open .api-card,
body.word-open #excelViewer,
body.word-open #pdfViewer {
  display: none !important;
}
body.word-open #wordViewer {
  display: block;
  position: relative;
  width: 100%;
  height: 100dvh;
  min-height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: #dfe4e9;
}
body.word-open .word-content {
  width: 100%;
  min-height: 100%;
  padding: 14px 12px 36px;
}
body.word-open .docx-page {
  margin-top: 0;
  margin-bottom: 18px;
}
.word-open-file-button {
  display: none;
}
body.word-open .word-open-file-button {
  display: inline-flex;
  position: fixed;
  top: 10px;
  right: 12px;
  z-index: 50;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid rgba(40, 55, 70, .22);
  border-radius: 7px;
  background: rgba(255,255,255,.92);
  color: #334354;
  box-shadow: 0 2px 10px rgba(0,0,0,.12);
  font-size: 12px;
  font-weight: 700;
  backdrop-filter: blur(4px);
}
body.word-open .word-open-file-button:hover {
  background: #fff;
  color: #0e4fae;
}

@media (max-width: 720px) {
  body:not(.excel-open):not(.pdf-open):not(.word-open) .app-shell {
    width: min(94vw, 520px);
    margin: 0;
  }
  body.word-open .word-content {
    padding: 8px 4px 24px;
  }
  body.word-open .docx-page {
    width: calc(100% - 4px);
    padding: 12mm 8mm;
  }
}
