@font-face {
  font-family: "sf-arabic-regular";
  src: url("./assets/sf-arabic-regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "ALKATIP";
  src: url("./assets/ALKATIP.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  font-family: "ALKATIP", "sf-arabic-regular", system-ui, sans-serif;
  --app-bg: #f4f5f7;
  --panel-bg: #fff;
  --panel-soft-bg: #fafbfc;
  --text: #111;
  --text-muted: #66707c;
  --text-subtle: #707680;
  --text-soft: #969696;
  --border: #d8dce2;
  --border-strong: #d9dce2;
  --hover-bg: #f1f4f8;
  --active-bg: #eaf1ff;
  --switch-bg: #f6f7f9;
  --primary: #256ee8;
  --primary-text: #fff;
  --black-button-bg: #111;
  --black-button-text: #fff;
  --secondary-button-bg: #ddd;
  --secondary-button-text: #111;
  --danger: #bf2020;
  --danger-hover: #8f1515;
  --menu-shadow: 0 10px 28px rgba(24, 32, 44, 0.16);
  color: var(--text);
  background: var(--app-bg);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --app-bg: #0f1115;
    --panel-bg: #171a20;
    --panel-soft-bg: #1f2430;
    --text: #f2f4f8;
    --text-muted: #a6afbd;
    --text-subtle: #8e99aa;
    --text-soft: #7f8896;
    --border: #303744;
    --border-strong: #343b48;
    --hover-bg: #222936;
    --active-bg: #18345e;
    --switch-bg: #202631;
    --primary: #4f8cff;
    --primary-text: #fff;
    --black-button-bg: #f2f4f8;
    --black-button-text: #111;
    --secondary-button-bg: #303744;
    --secondary-button-text: #f2f4f8;
    --danger: #ff6b6b;
    --danger-hover: #ff8b8b;
    --menu-shadow: 0 12px 30px rgba(0, 0, 0, 0.42);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  color: var(--text);
  background: var(--app-bg);
  direction: rtl;
  text-align: right;
  font-family: "ALKATIP", "sf-arabic-regular", system-ui, sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  grid-template-areas: "projects workbench";
  background: var(--app-bg);
}

.projects-panel {
  grid-area: projects;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border-strong);
  background: var(--panel-bg);
}

.panel-header {
  position: relative;
  min-height: 76px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}

.panel-header h2,
.timeline-header h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.clear-projects-button {
  margin-top: 9px;
  padding: 0;
  color: var(--danger);
  background: transparent;
  font-size: 13px;
  font-weight: 750;
}

.clear-projects-button:hover {
  color: var(--danger-hover);
}

#serverLed {
  flex: 0 0 auto;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.22);
  background: #d11f1f;
  box-shadow:
    0 0 0 4px rgba(209, 31, 31, 0.14),
    0 0 12px rgba(209, 31, 31, 0.58);
}

#serverLed.server-available {
  background: #18a058;
  box-shadow:
    0 0 0 4px rgba(24, 160, 88, 0.14),
    0 0 12px rgba(24, 160, 88, 0.58);
}

#serverLed.server-working {
  background: #d9a300;
  box-shadow:
    0 0 0 4px rgba(217, 163, 0, 0.16),
    0 0 12px rgba(217, 163, 0, 0.6);
}

#serverLed.server-offline {
  background: #d11f1f;
  box-shadow:
    0 0 0 4px rgba(209, 31, 31, 0.14),
    0 0 12px rgba(209, 31, 31, 0.58);
}

.project-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 8px;
}

.project-empty {
  padding: 22px 14px;
  color: var(--text-subtle);
  font-size: 14px;
  line-height: 1.7;
}

.project-item {
  position: relative;
  width: 100%;
  border-radius: 8px;
  color: var(--text);
  background: transparent;
}

.project-item.menu-open {
  z-index: 10;
}

.project-select {
  width: 100%;
  display: block;
  padding: 10px 38px 11px 10px;
  border-radius: 8px;
  color: inherit;
  background: transparent;
  text-align: right;
}

.project-item:hover .project-select {
  background: var(--hover-bg);
}

