/* =========================================
   CSS DESIGN TOKENS
   ========================================= */
:root {
  /* Neutral surfaces */
  --surface-tint:   #f4f4f4;

  /* Borders */
  --border-subtle:  #ccc;

  /* Text hierarchy */
  --text-muted:     #888;
  --text-faint:     #aaa;

  /* Veterinary table */
  --vet-row-base:        #ffffff;
  --vet-row-alt:         #f7f7f7;
  --vet-incomplete-bg:   #fff8e1;
  --vet-incomplete-fg:   #b45309;
  --vet-edit-ring:       #0d6efd;
  --vet-flash-bg:        #d1fae5;
  --vet-missing-bg:      #fee2e2;
}

/* =========================================
   FARMADMIN GLOBAL STYLES
   ========================================= */

/** Grid layout (migrated from adam.css) **/		
.grid-container {
  display: grid;
  margin: 0 auto;
  gap: 1rem;
  padding-right: 40px;
}
.grid-item {
  width: 100%;
}
.table {
  font-size: 24px;
  margin-bottom: 20px;
  height: auto;
}
.table thead {
  background-color: silver;
}

@media (min-width: 600px) {
  .grid-container { grid-template-columns: repeat(2, 1fr); }
  .table { font-size: 14px; }
}

/** Fixes for other styles (migrated from adam.css) **/
.datatable thead { color: black; }
.area_inner { max-width: 100%; }
.project_area { width: 100%; overflow-y: auto; }
.menu { width: 100%; }

/* =========================================
   FORM & CONTAINER LAYOUTS 
   (Restored from legacy isolated blocks)
   ========================================= */
.page-container {
    max-width: 1200px;
    margin: 20px auto;
    padding: 20px;
}

.form-section {
    overflow-x: auto;
    margin-bottom: 20px;
}

/* Order Item Table specifics */
.order-item-table { width: 100%; min-width: 800px; white-space: nowrap; }
.order-item-table td, .order-item-table th { padding: 8px 12px; vertical-align: top; }
.order-item-table th:nth-child(1), .order-item-table td:nth-child(1) { min-width: 200px; white-space: normal; }
.order-item-table th:nth-child(2), .order-item-table td:nth-child(2),
.order-item-table th:nth-child(3), .order-item-table td:nth-child(3) { width: 100px; }
.order-item-table th:nth-child(4), .order-item-table td:nth-child(4) { min-width: 150px; }
.order-item-table input[type="text"],
.order-item-table input[type="number"],
.order-item-table select { width: 100%; min-width: 0; box-sizing: border-box; }

/* =========================================
   NAVIGATION BUTTONS
   ========================================= */
