[hidden] {
  display: none !important;
}

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --primary: #0f172a;
  --primary-hover: #1e293b;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --wisp-color: #2563eb;
  --ftth-color: #7c3aed;
  --radius: 12px;
  --font-stack: system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-stack);
  background-color: var(--bg);
  color: var(--text-main);
  line-height: 1.5;
}

input, select, button {
  font: inherit;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  transition: all 0.2s ease-in-out;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.9rem;

  & input, & select {
    background: var(--surface);
    color: var(--text-main);
    padding: 0.75rem 0.9rem;
    &:focus {
      outline: none;
      border-color: var(--primary);
      box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.05);
    }
  }
}

.helper-text {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  line-height: 1.3;
}

.info-alert {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: #f5f3ff;
  border: 1px solid #ddd6fe;
  color: #5b21b6;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 1rem;

  & svg {
    flex-shrink: 0;
  }
}

.contact-phone-link {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.tx-info-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.88rem;

  & .tx-info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
  }
}

button {
  background: var(--surface);
  color: var(--text-main);
  padding: 0.65rem 1.1rem;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 0.55rem;

  &:hover { background: #f1f5f9; }
  &:active { transform: scale(0.98); }

  & svg {
    flex-shrink: 0;
  }

  &.danger {
    color: var(--danger);
    border-color: #fecaca;
    background: var(--danger-bg);
    &:hover { background: #fee2e2; }
  }

  &.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.75rem;
    gap: 0.4rem;
  }
}

.icon-inline {
  display: inline-block;
  vertical-align: middle;
  margin-inline-end: 0.45rem;
  flex-shrink: 0;
}

.brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.75rem;

  & .app-logo {
    width: 72px;
    height: 72px;
    object-fit: contain;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.08));
  }
}

/* Authentication Screen */
#login-view {
  min-height: 100vh;
  display: grid;
  place-content: center;
  padding: 1.5rem;

  & article {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.25rem 2rem;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);

    & header {
      text-align: center;
      margin-bottom: 1.75rem;
      & h1 { font-size: 1.6rem; font-weight: 700; }
      & p { color: var(--text-muted); font-size: 0.9rem; }
    }

    & button[type="submit"] {
      width: 100%;
      background: var(--primary);
      color: #ffffff;
      margin-top: 0.5rem;
      padding: 0.8rem;
      &:hover { background: var(--primary-hover); }
    }
  }
}

/* Dashboard App View */
#app-view {
  max-width: 620px;
  margin: 0 auto;
  padding: 1rem;

  & > header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface);
    padding: 0.9rem 1.2rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 0.75rem;

    & .user-brand-header {
      display: flex;
      align-items: center;
      gap: 0.75rem;

      & .app-logo-nav {
        width: 38px;
        height: 38px;
        object-fit: contain;
        flex-shrink: 0;
        filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.06));
      }
    }

    & h2 { font-size: 1.15rem; font-weight: 700; }
    & small { color: var(--success); font-weight: 600; font-size: 0.8rem; }
    & nav { display: flex; gap: 0.4rem; & button { padding: 0.45rem 0.8rem; font-size: 0.85rem; } }
  }

  & .credits-bar {
    margin-bottom: 0.75rem;

    & .credit-pill {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      padding: 0.75rem 1rem;
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-size: 0.85rem;
      cursor: pointer;
      user-select: none;
      transition: background 0.15s ease;

      &:hover { background: #f8fafc; }
      & strong { font-size: 1.05rem; }
    }
  }

  & .toolbar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;

    & .search-input-wrapper {
      position: relative;
      flex: 1;
      display: flex;
      align-items: center;

      & .search-icon {
        position: absolute;
        right: 0.85rem;
        pointer-events: none;
        stroke: var(--text-muted);
        flex-shrink: 0;
      }

      & input[type="search"] {
        width: 100%;
        background: var(--surface);
        padding: 0.65rem 0.9rem;
        padding-right: 2.35rem;
      }
    }

    & select {
      background: var(--surface);
      padding: 0.65rem 0.75rem;
    }

    & button {
      background: var(--primary);
      color: #ffffff;
      white-space: nowrap;
      gap: 0.5rem;
      &:hover { background: var(--primary-hover); }
    }
  }
}

