/* Admin login + 2FA pages: soft background, top-aligned bordered card */
body.login #page,
body.tfa #page { background: #cbd5e1 !important; }
html.dark body.login #page,
html.dark body.tfa #page { background: #0f172a !important; }
body.login #page > div,
body.tfa #page > div { align-items: flex-start !important; padding-top: 60px !important; }
#content-main.login-card {
    max-width: 440px !important;
    margin: 0 auto !important;
    padding: 36px 36px 28px !important;
    border: 1px solid rgba(148, 163, 184, 0.35) !important;
    border-radius: 14px !important;
    background: #1e293b !important;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35) !important;
}
.login-logo {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}
.login-logo img { height: 48px; width: auto; }
#content-main.login-card label,
#content-main.login-card .form-row label {
    color: #e2e8f0 !important;
}

/* AdminImageWidget: style the native file input as a real button */
.admin-image-widget input[type="file"] {
    font-size: 12px;
    color: transparent;
    width: 130px;
}
.admin-image-widget.no-image input[type="file"] {
    color: inherit;
    width: auto;
}
.admin-image-widget input[type="file"]::file-selector-button {
    padding: 6px 14px;
    margin-right: 8px;
    background: #4f46e5;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-weight: 500;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s;
}
.admin-image-widget input[type="file"]::file-selector-button:hover {
    background: #4338ca;
}

/* Status colors (colored badges) */
.colored-status { font-weight: bold; }
.cleaning-colored-status, .new-colored-status, .pending-colored-status { color: #3b82f6; }
.active-colored-status, .applied-colored-status, .completed-colored-status,
.signed-colored-status, .vacancy-colored-status { color: #22c55e; }
.received-colored-status { color: #a855f7; }
.draft-colored-status { color: #eab308; }
.unsigned-colored-status, .processing-colored-status,
.refunded-colored-status, .reserved-colored-status { color: #f97316; }
.cancelled-colored-status, .failed-colored-status, .rented-colored-status { color: #ef4444; }
.archived-colored-status, .expired-colored-status, .not_available-colored-status { color: #6b7280; }
.pending_manual_refund-colored-status { color: #d97706; }

/* Form field sizes */
.add-rent-form input:not([type="checkbox"]):not(.vDateField) { min-width: 250px; }
.add-rent-form select { min-width: 263.6px; }
.add-rent-form textarea { min-width: 500px; }

/* Raw ID fields */
.vForeignKeyRawIdAdminField { width: auto !important; }

/* Readonly label padding */
.aligned label + div.readonly { padding: 4px 10px 0 0 !important; }

/* Filter select */
.filter-select { margin: 5px 15px 20px; width: calc(100% - 30px); }

/* Inline formset styling */
.inline-group .tabular tr.has_original.has_no_show_original td { padding-top: 8px !important; }

/* Login and 2FA pages — the overridden templates render Django's default
   widgets which come unstyled under Unfold. Add borders so fields/buttons
   are visible. */
#login-form input[type="text"],
#login-form input[type="password"],
#login-form input[type="email"],
#tfa-form input[type="text"] {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    color: #111827;
    font-size: 14px;
    line-height: 1.5;
}
#login-form input[type="text"]:focus,
#login-form input[type="password"]:focus,
#login-form input[type="email"]:focus,
#tfa-form input[type="text"]:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
}
#login-form input[type="submit"],
#tfa-form button.submit-button {
    border: 1px solid #4f46e5;
    background: #4f46e5;
    color: #fff;
    padding: 10px 18px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
}
#login-form input[type="submit"]:hover,
#tfa-form button.submit-button:hover {
    background: #4338ca;
    border-color: #4338ca;
}
#tfa-form button.resend-code-button {
    border: 1px solid #d1d5db;
    background: #fff;
    color: #111827;
    padding: 10px 18px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
}
#tfa-form button.resend-code-button:hover:not(:disabled) {
    background: #f3f4f6;
}
#tfa-form button.resend-code-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
#login-form .form-row { margin-bottom: 12px; }
#login-form label, #tfa-form label {
    display: block;
    margin-bottom: 4px;
    font-size: 13px;
    font-weight: 500;
    color: #374151;
}

@media (prefers-color-scheme: dark) {
    #login-form input[type="text"],
    #login-form input[type="password"],
    #login-form input[type="email"],
    #tfa-form input[type="text"] {
        background: #1f2937;
        color: #f3f4f6;
        border-color: #374151;
    }
    #tfa-form button.resend-code-button {
        background: #1f2937;
        color: #f3f4f6;
        border-color: #374151;
    }
    #login-form label, #tfa-form label { color: #d1d5db; }
}

/* Unfold uses a class-based dark mode (html.dark) — mirror the dark styles there
   so labels stay readable regardless of OS preference. */