.nav-actions-container {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.btn-nav {
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    transition: filter 0.2s ease, opacity 0.2s ease;
}

.btn-nav:hover {
    filter: brightness(90%);
}

.btn-nav-primary { background-color: #2196F3; }
.btn-nav-success { background-color: #4CAF50; }
.btn-nav-warning { background-color: #f39c12; }

/* =========================================
   LIST VIEW HELPERS
   ========================================= */
/* Custom styling for action links */
.action-links a {
    display: inline-block;
    margin-right: 8px;
    padding: 4px 8px;
    border-radius: 3px;
    text-decoration: none;
    font-size: 12px;
}
.action-links .edit-link { background-color: #2196F3; color: white; }
.action-links .delete-link { background-color: #f44336; color: white; }
.action-links a:hover { opacity: 0.8; }

/* Phone number styling */
.phone-link { color: #4CAF50; text-decoration: none; font-weight: 500; }
.phone-link:hover { text-decoration: underline; color: #45a049; }

/* -----------------------------------------
   ORDER LIST SPECIFIC HELPERS
   ----------------------------------------- */
.status-dropdown {
    width: 100%;
    padding: 4px 8px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 12px;
}
.status-dropdown:focus { outline: none; border-color: #4CAF50; }

.message-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    padding: 15px;
    text-align: center;
    font-weight: bold;
    z-index: 1000;
    display: none;
    justify-content: space-between;
    align-items: center;
}
.message-banner.success { background-color: #d4edda; color: #155724; border-bottom: 3px solid #28a745; }
.message-banner.error { background-color: #f8d7da; color: #721c24; border-bottom: 3px solid #dc3545; }
.message-banner.show { display: flex; }
.message-banner button { background: none; border: none; font-size: 20px; cursor: pointer; padding: 0 10px; color: inherit; }

.dt-top, .dt-bottom { display: flex; justify-content: space-between; align-items: center; margin: 10px 0; }
.dt-top .dt-right, .dt-bottom .dt-right { display: flex; gap: 10px; align-items: center; }

.action-buttons { display: flex; gap: 5px; flex-wrap: wrap; }
.btn { padding: 4px 8px; border: none; border-radius: 3px; font-size: 11px; cursor: pointer; text-decoration: none; display: inline-block; text-align: center; min-width: 50px; }
.btn-sm { padding: 3px 6px; font-size: 10px; }
.btn-primary { background-color: #007bff; color: white; }
.btn-primary:hover { background-color: #0056b3; }
.btn-success { background-color: #28a745; color: white; }
.btn-success:hover { background-color: #1e7e34; }
.btn-outline-danger { background-color: transparent; color: #dc3545; border: 1px solid #dc3545; }
.btn-outline-danger:hover { background-color: #dc3545; color: white; }
.subdued-text { color: #cccccc !important; }

/* Jspreadsheet CE — cell and toolbar font. Material Icons keep their own font via !important rules above. */
.jss td, .jss th, .jss input,
.jtoolbar, .jtoolbar * { font-family: "Avenir Next", "Helvetica Neue", Arial, sans-serif; font-size: 13px; }

/* =========================================
   SPREADSHEET DOC PAGE (public_doc.php)
   ========================================= */

.doc-page-wrapper {
    max-width: 100%;
    padding: 0 8px;
}

.doc-page-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    background: var(--surface-tint);
    padding: 10px;
    border-radius: 5px;
}

.doc-page-title {
    margin: 0;
    font-size: clamp(1.1rem, 4vw, 1.5rem);
    line-height: 1.2;
}

.doc-page-badge {
    font-size: 0.5em;
    color: var(--text-muted);
}

.doc-page-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.doc-presence-bar {
    font-size: 0.82em;
    font-family: "Avenir Next", "Helvetica Neue", Arial, sans-serif;
}

.doc-not-you {
    font-size: 0.78em;
    color: var(--text-faint);
    text-decoration: none;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 0 4px;
}

.doc-save-status {
    font-size: 0.8em;
    color: var(--text-muted);
}

.doc-sheet-container {
    width: 100%;
    height: calc(100svh - 130px);
    border: 1px solid var(--border-subtle);
}

@media (min-width: 600px) {
    .doc-page-wrapper  { padding: 0 20px; }
    .doc-sheet-container { height: calc(100svh - 90px); }
}

/* =========================================
   VETERINARY RECORDS TABLE
   ========================================= */

/* Row striping — soft grey, replaces inline blue/yellow */
.vet-table tr.vet-row-odd  td { background: var(--vet-row-base); }
.vet-table tr.vet-row-even td { background: var(--vet-row-alt); }
.vet-table tr.vet-row-incomplete td { background: var(--vet-incomplete-bg); }

/* Cell with missing required value */
.vet-table td.vet-cell-missing { background: var(--vet-missing-bg); }

/* Editable cells */
td.vet-editable { cursor: pointer; }
td.vet-editable:hover { outline: 1px solid var(--vet-edit-ring); outline-offset: -1px; }
td.vet-editing  { outline: 2px solid var(--vet-edit-ring); outline-offset: -1px; background: var(--vet-row-base); }

/* Inline input */
.vet-inline-input { min-width: 70px; width: 100%; box-sizing: border-box; }

/* Brief green flash on successful save — defined after row classes so specificity wins */
.vet-table tr td.vet-saved { background: var(--vet-flash-bg); transition: background 0.9s; }

/* Warning icon for incomplete rows */
.vet-warn-icon { font-size: 14px; color: var(--vet-incomplete-fg); vertical-align: middle; margin-right: 4px; }

/* Action links in options column */
.vet-link-edit   { color: green; margin-right: 6px; text-decoration: none; }
.vet-link-delete { color: #cc0000; text-decoration: none; }
.vet-link-edit:hover, .vet-link-delete:hover { text-decoration: underline; }

/* Reason cell: limit width to keep table manageable */
.vet-reason-cell { max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vet-reason-cell.vet-editing { white-space: normal; max-width: none; }

/* Mobile card */
.vet-mobile-card { font-size: 0.9rem; }

/* Print-only header block (farm constants shown once at top) */
.vet-print-header { display: none; }

/* Page number footer — @page margin boxes work in Chromium-based browsers */
@page {
    margin: 15mm 10mm 20mm 10mm;
    @bottom-right {
        content: "Page " counter(page) " of " counter(pages);
        font-size: 9pt;
        font-family: sans-serif;
        color: #555;
    }
}

@media print {
    /* Hide navigation and toolbar */
    header, nav, .navbar  { display: none !important; }
    .vet-no-print         { display: none !important; }

    /* Show print header */
    .vet-print-header {
        display: block;
        margin-bottom: 12px;
        padding-bottom: 8px;
        border-bottom: 2px solid #000;
    }

    td.vet-editable      { cursor: default; }
    td.vet-editable:hover { outline: none; }
    .vet-reason-cell     { max-width: none; white-space: normal; overflow: visible; }
    .container-fluid     { padding: 0; }
    .vet-table           { font-size: 10pt; }
}

/* Print header typography */
.vet-print-header-title {
    font-size: 16pt;
    font-weight: bold;
    margin: 0 0 4px 0;
}
.vet-print-header-meta {
    font-size: 10pt;
    margin: 0;
}

/* Footer */
.footer-copy    { flex-grow: 1; }
.footer-version { color: var(--text-muted); font-size: 0.8em; }

/* Mobile toolbar: horizontal scroll with adequate touch targets */
@media (max-width: 599px) {
    .jtoolbar {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap !important;
    }
    .jtoolbar > div {
        flex-shrink: 0;
        min-height: 44px;
        min-width: 44px;
    }
}

/* === Calendar === */
.cal-wrap        { max-width: 960px; margin: 20px auto; padding: 0 12px; }
.cal-nav         { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.cal-nav-actions   { display: flex; align-items: center; gap: 8px; }
.cal-presence-bar  { font-size: 0.78em; color: var(--text-muted); text-align: center;
                     min-height: 1.2em; margin-bottom: 6px; }
.cal-name-input    { border: 1px solid var(--border-subtle); border-radius: 4px;
                     padding: 1px 6px; font-size: inherit; width: 110px; vertical-align: middle; }
.cal-not-you         { color: var(--text-muted); margin-left: 8px; font-size: 0.85em; }
.cal-presence-member { margin-right: 14px; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.cal-title       { margin: 0; font-size: 1.4rem; font-weight: 600; }
.cal-grid  { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: #d0d0d0; }
.cal-dow   { background: #e9ecef; text-align: center; padding: 6px 2px; font-weight: 600; font-size: 0.8rem; }
.cal-day   { min-height: 90px; background: #fff; padding: 4px; cursor: pointer; overflow: hidden; }
.cal-day:hover        { background: #f5f9f5; }
.cal-day.cal-today    { background: #fff8e1; }
.cal-day.cal-blank        { background: #f5f5f5; cursor: default; }
.cal-day.cal-other-month  { background: #f8f8f8; }
.cal-day.cal-other-month .cal-day-num { color: #bbb; }
.cal-day-num  { display: block; font-size: 0.8rem; color: #666; margin-bottom: 2px; }
.cal-event    { background: #4a7c59; color: #fff; border-radius: 3px; padding: 2px 5px;
                font-size: 0.72rem; margin-bottom: 2px; cursor: pointer;
                white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-event:hover      { background: #3a6649; }
.cal-details-summary  { cursor: pointer; user-select: none; padding: 4px 0; }
.cal-date-wrapper     { position: relative; }
.cal-date-display     { display: flex; align-items: center; gap: 8px; padding: 8px 12px;
                        border: 1px solid #dee2e6; border-radius: 6px;
                        background: #fff; font-size: 0.95rem; color: #333; cursor: pointer; }
.cal-date-wrapper:hover .cal-date-display { border-color: #86b7fe; background: #f8f9fa; }
.cal-date-input       { position: absolute; inset: 0; opacity: 0; pointer-events: none; }

@media (max-width: 767px) {
    .cal-day     { min-height: 64px; padding: 2px; }
    .cal-dow     { font-size: 0.68rem; padding: 4px 1px; }
    .cal-day-num { font-size: 0.7rem; }
    .cal-event   { font-size: 0.62rem; padding: 1px 3px; }
    .cal-title   { font-size: 1.1rem; }
}
@media (max-width: 480px) {
    .cal-day     { min-height: 48px; }
    .cal-dow     { font-size: 0.6rem; }
    .cal-event   { font-size: 0.58rem; }
}

@media print {
    header, nav, .navbar, footer { display: none !important; }
    #btn-print, #btn-share, .cal-nav .btn { display: none !important; }
    .modal { display: none !important; }
    .cal-wrap { max-width: 100%; margin: 0; padding: 0; }
    .cal-event {
        background: #4a7c59 !important;
        color: #fff !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }
    .cal-day.cal-today { background: #fff8e1 !important; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}

/* ── Reports (silage, stock-april, purchases) ──────────────────────────── */

/* Silage report */
.ratio-hi       { background-color: #fff3cd !important; }
.ratio-lo       { background-color: #cfe2ff !important; }
.row-partial td { font-style: italic; color: #888; }
.carry-known    { font-weight: 700; color: #198754; }
.carry-est      { color: #6c757d; font-style: italic; }
.planning-card  { background: #f0f9f0; border: 2px solid #198754; border-radius: 8px; padding: 1rem 1.5rem; }
.planning-headline { font-size: 2rem; font-weight: 800; color: #198754; line-height: 1; }
.reminder-card  { background: #fff8e1; border-left: 4px solid #ffc107; padding: 0.6rem 1rem; border-radius: 4px; }

/* Stock-at-April-30 report */
.selected-row td     { background-color: #e8f5e9 !important; font-weight: 600; }
.tbl-summary td,
.tbl-summary th      { vertical-align: middle; text-align: center; }
.tbl-summary td:first-child { text-align: left; }
.yr-link             { cursor: pointer; text-decoration: none; color: inherit; }
.yr-link:hover       { color: #0d6efd; text-decoration: underline; }
.detail-section      { background: #f8f9fa; border-radius: 6px; padding: 1rem 1.2rem; }
.detail-section h5   { color: #495057; border-bottom: 1px solid #dee2e6; padding-bottom: 0.4rem; margin-bottom: 0.7rem; }
.eartag-link         { font-family: monospace; font-size: 0.9em; }
.dateculled-set      { color: #dc3545; font-size: 0.85em; }
.no-dateculled       { color: #198754; font-size: 0.85em; }
.age-cell            { white-space: nowrap; }

/* Purchase report */
.contact-box textarea { width: 100%; font-size: 0.78rem; font-family: monospace; resize: vertical; min-height: 90px; }

.print-only { display: none; }

@media print {
    .no-print        { display: none !important; }
    .print-only      { display: inline !important; }
    .container-fluid { padding: 0 !important; }
    h2               { font-size: 1.1rem; }
    .card            { border: 1px solid #ccc !important; box-shadow: none !important; }
    .planning-card   { border: 2px solid #198754 !important; }
    .detail-section  { break-inside: avoid; }
}

/* ── Electricity Pages ──────────────────────────────────────────────────── */

/* Small muted labels — register names, rate breakdowns */
.el-register-label  { font-size: 11px; color: #6b7280; }
/* Uppercase register tag in invoice review (slightly lighter) */
.el-register-tag    { font-size: 11px; color: #9ca3af; text-transform: uppercase; }
/* Amber notice for previously-saved readings (edit mode) */
.el-saved-notice      { font-size: 11px; color: #856404; }
/* Blue prompt for new readings */
.el-new-reading-label { font-size: 11px; color: #2563eb; font-weight: 600; margin-bottom: 3px; }
/* 12px label e.g. "Dual Rate" / "Dual Meter" */
.el-dual-label      { font-size: 12px; }
/* Tooltip anchor pattern */
.el-tooltip-trigger { cursor: help; text-decoration: underline dotted; }

/* Micro-spacing utilities (6 px / 2 px) used in dual-register layouts */
.el-mt-6 { margin-top: 6px; }
.el-mb-2 { margin-bottom: 2px; }
.el-mt-2 { margin-top: 2px; }

/* Readings-table column widths */
.readings-table th:nth-child(1) { width: 120px; }
.readings-table th:nth-child(2) { width: 200px; }
.readings-table th:nth-child(3) { width: 140px; }
.readings-table th:nth-child(4) { width: 160px; }
.readings-table th:nth-child(5) { width: 120px; }
.readings-table th:nth-child(6) { width: 180px; }