.project-item.active .project-select {
  background: var(--active-bg);
}

.project-menu-button {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  color: var(--text-muted);
  background: transparent;
  direction: ltr;
  font-size: 17px;
  font-weight: 900;
  line-height: 1;
}

.project-menu-button:hover {
  background: var(--hover-bg);
}

.project-menu {
  position: absolute;
  top: 38px;
  left: 8px;
  z-index: 20;
  min-width: 132px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
  box-shadow: var(--menu-shadow);
}

.project-menu-item {
  width: 100%;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 6px;
  color: var(--text);
  background: transparent;
  text-align: right;
  font-size: 13px;
  font-weight: 750;
}

.project-menu-item:hover {
  background: var(--hover-bg);
}

.project-menu-item.danger {
  color: var(--danger);
}

.project-title {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 14px;
  font-weight: 800;
}

.project-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 5px;
  color: var(--text-subtle);
  direction: ltr;
  font-size: 12px;
}

.workbench {
  grid-area: workbench;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(90px, 0.75fr) minmax(120px, 1.25fr);
  gap: 12px;
  padding: 20px;
  overflow: hidden;
}

.app-header {
  min-width: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.app-header > div {
  min-width: 0;
}

.app-title-line {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 3.1vw, 44px);
  line-height: 1.05;
  font-weight: 850;
  letter-spacing: 0;
}

.author-mark {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text-muted);
  direction: ltr;
  font-family: system-ui, sans-serif;
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
}

.author-mark img {
  width: 26px;
  height: 26px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: #fff;
  object-fit: contain;
}

.active-project-title {
  margin-top: 6px;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-block {
  flex: 0 0 auto;
  max-width: 360px;
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  direction: rtl;
}

#backendLabel {
  min-width: 0;
  color: var(--text-soft);
  direction: ltr;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status {
  min-width: 0;
  color: var(--text-muted);
  direction: rtl;
  text-align: right;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
}

.primary-button,
.secondary-button,
.file-button {
  min-height: 40px;
  padding: 0 18px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 750;
  white-space: nowrap;
}

.primary-button {
  color: var(--black-button-text);
  background: var(--black-button-bg);
}

.secondary-button {
  color: var(--secondary-button-text);
  background: var(--secondary-button-bg);
}

.file-button {
  color: var(--primary-text);
  background: var(--primary);
}

.file-picker {
  position: relative;
  min-width: 0;
  max-width: 100%;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

.file-picker.disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.file-picker-caption {
  flex: 0 0 auto;
  font-weight: 750;
  white-space: nowrap;
}

.file-picker-control {
  min-width: 0;
  width: min(340px, 44vw);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  direction: rtl;
}

.file-picker-action {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  color: var(--text);
  background: var(--panel-soft-bg);
  font-weight: 750;
  white-space: nowrap;
}

.selected-file-name {
  min-width: 0;
  overflow: hidden;
  color: var(--text-muted);
  direction: auto;
  text-align: start;
  font-family: system-ui, sans-serif;
  font-size: 14px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.download-buttons {
  display: none;
  align-items: center;
  gap: 8px;
  direction: rtl;
}


.download-label {
  flex: 0 0 auto;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 750;
  white-space: nowrap;
}

.download-button {
  min-height: 34px;
  min-width: 50px;
  padding: 0 12px;
  border-radius: 6px;
  color: var(--primary-text);
  background: var(--primary);
  font-size: 13px;
  font-weight: 750;
  white-space: nowrap;
  direction: ltr;
  cursor: pointer;
}

.download-button:hover {
  filter: brightness(1.12);
}

.download-button:active {
  filter: brightness(0.95);
}

.transcript-pane {
  min-height: 0;
  padding: 8px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
  color: var(--text);
  font-size: clamp(14px, 1.05vw, 18px);
  line-height: 1.55;
  direction: rtl;
  text-align: start;
  text-indent: 0;
  overflow: auto;
  overflow-wrap: break-word;
}

#confirmed {
  margin: 0;
  padding: 0;
  color: var(--text);
  text-indent: 0;
}

#unconfirmed {
  margin: 0;
  padding: 0;
  color: var(--text-soft);
  text-indent: 0;
}

.timeline-pane {
  min-height: 0;
  padding: 12px 14px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
  overflow: hidden;
}

.timeline-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.view-switch {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--switch-bg);
}