/* Customer, Tx & Log Cards */
#customers-list, #detail-tx-list, #logs-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;

  & article {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);

    & header {
      display: flex;
      justify-content: space-between;
      align-items: center;

      & strong { font-size: 1.05rem; }
      & .badges {
        display: flex;
        gap: 0.35rem;
        align-items: center;
      }

      & span {
        font-size: 0.75rem;
        padding: 0.2rem 0.55rem;
        border-radius: 99px;
        font-weight: 600;

        &.wisp { background: #eff6ff; color: var(--wisp-color); border: 1px solid #bfdbfe; }
        &.ftth { background: #f5f3ff; color: var(--ftth-color); border: 1px solid #ddd6fe; }
        &.debt { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
        &.clear { background: var(--success-bg); color: var(--success); border: 1px solid #bbf7d0; }
        &.badge-info { background: #f1f5f9; color: var(--text-main); }
        &.badge-log { background: #f8fafc; color: var(--text-muted); border: 1px solid var(--border); }
      }
    }

    & p {
      font-size: 0.88rem;
      color: var(--text-muted);
      display: flex;
      flex-wrap: wrap;
      gap: 0.75rem 1.25rem;

      & a { color: var(--text-main); text-decoration: none; font-weight: 500; }
    }

    & footer {
      display: flex;
      gap: 0.5rem;
      margin-top: 0.5rem;
      padding-top: 0.75rem;
      border-top: 1px solid #f1f5f9;

      & button {
        flex: 1;
        padding: 0.5rem;
        font-size: 0.85rem;

        &:first-child { background: var(--primary); color: #ffffff; &:hover { background: var(--primary-hover); } }
      }
    }
  }
}

/* Modals & Dialogs */
dialog {
  margin: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-main);
  padding: 1.5rem;
  width: calc(100% - 2rem);
  max-width: 480px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);

  &::backdrop {
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(2px);
  }

  & header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;

    & .dialog-close {
      background: transparent;
      border: none;
      font-size: 1.2rem;
      color: var(--text-muted);
      cursor: pointer;
      padding: 0.2rem 0.5rem;
      &:hover { color: var(--text-main); }
    }
  }

  & footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    margin-top: 1.25rem;
    & button:last-child {
      background: var(--primary);
      color: #ffffff;
      &:hover { background: var(--primary-hover); }
    }
  }
}

#customer-detail-dialog {
  max-width: 520px;
  width: min(520px, calc(100% - 2rem));
  max-height: 85vh;
  overflow-y: auto;
  overflow-x: hidden;

  & section {
    margin-top: 1.25rem;
    & h4 { font-size: 0.95rem; color: var(--text-muted); margin-bottom: 0.65rem; }
  }
}

#logs-dialog {
  max-width: 640px;
  width: min(640px, calc(100% - 2rem));
  max-height: 85vh;
  overflow-y: auto;
  overflow-x: hidden;

  & section {
    margin-top: 1rem;
    & h4 { font-size: 0.95rem; color: var(--text-muted); margin-bottom: 0.65rem; }
  }
}

#reports-dialog {
  max-width: 580px;
  width: min(580px, calc(100% - 2rem));
  max-height: 85vh;
  overflow-y: auto;
  overflow-x: hidden;
  & .metrics {
    display: grid;
    gap: 0.65rem;
    margin-bottom: 0.5rem;
    & article {
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 1rem;
      text-align: center;
      & small { color: var(--text-muted); display: block; font-size: 0.8rem; }
      & strong { font-size: 1.45rem; font-weight: 700; }
    }
  }
  & footer { flex-direction: column; & button { width: 100%; } }
}

/* Custom System Dialog (Alert / Confirm) */
.system-dialog {
  max-width: 400px;
  text-align: center;
  padding: 1.75rem 1.5rem;
  border-radius: var(--radius);

  & .system-dialog-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
  }

  & .alert-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.25rem;

    &.success {
      background: var(--success-bg);
      color: var(--success);
      border: 1px solid #bbf7d0;
    }

    &.error, &.danger {
      background: var(--danger-bg);
      color: var(--danger);
      border: 1px solid #fecaca;
    }

    &.warning {
      background: #fffbeb;
      color: #d97706;
      border: 1px solid #fde68a;
    }

    &.info {
      background: #eff6ff;
      color: #2563eb;
      border: 1px solid #bfdbfe;
    }
  }

  & h3 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-main);
  }

  & p {
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.5;
    word-break: break-word;
  }

  & footer {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    margin-top: 1rem;

    & button {
      min-width: 100px;
      padding: 0.6rem 1.25rem;
    }
  }
}