html.dark #login-form input[type="text"],
html.dark #login-form input[type="password"],
html.dark #login-form input[type="email"],
html.dark #tfa-form input[type="text"] {
    background: #1f2937;
    color: #f3f4f6;
    border-color: #374151;
}
html.dark #tfa-form button.resend-code-button {
    background: #1f2937;
    color: #f3f4f6;
    border-color: #374151;
}
html.dark #login-form label,
html.dark #tfa-form label { color: #e5e7eb; }

/* Admin list table — make clickable links visually distinct */
#result_list td a {
    color: #818cf8;
    text-decoration: none;
}
#result_list td a:hover {
    text-decoration: underline;
}

/* Point 8: Editable form fields — visible borders in dark mode
   Uses specific selectors for Django's default form widgets that Unfold
   doesn't style (manual rental form, content localizations, customer forms). */
html.dark .aligned input[type="text"],
html.dark .aligned input[type="email"],
html.dark .aligned input[type="url"],
html.dark .aligned input[type="number"],
html.dark .aligned textarea,
html.dark .aligned select,
html.dark .manual-rental-form input[type="text"],
html.dark .manual-rental-form input[type="date"],
html.dark .manual-rental-form select {
    border: 1px solid #374151;
    background: #1f2937;
    color: #f3f4f6;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    line-height: 1.5;
}
html.dark .aligned input:focus,
html.dark .aligned textarea:focus,
html.dark .aligned select:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