.view-switch button {
  min-width: 58px;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 6px;
  color: var(--text-muted);
  background: transparent;
  font-size: 13px;
  font-weight: 750;
}

.view-switch button.active {
  color: var(--primary-text);
  background: var(--primary);
}

#segmentCount {
  margin-right: auto;
  color: var(--text-subtle);
  font-size: 13px;
  direction: ltr;
}

.result-content {
  height: calc(100% - 38px);
  min-height: 0;
  overflow: auto;
}

.timeline-list {
  display: grid;
  grid-auto-rows: max-content;
  align-content: start;
  gap: 8px;
  direction: rtl;
}

.timeline-empty {
  color: var(--text-subtle);
  direction: rtl;
  font-size: 14px;
}

.segment-card {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  min-height: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft-bg);
  direction: rtl;
  text-align: right;
  overflow: visible;
}

.segment-time {
  display: block;
  direction: ltr;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  text-align: left;
}

.segment-text {
  margin: 0;
  min-width: 0;
  overflow: visible;
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  white-space: normal;
  word-break: break-word;
}

.whole-transcript {
  min-height: 100%;
  padding: 0;
  color: var(--text);
  direction: rtl;
  text-align: start;
  text-indent: 0;
  white-space: pre-wrap;
  font-size: 18px;
  line-height: 1.8;
}

@media (max-width: 800px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(118px, 24vh);
    grid-template-areas:
      "workbench"
      "projects";
  }

  .projects-panel {
    min-height: 0;
    border-top: 1px solid var(--border-strong);
    border-left: 0;
  }

  .panel-header {
    min-height: 56px;
    padding: 12px 14px 10px;
  }

  .clear-projects-button {
    margin-top: 6px;
  }

  .project-list {
    padding: 6px;
  }

  .workbench {
    grid-template-rows: auto auto minmax(70px, 0.8fr) minmax(100px, 1fr);
    gap: 10px;
    padding: 14px;
  }

  .app-header {
    gap: 10px;
  }

  h1 {
    font-size: clamp(24px, 4vw, 36px);
  }

  .author-mark {
    font-size: 13px;
  }

  .author-mark img {
    width: 23px;
    height: 23px;
  }

  .active-project-title {
    font-size: 13px;
  }

  .status-block {
    max-width: 260px;
    margin-top: 4px;
  }

  .status {
    font-size: 13px;
  }

  .toolbar {
    gap: 8px;
  }

  .primary-button,
  .secondary-button,
  .file-button {
    min-height: 38px;
    padding: 0 14px;
    font-size: 14px;
  }

  .file-picker {
    min-height: 38px;
    gap: 8px;
    font-size: 14px;
  }

  .file-picker-control {
    width: min(300px, 48vw);
  }

  .file-picker-action {
    min-height: 30px;
    padding: 0 10px;
  }

  .selected-file-name {
    font-size: 13px;
  }

  .transcript-pane {
    font-size: 15px;
    line-height: 1.5;
  }

  .timeline-pane {
    padding: 10px;
  }

  .timeline-header {
    margin-bottom: 8px;
  }

  .result-content {
    height: calc(100% - 34px);
  }

  .segment-card {
    grid-template-columns: 1fr;
    gap: 5px;
    padding: 8px 10px;
  }

  .segment-time {
    text-align: right;
  }

  .whole-transcript {
    font-size: 15px;
    line-height: 1.65;
  }
}

@media (max-width: 800px) {
  .app-header {
    align-items: flex-start;
  }

  .toolbar {
    align-items: stretch;
  }

  .file-picker {
    flex: 1 1 280px;
  }

  .file-button {
    flex: 1 1 180px;
  }

  .primary-button,
  .secondary-button {
    flex: 0 0 auto;
  }
}
