/* =============================================================================
   formsandtables.css — Element-level styling for forms and tables
   =============================================================================
   Self-contained: all colors, sizes, and radii are defined in :root below.
   Edit the variables to restyle without touching the rules.

   Goal: make every <form>, <input>, <button>, <table> on the site look
   consistent without requiring class assignments. Class versions
   (.td-btn, .td-form, .td-form-grid, .td-field) are kept as escape hatches.
   ============================================================================= */

:root {
    /* ── Shared (used by inputs, fieldsets, tables, buttons) ────────────── */
    --ft-border-color:                 #d1d5db;
    --ft-border-radius:                4px;

    /* ── Inputs (text/email/password/textarea/select/number/etc.) ─────────── */
    --input-text-color:                #1e293b;
    --input-background:                #ffffff;
    --input-focus-border-color:        #3b82f6;
    --input-focus-shadow:              0 0 0 3px rgba(59, 130, 246, 0.15);
    --input-accent-color:              #3b82f6;   /* checkbox / radio tint */

    /* ── Labels & legends ─────────────────────────────────────────────────── */
    --label-text-color:                #bcbdbe;
    --label-muted-color:               #64748b;

    /* ── Buttons (primary / default) ──────────────────────────────────────── */
    --button-text-color:               #ffffff;
    --button-background:               #3b82f6;
    --button-background-hover:         #2563eb;

    /* ── Buttons (danger) ─────────────────────────────────────────────────── */
    --button-danger-background:        #dc2626;
    --button-danger-background-hover:  #b91c1c;

    /* ── Buttons (ghost / secondary) ──────────────────────────────────────── */
    --button-ghost-text-color:         #3b82f6;
    --button-ghost-background-hover:   #f1f5f9;

    /* ── Tables ───────────────────────────────────────────────────────────── */
    --table-header-background:         #f1f5f9;
    --table-header-text-color:         #64748b;
}

/* ── Form inputs (element-level — no class required) ─────────────────────── */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="number"],
input[type="search"],
input[type="tel"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="month"],
input[type="week"],
textarea,
select {
    font-family:   inherit;
    font-size:     inherit;
    color:         var(--input-text-color);
    background:    var(--input-background);
    padding:       0.45rem 0.7rem;
    border:        1px solid var(--ft-border-color);
    border-radius: var(--ft-border-radius);
    box-sizing:    border-box;
    line-height:   1.4;
}

input:focus,
textarea:focus,
select:focus {
    outline:      none;
    border-color: var(--input-focus-border-color);
    box-shadow:   var(--input-focus-shadow);
}

textarea {
    resize:     vertical;
    min-height: 60px;
}

input[type="checkbox"],
input[type="radio"] {
    accent-color:   var(--input-accent-color);
    margin-right:   0.25rem;
    vertical-align: middle;
}

label {
    display:        inline-block;
    font-size:      0.875rem;
    color:          var(--label-text-color);
    margin-bottom:  0.2rem;
}

fieldset {
    border:        1px solid var(--ft-border-color);
    border-radius: var(--ft-border-radius);
    padding:       1rem 1.25rem;
    margin:        0 0 1rem;
}
legend {
    padding:     0 0.4rem;
    font-weight: 600;
    color:       var(--label-text-color);
}

/* ── Buttons (element-level — default to primary) ────────────────────────── */
button,
input[type="submit"],
input[type="reset"],
input[type="button"] {
    display:        inline-block;
    padding:        0.45rem 1rem;
    font-family:    inherit;
    font-size:      0.875rem;
    font-weight:    600;
    color:          var(--button-text-color);
    background:     var(--button-background);
    border:         none;
    border-radius:  var(--ft-border-radius);
    cursor:         pointer;
    transition:     background 0.15s;
    line-height:    1.2;
}
button:hover,
input[type="submit"]:hover,
input[type="reset"]:hover,
input[type="button"]:hover {
    background: var(--button-background-hover);
}
button:disabled,
input[type="submit"]:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ── Tables (element-level) ──────────────────────────────────────────────── */
table {
    width:           100%;
    border-collapse: collapse;
    font-size:       0.875rem;
    margin-bottom:   1rem;
}
th {
    background:      var(--table-header-background);
    color:           var(--table-header-text-color);
    font-size:       0.75rem;
    font-weight:     600;
    text-transform:  uppercase;
    letter-spacing:  0.05em;
    padding:         0.5rem 0.875rem;
    text-align:      left;
    border-bottom:   1px solid var(--ft-border-color);
}
td {
    padding:        0.6rem 0.875rem;
    border-bottom:  1px solid var(--ft-border-color);
    vertical-align: middle;
}
tr:last-child td { border-bottom: none; }

/* ============================================================================
   Class escape hatches — use only when you need explicit, non-default styling.
   ============================================================================ */

/* Buttons */
.td-btn {
    display:       inline-block;
    padding:       0.45rem 1rem;
    font-family:   inherit;
    font-size:     0.875rem;
    font-weight:   600;
    color:         var(--button-text-color);
    background:    var(--button-background);
    border:        none;
    border-radius: var(--ft-border-radius);
    cursor:        pointer;
    transition:    background 0.15s;
    white-space:   nowrap;
}
.td-btn-primary       { background: var(--button-background); color: var(--button-text-color); }
.td-btn-primary:hover { background: var(--button-background-hover); }
.td-btn-danger        { background: var(--button-danger-background); color: var(--button-text-color); font-size: 0.75rem; padding: 0.3rem 0.65rem; }
.td-btn-danger:hover  { background: var(--button-danger-background-hover); }
.td-btn-ghost         { background: transparent; color: var(--button-ghost-text-color); border: 1px solid var(--ft-border-color); font-size: 0.75rem; padding: 0.3rem 0.65rem; }
.td-btn-ghost:hover   { background: var(--button-ghost-background-hover); }

/* Form layout helpers */
.td-form      { display: flex; flex-wrap: wrap; gap: 0.625rem; align-items: flex-end; }
.td-form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0.75rem; }
.td-field     { display: flex; flex-direction: column; gap: 0.25rem; }
.td-field-full{ grid-column: 1 / -1; }

.td-field label {
    font-size:      0.75rem;
    font-weight:    600;
    color:          var(--label-muted-color);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom:  0;
}
.td-field input,
.td-field select,
.td-field textarea { width: 100%; }

.td-list-add-form {
    margin-top:  0.875rem;
    padding-top: 0.875rem;
    border-top:  1px solid var(--ft-border-color);
}
.td-form-actions { margin-top: 0.625rem; display: flex; gap: 0.4rem; align-items: center; }

/* Tables — element-level rules cover most cases; .td-table is for explicit usage */
.td-table { /* element-level styling already applies to <table>; this class is a no-op marker */ }