/* Point 7: Gate device phone panel — dark mode fixes */
html.dark .customer-info strong { color: #f3f4f6 !important; }
html.dark .customer-row:hover { background: #1e293b !important; }
html.dark .phone-checkbox-item .phone-number { color: #e2e8f0; }
html.dark #phone-management-panel .search-bar { background: #1e293b !important; }
html.dark #phone-management-panel .search-bar input {
    background: #1f2937 !important;
    color: #f3f4f6 !important;
    border-color: #374151 !important;
}
html.dark .save-bar { background: #1e293b !important; }
html.dark .standalone-section { border-color: #374151 !important; }

/* Point 9: Phone number widget — dark mode */
html.dark .phone-number-widget {
    border-color: #374151;
}
html.dark .country-select-display {
    background: #1f2937 !important;
}
html.dark .country-select-dropdown {
    background: #1f2937 !important;
    border-color: #374151 !important;
}
html.dark .country-select-dropdown li:hover {
    background: #374151 !important;
}
html.dark .phone-number-widget input {
    background: #1f2937 !important;
    color: #f3f4f6 !important;
}
.phone-number-widget input {
    padding: 5px 6px !important;
    font-size: 14px;
}

/* Point 10: Email/SMS logs — message preview dark mode */
html.dark .report-table td .message-preview,
html.dark .report-table td .message-preview span,
html.dark .report-table td .message-preview p,
html.dark .report-table td .message-preview td,
html.dark .report-table td .message-preview th,
html.dark .report-table td .message-preview li,
html.dark .report-table td .message-preview b,
html.dark .report-table td .message-preview strong {
    background: #1e293b !important;
    color: #e2e8f0 !important;
    border-color: #374151 !important;
}
html.dark .report-table td .message-preview table {
    background: #1e293b !important;
}
html.dark .report-table td .message-preview a {
    color: #818cf8;
}


/* Return requests: the clause-4.4 plaque column.
   Unfold puts white-space: nowrap on every list header cell, so one more
   column pushed the header row wider than the page can hold. Letting the
   HEADER (and only the header) wrap to a second line buys the column without
   squeezing any of the values. Scoped to this one list on purpose: everywhere
   else the single-line header is what keeps the tables scannable. */
body.model-returnrequest.change-list #result_list thead th {
    white-space: normal;
}
/* 6rem is the width at which the wordy captions break in two and stop
   deciding how wide their column is: "Auto / Created", "Return / Date",
   "Clause 4.4 / plaque", and in Russian "Создано / автоматически". The data
   cells already wrap, so this is the last thing holding the table wide. */
body.model-returnrequest.change-list #result_list thead th .text {
    max-width: 6rem;
}


/* Change forms on a phone.
   A <fieldset> is at least as wide as its widest unbreakable content by
   default (min-inline-size: min-content), unlike a div. One such line in a
   card (a long document number, an e-mail, a select) made the whole block,
   and with it every block of the form, wider than the screen, and the rental
   card scrolled sideways at 375 px. With a zero minimum the blocks keep the
   width of the screen and their content wraps; wide tables inside already
   scroll in their own boxes. On a desktop nothing changes: the blocks are
   wider than their content anyway. */
fieldset.module {
    min-width: 0;
}

/* Record cards: every admin card laid out as a form to fill in
   (app_back/templates/admin/includes/fieldset.html). Each section is a block
   with an icon and a title; fields sit in a grid, the label above the value,
   and long values take the whole width (card-field--wide). */
.admin-card-section {
    margin: 0 0 16px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #fff;
    min-width: 0;
}
html.dark .admin-card-section { border-color: #1f2937; background: rgba(255, 255, 255, 0.02); }
.admin-card-section--stacked { border: 0; border-radius: 0; background: transparent; margin: 0; }
.admin-card-section > details > summary { list-style: none; }
.admin-card-section > details > summary::-webkit-details-marker { display: none; }
.admin-card-section__title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 600;
    border-bottom: 1px solid #f1f5f9;
}
html.dark .admin-card-section__title { border-color: #1f2937; }
.admin-card-section__title .material-symbols-outlined { font-size: 19px; color: #4f46e5; }
html.dark .admin-card-section__title .material-symbols-outlined { color: #818cf8; }
.admin-card-section > details:not([open]) .admin-card-section__title { border-bottom: 0; }
.admin-card-section > details > summary .admin-card-section__title::after {
    content: "expand_more";
    font-family: "Material Symbols Outlined";
    margin-left: auto;
    font-size: 20px;
    font-weight: 400;
    transition: transform .15s;
}
.admin-card-section > details[open] > summary .admin-card-section__title::after { transform: rotate(180deg); }
.admin-card-section__description { padding: 10px 14px 0; font-size: 13px; line-height: 1.5; max-width: 900px; }
/* Fields sit in a grid of narrow columns (about 90px each, as many as the
   block holds) and each takes as many columns as what it holds needs
   (card-field--xs ... --l, picked in admin_cards.py): a number one column,
   a date two, a name three, an address four, a text or a list the whole row.
   A cell is a subgrid of three rows (label, value, note), so along a row the
   labels, the inputs and the help texts line up whatever their height. */
.admin-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr));
    grid-auto-flow: row;
    gap: 4px 16px;
    align-items: start;
    padding: 12px 14px 8px;
}
.admin-card-grid > .card-field {
    display: grid;
    grid-template-rows: subgrid;
    grid-row: span 3;
    grid-column: span 3;
    min-width: 0;
}
.admin-card-grid > .card-field--xs { grid-column: span 1; }
.admin-card-grid > .card-field--s { grid-column: span 2; }
.admin-card-grid > .card-field--m { grid-column: span 3; }
.admin-card-grid > .card-field--l { grid-column: span 4; }
.admin-card-grid > .card-field--wide { grid-column: 1 / -1; }
.admin-card-grid > .card-field.hidden { display: none; }
.admin-card-label { align-self: end; min-width: 0; }
.admin-card-label label {
    display: block;
    margin: 0;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.3;
    color: #64748b;
    overflow-wrap: anywhere;
}
html.dark .admin-card-label label { color: #94a3b8; }
.admin-card-value { min-width: 0; align-self: start; }
.admin-card-value input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]),
.admin-card-value select,
.admin-card-value textarea { width: 100%; max-width: 100%; }
.admin-card-value .select2-container { width: 100% !important; }
.admin-card-value .readonly { max-width: none; font-size: 14px; line-height: 1.45; padding: 8px 0 !important; overflow-wrap: anywhere; }
.admin-card-value pre { white-space: pre-wrap; overflow-wrap: anywhere; max-width: 100%; }
.admin-card-meta { min-width: 0; padding-bottom: 8px; font-size: 12px; line-height: 1.4; }
.admin-card-meta:empty { padding-bottom: 8px; }
.admin-card-meta .help, .admin-card-meta p { margin: 0; max-width: 60ch; }
.admin-card-errors { margin-top: 2px; color: #dc2626; font-size: 12px; }
html.dark .admin-card-errors { color: #f87171; }
.admin-card-errors ul { margin: 0; padding: 0; list-style: none; }
.admin-card-check { display: flex; align-items: center; gap: 8px; min-height: 38px; align-self: center; }
.admin-card-check label { margin: 0; font-size: 13px; font-weight: 500; }
@media (max-width: 640px) {
    .admin-card-grid { padding: 10px 12px 6px; }
    .admin-card-grid > .card-field { grid-column: 1 / -1; }
    .admin-card-section__title { padding: 10px 12px; }
}
/* Plain Django widgets (forms that set their own widgets) get the same box
   as Unfold's own inputs inside a card. */
.admin-card-value :is(input[type="text"], input[type="email"], input[type="url"], input[type="number"],
    input[type="tel"], input[type="password"], input[type="date"], input:not([type]), textarea, select):not([class*="border"]) {
    border: 1px solid #d1d5db;
    background: #fff;
    color: #111827;
    padding: 7px 10px;
    border-radius: 6px;
    font-size: 14px;
    line-height: 1.4;
    min-height: 38px;
}
html.dark .admin-card-value :is(input[type="text"], input[type="email"], input[type="url"], input[type="number"],
    input[type="tel"], input[type="password"], input[type="date"], input:not([type]), textarea, select):not([class*="border"]) {
    border-color: #374151;
    background: #1f2937;
    color: #f3f4f6;
}
.admin-card-value :is(input, textarea, select):not([class*="border"]):focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}
/* A text area grows with its text instead of standing ten empty lines tall. */
.admin-card-value textarea {
    height: auto;
    min-height: 64px;
    max-height: 420px;
    field-sizing: content;
    resize: vertical;
}
/* The manual rental form keeps its own panels; only the icon title is shared. */
.panel-header .admin-card-section__title { padding: 0; border: 0; }

/* Record cards, the mosaic: on a wide screen the blocks of a card (sections
   and inline tables) stand in columns like tiles, two from 1280px and three
   from 1800px. The container is a grid of one-pixel rows and
   app_back/js/record_cards.js gives every block as many rows as it is tall,
   so a block goes under the shorter column, in its own order, and nothing is
   cut: CSS columns sliced a block whose bottom crossed the balance line. The
   script also sorts the blocks: a short section or a small inline table
   (record-card--narrow) takes one column, a section with many fields, a wide
   inline table and everything else take the whole width, and a short block
   with no short neighbour takes the whole width too instead of standing
   beside a hole. An inline table with nothing in it and nothing to add
   (record-card--empty) is not shown. Without the script the blocks stay in
   one column, as Unfold lays them out. */
@media (min-width: 1280px) {
    #content-main form .record-cards--mosaic {
        display: grid;
        grid-template-columns: repeat(var(--record-cards-columns, 2), minmax(0, 1fr));
        grid-auto-rows: 1px;
        grid-auto-flow: row;
        column-gap: 16px;
        row-gap: 0;
        align-items: start;
    }
    #content-main form .record-cards--mosaic > * {
        grid-column: 1 / -1;
        min-width: 0;
    }
    #content-main form .record-cards--mosaic > .record-card--narrow {
        grid-column: auto / span 1;
    }
}
@media (min-width: 1800px) {
    #content-main form .record-cards--mosaic { --record-cards-columns: 3; }
}
#content-main form .record-card--empty { display: none; }