.btn-secondary {
  background: var(--bg);
  color: var(--text-main);
  border: 1px solid var(--border);
  &:hover { background: #e2e8f0; }
}

/* Audit Logs Filter Bar */
.logs-filter-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  background: var(--bg);
  padding: 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 0.65rem;
  width: 100%;
  box-sizing: border-box;

  & .filter-field {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;

    & label {
      margin-bottom: 0;
      font-size: 0.78rem;
      font-weight: 600;
      color: var(--text-muted);
    }

    & input, & select {
      width: 100%;
      min-width: 0;
      box-sizing: border-box;
      padding: 0.5rem 0.65rem;
      font-size: 0.82rem;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 8px;
    }
  }

  & .filter-actions {
    min-width: 0;
    display: flex;
    align-items: flex-end;

    & button {
      width: 100%;
      height: 38px;
      font-size: 0.8rem;
      padding: 0 0.75rem;
      background: var(--surface);
      color: var(--text-muted);
      border: 1px solid var(--border);
      border-radius: 8px;
      gap: 0.35rem;
      &:hover { color: var(--text-main); background: #e2e8f0; }
    }
  }
}

@media (max-width: 440px) {
  .logs-filter-bar {
    grid-template-columns: 1fr;
  }
}

.logs-count-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.25rem 0.25rem 0.5rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* PDF Reports Section */
.pdf-reports-section {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);

  & h4 {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
  }

  & .helper-text {
    margin-bottom: 0.75rem;
  }

  & .pdf-btn-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.65rem;

    @media (max-width: 480px) {
      grid-template-columns: 1fr;
    }
  }

  & .btn-pdf {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    text-align: right;
    cursor: pointer;
    transition: all 0.2s ease;

    &:hover {
      border-color: var(--primary);
      background: #f8fafc;
      transform: translateY(-1px);
      box-shadow: 0 2px 5px rgba(0, 0, 0, 0.04);
    }

    & svg {
      stroke: var(--primary);
      flex-shrink: 0;
    }

    & div {
      display: flex;
      flex-direction: column;
      text-align: right;
    }

    & strong {
      display: block;
      font-size: 0.85rem;
      color: var(--text-main);
    }

    & small {
      display: block;
      font-size: 0.72rem;
      color: var(--text-muted);
    }
  }
}

/* Printable PDF Report Document */
.pdf-report-document {
  direction: rtl;
  text-align: right;
  font-family: system-ui, -apple-system, sans-serif;
  background: #ffffff;
  color: #0f172a;
  padding: 24px;
  width: 100%;
  box-sizing: border-box;

  & .pdf-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 2px solid #0f172a;
    padding-bottom: 14px;
    margin-bottom: 16px;

    & .pdf-brand-with-logo {
      display: flex;
      align-items: center;
      gap: 12px;

      & .pdf-logo {
        width: 46px;
        height: 46px;
        object-fit: contain;
        flex-shrink: 0;
      }
    }

    & h2 {
      font-size: 1.35rem;
      font-weight: 800;
      color: #0f172a;
      margin-bottom: 4px;
    }

    & .pdf-period-title {
      font-size: 1rem;
      color: #475569;
      font-weight: 600;
    }

    & .pdf-meta {
      font-size: 0.78rem;
      color: #475569;
      text-align: left;
      line-height: 1.4;

      & strong {
        color: #0f172a;
      }
    }
  }

  & .pdf-kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 16px;

    & .pdf-kpi-card {
      border: 1px solid #e2e8f0;
      border-radius: 8px;
      padding: 10px 12px;
      background: #f8fafc;
      text-align: center;

      & .label {
        display: block;
        font-size: 0.72rem;
        color: #64748b;
        margin-bottom: 4px;
      }

      & .val {
        display: block;
        font-size: 1.05rem;
        font-weight: 800;

        &.success { color: #16a34a; }
        &.danger { color: #dc2626; }
        &.ftth { color: #7c3aed; }
        &.wisp { color: #2563eb; }
      }
    }
  }

  & .pdf-summary-bar {
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: #f1f5f9;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.8rem;
    margin-bottom: 16px;
    border: 1px solid #e2e8f0;

    & strong {
      color: #0f172a;
    }
  }

  & .pdf-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.76rem;
    margin-bottom: 16px;

    & th, & td {
      border: 1px solid #cbd5e1;
      padding: 7px 8px;
      text-align: right;
    }

    & th {
      background-color: #0f172a;
      color: #ffffff;
      font-weight: 700;
    }

    & tr:nth-child(even) {
      background-color: #f8fafc;
    }

    & .badge-table {
      display: inline-block;
      padding: 2px 6px;
      border-radius: 4px;
      font-size: 0.68rem;
      font-weight: 600;

      &.wisp { background: #eff6ff; color: #2563eb; }
      &.ftth { background: #f5f3ff; color: #7c3aed; }
      &.debt { background: #fef2f2; color: #dc2626; }
      &.paid { background: #f0fdf4; color: #16a34a; }
      &.partial { background: #fffbeb; color: #d97706; }
    }
  }

  & .pdf-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #e2e8f0;
    padding-top: 10px;
    font-size: 0.72rem;
    color: #94a3b8;
  }
}