:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --ink: #1e2930;
  --muted: #647177;
  --line: #d9d5ca;
  --surface: #ffffff;
  --surface-strong: #fdfaf3;
  --blue: #1f6f8b;
  --green: #2f7d5b;
  --red: #a24d4a;
  --gold: #a56d16;
  --shadow: 0 18px 50px rgba(35, 43, 47, 0.10);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow-x: hidden;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}

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

button,
.file-button {
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  min-height: 42px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 160ms ease, background 160ms ease, opacity 160ms ease;
}

button:hover,
.file-button:hover {
  background: #0f1d24;
}

button:active,
.file-button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 56px) 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 0.85rem;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 3.4rem);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 6px;
  font-size: 1.25rem;
  letter-spacing: 0;
}

p {
  color: var(--muted);
  line-height: 1.7;
}

.status-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--green);
  font-size: 0.92rem;
  font-weight: 700;
  padding: 9px 14px;
  white-space: nowrap;
}

.app-shell {
  width: min(1440px, calc(100% - 36px));
  margin: 0 auto 36px;
  min-width: 0;
}

.input-panel,
.table-panel,
.top-words-panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.input-panel {
  padding: clamp(16px, 2vw, 24px);
}

.panel-heading,
.controls-row,
.filter-row,
.actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.panel-heading {
  justify-content: space-between;
  margin-bottom: 14px;
}

.panel-heading.compact {
  padding: 18px 18px 10px;
  margin-bottom: 0;
}

.file-button input {
  display: none;
}

textarea {
  width: 100%;
  min-height: 210px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  color: var(--ink);
  background: var(--surface-strong);
  line-height: 1.9;
  outline: none;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31, 111, 139, 0.14);
}

.controls-row {
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 14px;
}

.controls-row label {
  color: var(--muted);
  font-weight: 700;
}

select,
input[type="search"] {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  min-height: 42px;
  padding: 0 12px;
  outline: none;
}

.summary-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  min-height: 104px;
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 2rem;
  line-height: 1;
}

.metric.noun strong {
  color: var(--green);
}

.metric.verb strong {
  color: var(--red);
}

.metric.particle strong {
  color: var(--gold);
}

.results-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 14px;
  min-width: 0;
}

.filter-row {
  padding: 0 18px 14px;
}

.filter-row input {
  flex: 1;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow: auto;
  max-height: 560px;
  border-top: 1px solid var(--line);
  overscroll-behavior-inline: contain;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1380px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f0ede5;
  color: #46545b;
  font-size: 0.88rem;
}

td {
  background: #fff;
  vertical-align: top;
}

.features-cell {
  min-width: 260px;
  white-space: normal;
}

.morph-features {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 380px;
}

.morph-chip {
  display: inline-flex;
  align-items: stretch;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #faf8f2;
  direction: ltr;
  font-size: 0.78rem;
  line-height: 1.35;
}

.morph-key {
  padding: 3px 6px;
  background: #ede9df;
  color: #46545b;
  font-weight: 700;
}

.morph-value {
  padding: 3px 7px;
  color: var(--ink);
}

.muted-cell {
  color: var(--muted);
}

.review-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 10px;
  background: #fff3d8;
  color: #8a5a00;
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.class-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 700;
}

.class-badge.اسم {
  background: rgba(47, 125, 91, 0.12);
  color: var(--green);
}

.class-badge.فعل {
  background: rgba(162, 77, 74, 0.12);
  color: var(--red);
}

.class-badge.حرف {
  background: rgba(165, 109, 22, 0.14);
  color: var(--gold);
}

.top-words-panel {
  padding: 18px;
  align-self: start;
}

.top-word-group + .top-word-group {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.top-word-group h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.word-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 7px 0;
  color: var(--muted);
}

.word-row strong {
  color: var(--ink);
}

.empty-state {
  color: var(--muted);
  text-align: center;
}

@media (max-width: 980px) {
  .summary-panel,
  .results-layout {
    grid-template-columns: 1fr 1fr;
  }

  .table-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .app-header {
    gap: 12px;
    padding: 20px 14px 12px;
  }

  .app-shell {
    width: min(100% - 20px, 720px);
    margin-bottom: 24px;
  }

  .app-header,
  .panel-heading,
  .controls-row,
  .filter-row {
    align-items: stretch;
    flex-direction: column;
  }

  .summary-panel,
  .results-layout {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 1.8rem;
    line-height: 1.25;
  }

  .status-pill {
    align-self: flex-start;
    white-space: normal;
  }

  .input-panel {
    padding: 14px;
  }

  .panel-heading.compact {
    padding: 14px 14px 10px;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  textarea {
    min-height: 180px;
  }

  .summary-panel {
    gap: 10px;
  }

  .metric {
    min-height: auto;
    padding: 14px;
  }

  .metric strong {
    font-size: 1.7rem;
  }

  .table-wrap {
    max-height: 520px;
  }

  table {
    min-width: 1120px;
  }

  button,
  .file-button,
  select,
  input[type="search"] {
    width: 100%;
  }
}