/* Inline tables (prices, pictures, plans, histories) fill their block and
   never run past it: a cell shrinks with the window instead of pushing the
   table into a horizontal scroll. */
#content-main table.formset {
    width: 100% !important;
    table-layout: auto;
}
#content-main table.formset thead th {
    white-space: normal;
}
#content-main table.formset td select,
#content-main table.formset td input:not([type="checkbox"]):not([type="radio"]):not([type="file"]) {
    width: 100%;
    min-width: 4.5rem;
    max-width: none;
    box-sizing: border-box;
}

/* Chips: one block for choosing several values (app_back/widgets.py). */
.chip-select { display: flex; flex-direction: column; gap: 8px; }
.chip-select__tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; font-size: 12px; color: #64748b; }
html.dark .chip-select__tools { color: #94a3b8; }
.chip-select__search {
    flex: 1 1 180px;
    max-width: 280px;
    min-height: 32px;
    padding: 4px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    font-size: 13px;
}
html.dark .chip-select__search { border-color: #374151; background: #1f2937; color: #f3f4f6; }
.chip-select__action { background: none; border: 0; padding: 0; color: #4f46e5; cursor: pointer; font-size: 12px; }
html.dark .chip-select__action { color: #818cf8; }
.chip-select__list { display: flex; flex-wrap: wrap; gap: 6px; max-height: 260px; overflow: auto; }
.chip-select__chip { position: relative; display: inline-flex; }
.chip-select__chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip-select__chip span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 30px;
    padding: 4px 12px;
    border: 1px solid #d1d5db;
    border-radius: 999px;
    font-size: 13px;
    line-height: 1.2;
    cursor: pointer;
    user-select: none;
    transition: background-color .12s, border-color .12s, color .12s;
}
html.dark .chip-select__chip span { border-color: #374151; color: #e5e7eb; }
.chip-select__chip span:hover { border-color: #6366f1; }
.chip-select__chip input:checked + span { background: #4f46e5; border-color: #4f46e5; color: #fff; }
.chip-select__chip input:checked + span::before { content: "✓"; font-size: 11px; }
.chip-select__chip input:focus-visible + span { outline: 2px solid #818cf8; outline-offset: 2px; }
.chip-select__chip input:disabled + span { opacity: .5; cursor: not-allowed; }
.chip-select__chip[hidden] { display: none; }

