/* ================================================================
   Patient Information System – Frontend Public Styles
   ================================================================ */

/* ── Design tokens ── */
.pis-frontend {
    --pis-primary:     #1a6fc4;
    --pis-primary-dk:  #145aa0;
    --pis-primary-lt:  #e8f2fd;
    --pis-accent:      #e74c3c;
    --pis-green:       #059669;
    --pis-green-lt:    #d1fae5;
    --pis-surface:     #ffffff;
    --pis-bg:          #f4f7fb;
    --pis-border:      #dde3ee;
    --pis-text:        #1a2035;
    --pis-muted:       #64748b;
    --pis-radius:      12px;
    --pis-radius-sm:   8px;
    --pis-shadow:      0 2px 10px rgba(0,0,0,.07);
    --pis-shadow-md:   0 6px 20px rgba(0,0,0,.1);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--pis-text);
    line-height: 1.6;
}

/* ── Notices ── */
.pis-notice {
    padding: 12px 18px;
    border-radius: var(--pis-radius-sm);
    margin-bottom: 20px;
    font-size: 14px;
    font-weight: 500;
    border-left: 4px solid;
}
.pis-notice--success { background: var(--pis-green-lt); border-color: var(--pis-green); color: #065f46; }
.pis-notice--error   { background: #fee2e2; border-color: var(--pis-accent); color: #991b1b; }

/* ================================================================
   SHARED COMPONENTS
   ================================================================ */

/* Buttons */
.pis-pub-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 18px;
    border-radius: var(--pis-radius-sm);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: all .18s;
    line-height: 1.3;
    white-space: nowrap;
}
.pis-pub-btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.pis-pub-btn--primary  { background: var(--pis-primary); color: #fff; }
.pis-pub-btn--primary:hover  { background: var(--pis-primary-dk); color: #fff; box-shadow: var(--pis-shadow-md); transform: translateY(-1px); }
.pis-pub-btn--secondary { background: var(--pis-primary-lt); color: var(--pis-primary); }
.pis-pub-btn--secondary:hover { background: #d0e8fa; color: var(--pis-primary-dk); }
.pis-pub-btn--ghost     { background: transparent; color: var(--pis-muted); border: 1.5px solid var(--pis-border); }
.pis-pub-btn--ghost:hover { background: var(--pis-bg); color: var(--pis-text); border-color: #b8c2d4; }
.pis-pub-btn--danger    { background: #fee2e2; color: #b91c1c; }
.pis-pub-btn--danger:hover { background: #fecaca; color: #991b1b; }
.pis-pub-btn--lg { padding: 12px 24px; font-size: 15px; }

/* Badges */
.pis-pub-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 11px;
    border-radius: 50px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .2px;
}
.pis-pub-badge--male   { background: #dbeafe; color: #1d4ed8; }
.pis-pub-badge--female { background: #fce7f3; color: #9d174d; }
.pis-pub-badge--other  { background: #f3e8ff; color: #6b21a8; }

/* Back link */
.pis-pub-back {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 14px;
    font-weight: 500;
    color: var(--pis-muted);
    text-decoration: none;
    transition: color .15s;
}
.pis-pub-back svg { width: 18px; height: 18px; }
.pis-pub-back:hover { color: var(--pis-primary); }

/* Nav row */
.pis-pub-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
    flex-wrap: wrap;
    gap: 10px;
}
.pis-pub-nav__actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ================================================================
   LIST VIEW
   ================================================================ */

/* Header */
.pis-pub-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
    flex-wrap: wrap;
    gap: 14px;
    padding: 22px 24px;
    background: var(--pis-surface);
    border-radius: var(--pis-radius);
    box-shadow: var(--pis-shadow);
    border: 1px solid var(--pis-border);
}
.pis-pub-header__title { display: flex; align-items: center; gap: 14px; }
.pis-pub-header__title svg { width: 32px; height: 32px; color: var(--pis-primary); flex-shrink: 0; }
.pis-pub-header__title h2 { margin: 0 0 3px; font-size: 20px; font-weight: 700; line-height: 1.2; }
.pis-pub-header__title p  { margin: 0; font-size: 13px; color: var(--pis-muted); }

/* Search */
.pis-pub-search-form { margin-bottom: 18px; }
.pis-pub-search-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pis-pub-search-wrap { flex: 1; min-width: 220px; position: relative; }
.pis-pub-search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--pis-muted); pointer-events: none; }
.pis-pub-search-input {
    width: 100%;
    padding: 10px 14px 10px 38px;
    border: 1.5px solid var(--pis-border);
    border-radius: var(--pis-radius-sm);
    font-size: 14px;
    color: var(--pis-text);
    background: var(--pis-surface);
    box-sizing: border-box;
    transition: border-color .15s, box-shadow .15s;
    font-family: inherit;
}
.pis-pub-search-input:focus { outline: none; border-color: var(--pis-primary); box-shadow: 0 0 0 3px rgba(26,111,196,.15); }

/* Table */
.pis-pub-table-wrap { overflow-x: auto; background: var(--pis-surface); border: 1px solid var(--pis-border); border-radius: var(--pis-radius); box-shadow: var(--pis-shadow); }
.pis-pub-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.pis-pub-table thead { background: #f5f8fc; }
.pis-pub-table th {
    padding: 13px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    color: var(--pis-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    border-bottom: 2px solid var(--pis-border);
    white-space: nowrap;
}
.pis-pub-table td { padding: 14px 16px; border-bottom: 1px solid #eef1f7; vertical-align: middle; }
.pis-pub-table tbody tr:last-child td { border-bottom: none; }
.pis-pub-table tbody tr:hover { background: #f9fbff; }
.pis-pub-td--name a { font-weight: 600; color: var(--pis-primary); text-decoration: none; }
.pis-pub-td--name a:hover { text-decoration: underline; }
.pis-pub-td--diag { max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--pis-muted); font-size: 13px; }
.pis-pub-td--actions { white-space: nowrap; }

/* Action icon buttons */
.pis-pub-action {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border-radius: 6px;
    text-decoration: none; transition: background .15s, color .15s; margin-right: 2px;
}
.pis-pub-action svg { width: 16px; height: 16px; }
.pis-pub-action--view   { color: var(--pis-muted); }
.pis-pub-action--view:hover   { background: var(--pis-primary-lt); color: var(--pis-primary); }
.pis-pub-action--edit   { color: var(--pis-primary); }
.pis-pub-action--edit:hover   { background: var(--pis-primary-lt); color: var(--pis-primary-dk); }
.pis-pub-action--delete { color: var(--pis-accent); }
.pis-pub-action--delete:hover { background: #fee2e2; color: #b91c1c; }

/* Empty state */
.pis-pub-empty {
    padding: 64px 20px;
    text-align: center;
    background: var(--pis-surface);
    border: 1px solid var(--pis-border);
    border-radius: var(--pis-radius);
    color: var(--pis-muted);
}
.pis-pub-empty svg { width: 48px; height: 48px; display: block; margin: 0 auto 14px; color: #c8d1e0; }
.pis-pub-empty p { font-size: 14px; }

/* Pagination */
.pis-pub-pagination { margin-top: 18px; display: flex; gap: 6px; flex-wrap: wrap; }
.pis-pub-pagination .page-numbers {
    padding: 7px 13px; border-radius: 6px; text-decoration: none;
    font-size: 13px; font-weight: 500;
    color: var(--pis-primary); border: 1.5px solid var(--pis-border);
    background: var(--pis-surface); transition: background .15s;
}
.pis-pub-pagination .page-numbers:hover { background: var(--pis-primary-lt); }
.pis-pub-pagination .page-numbers.current { background: var(--pis-primary); color: #fff; border-color: var(--pis-primary); }

/* ================================================================
   FORM VIEW
   ================================================================ */

.pis-pub-form-header { margin-bottom: 24px; }
.pis-pub-form-header h2 { margin: 0 0 5px; font-size: 22px; font-weight: 700; }
.pis-pub-form-header p  { margin: 0; color: var(--pis-muted); font-size: 14px; }

.pis-pub-section {
    background: var(--pis-surface);
    border: 1px solid var(--pis-border);
    border-radius: var(--pis-radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--pis-shadow);
}
.pis-pub-section__head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    padding-bottom: 14px;
    border-bottom: 2px solid var(--pis-bg);
}
.pis-pub-section__head svg { width: 22px; height: 22px; color: var(--pis-primary); flex-shrink: 0; }
.pis-pub-section__head h3 { margin: 0; font-size: 16px; font-weight: 700; }

/* Grids */
.pis-pub-grid { display: grid; gap: 16px; margin-bottom: 16px; }
.pis-pub-grid--1 { grid-template-columns: 1fr; }
.pis-pub-grid--2 { grid-template-columns: repeat(2, 1fr); }
.pis-pub-grid--3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 860px) { .pis-pub-grid--3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .pis-pub-grid--2, .pis-pub-grid--3 { grid-template-columns: 1fr; } }

/* Fields */
.pis-pub-field { display: flex; flex-direction: column; gap: 6px; }
.pis-pub-field label { font-size: 13px; font-weight: 600; color: var(--pis-text); }
.pis-pub-field--req label::after { content: ' *'; color: var(--pis-accent); }
.pis-pub-field input[type="text"],
.pis-pub-field input[type="date"],
.pis-pub-field select,
.pis-pub-field textarea {
    padding: 10px 13px;
    border: 1.5px solid var(--pis-border);
    border-radius: var(--pis-radius-sm);
    font-size: 14px;
    color: var(--pis-text);
    background: var(--pis-surface);
    width: 100%;
    box-sizing: border-box;
    font-family: inherit;
    transition: border-color .15s, box-shadow .15s;
    -webkit-appearance: none;
    appearance: none;
}
.pis-pub-field select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='none' stroke='%2364748b' stroke-width='1.5' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 13px center;
    padding-right: 36px;
}
.pis-pub-field textarea { resize: vertical; min-height: 110px; }
.pis-pub-field input:focus,
.pis-pub-field select:focus,
.pis-pub-field textarea:focus { outline: none; border-color: var(--pis-primary); box-shadow: 0 0 0 3px rgba(26,111,196,.15); }
.pis-pub-field.pis-pub-field--error input,
.pis-pub-field.pis-pub-field--error select,
.pis-pub-field.pis-pub-field--error textarea { border-color: var(--pis-accent); box-shadow: 0 0 0 3px rgba(231,76,60,.12); }
.pis-pub-error-msg { font-size: 12px; color: var(--pis-accent); margin-top: 3px; }
.pis-pub-hint { font-size: 12px; color: var(--pis-muted); font-style: italic; }

.pis-pub-form-footer { display: flex; gap: 12px; align-items: center; margin-top: 4px; flex-wrap: wrap; }

/* ================================================================
   SINGLE / PROFILE VIEW
   ================================================================ */

.pis-pub-profile { background: var(--pis-surface); border: 1px solid var(--pis-border); border-radius: var(--pis-radius); box-shadow: var(--pis-shadow); overflow: hidden; }

/* Hero */
.pis-pub-profile__hero {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 28px 28px 22px;
    background: linear-gradient(135deg, var(--pis-primary) 0%, #2b5fad 100%);
    color: #fff;
    flex-wrap: wrap;
}
.pis-pub-avatar {
    width: 72px; height: 72px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,.2);
    flex-shrink: 0;
    border: 3px solid rgba(255,255,255,.35);
}
.pis-pub-avatar svg { width: 40px; height: 40px; color: #fff; }
.pis-pub-avatar--female { background: rgba(252,231,243,.25); }
.pis-pub-profile__name { margin: 0 0 8px; font-size: 22px; font-weight: 700; line-height: 1.2; }
.pis-pub-profile__meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; opacity: .9; }
.pis-pub-profile__meta .pis-pub-badge { font-size: 11px; background: rgba(255,255,255,.25); color: #fff; }
.pis-pub-dot { width: 4px; height: 4px; border-radius: 50%; background: rgba(255,255,255,.5); }
.pis-pub-record-id { opacity: .7; font-size: 12px; }

/* Detail grid */
.pis-pub-detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0;
}
@media (max-width: 680px) { .pis-pub-detail-grid { grid-template-columns: 1fr; } }

.pis-pub-detail-card { padding: 22px 24px; border-top: 1px solid var(--pis-border); border-right: 1px solid var(--pis-border); }
.pis-pub-detail-card:nth-child(even) { border-right: none; }
.pis-pub-detail-card--full { grid-column: 1 / -1; border-right: none; }

.pis-pub-detail-card__head {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--pis-muted);
    margin-bottom: 16px;
}
.pis-pub-detail-card__head svg { width: 17px; height: 17px; color: var(--pis-primary); flex-shrink: 0; }
.pis-pub-detail-card__head--accent { color: var(--pis-primary); }
.pis-pub-detail-card__head--accent svg { color: var(--pis-primary); }

.pis-pub-detail-row { display: flex; gap: 12px; margin-bottom: 11px; font-size: 14px; }
.pis-pub-detail-row:last-child { margin-bottom: 0; }
.pis-pub-detail-label { min-width: 160px; flex-shrink: 0; color: var(--pis-muted); font-size: 13px; padding-top: 1px; }
.pis-pub-detail-value { color: var(--pis-text); font-weight: 500; }
.pis-pub-detail-value--highlight { color: var(--pis-primary); font-weight: 600; }
.pis-pub-detail-empty { color: var(--pis-muted); font-style: italic; font-size: 14px; margin: 0; }
@media (max-width: 480px) { .pis-pub-detail-row { flex-direction: column; gap: 3px; } .pis-pub-detail-label { min-width: unset; } }

.pis-pub-text-block { font-size: 14px; line-height: 1.7; color: var(--pis-text); white-space: pre-wrap; margin: 0; }
.pis-pub-text-block--diagnosis { font-weight: 500; color: var(--pis-primary-dk); }

/* Lab tags */
.pis-pub-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.pis-pub-tag {
    display: inline-flex;
    padding: 5px 13px;
    background: var(--pis-primary-lt);
    color: var(--pis-primary);
    border-radius: 50px;
    font-size: 13px;
    font-weight: 500;
}

/* Print helper */
@media print {
    .pis-pub-nav__actions, .pis-pub-back { display: none; }
    .pis-pub-profile { box-shadow: none; border: 1px solid #ccc; }
    .pis-pub-profile__hero { background: #1a6fc4 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
